Checkout Integration
This is the full checkout flow, end to end. It applies to any system that evaluates a cart at the moment of purchase: POS, e-commerce checkout, self-checkout, kiosk, or the middleware that calls Loyal Guru on their behalf.
If you have not yet made a single call, start with the Quickstart β it gets you a first response in a few minutes. This page assumes that call already works and walks through everything needed to put the flow into production.
The flowβ
Two calls carry the integration: one that previews and one that commits. Everything else is error handling around them.
POST /carts/simulate evaluates the cart without persisting it and without consuming vouchers, so you can call it as often as the cart changes. POST /carts/realtime is the commit: it persists the transaction, consumes the vouchers and awards the points. Call it once, when the payment is confirmed.
Which scope applies to youβ
The flow above is identical in both integration scopes. What changes is who calculates the final price, set by the apply_discounts flag:
| Scope | apply_discounts | What the response carries | What you build |
|---|---|---|---|
| Loyal Guru calculates (Promo Engine) | true | Calculated effects and final values | Apply the returned effects to the cart |
| Your system calculates (Coupon Server) | false | Applicable rules, coupon and voucher validation | Parse the rules and calculate the amounts yourself |
Confirm the value with the Loyal Guru project team before you build β it is set per Company and determines how much logic lives on your side. The examples on this page use apply_discounts: true. If your Company runs as Coupon Server, the call sequence is the same but the response is interpreted differently: see Coupon Server and Reading from GET.
Step 1 β Confirm the data the rules depend onβ
The engine evaluates the cart against Customer state, Company data and the active campaigns. Before the first meaningful test, confirm that the identifiers your checkout sends already exist in Loyal Guru:
| Data | Guide |
|---|---|
| Customer identity | Customer Data |
| Products, locations, taxonomies | Company Data |
The identifiers in the cart lines must be the same ones loaded through the data connection β a product_id that does not exist in the catalog cannot match a product rule. This is the most common cause of "the campaign does not apply" during integration testing.
Step 2 β Configure a campaign to test againstβ
Campaigns are configured in the Owner App, not through the integration. For a first end-to-end test, ask the loyalty manager or the Loyal Guru team for a sandbox campaign that is easy to trigger and easy to verify:
- A discount campaign in the current Loyalty and Promotional Engine.
- A simple condition β a specific product, or a cart total above a threshold.
- A visible effect β a percentage or fixed amount discount.
- Activated in the sandbox Company.
Test with an eligible Customer and an ineligible one. A campaign that always applies proves less than one that correctly declines.
Step 3 β Simulate the cartβ
Call simulate whenever the cart changes and the Customer should see the result. It does not persist anything.
curl --request POST 'https://streaming.loyal.guru/carts/simulate' \
--header 'X-Api-Key: YOUR_API_KEY' \
--header 'X-Api-Secret: YOUR_API_SECRET' \
--header 'X-Api-Version: 1' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": 20260717002,
"customer_id": 123456,
"apply_discounts": true,
"country": "ES",
"location_id": 1001,
"payment_method": "card",
"total": 45.00,
"lines": [
{
"product_id": 10045,
"product_code": "SKU-10045",
"quantity": 3,
"unit_price": 15.00,
"total": 45.00
}
]
}'
Step 4 β Apply the returned effectsβ
{
"effects": [
{
"rule_id": 101,
"rule_name": "10% off test campaign",
"type": "discount",
"effect_type": "percentage",
"distribution_type": "individual_items",
"select_customers": "all_customers",
"value": 450,
"line": 1
}
],
"total_discount_applied": 4.5,
"score": 45
}
How your system consumes it:
- Apply line effects to the cart line referenced by
line. Alineof-1means the effect applies to the cart total, not to a line. - Read
valueas cents for a discount effect, and as a number of points for a points effect. Cart-level totals such astotal_discount_appliedare money amounts. Mixing the two units is the most common arithmetic mismatch in this step. - Apply cart-level effects to the cart total.
- Show coupon or voucher feedback when the request carried
coupons_desired. - Show earned points or wallet value only if loyalty feedback is part of the checkout experience.
- Keep the raw response in your logs. Reconciliation and support cases are impossible without it.
The exact response depends on Company configuration and the modules enabled. Field-level schemas are in the cart endpoints reference.
Step 5 β Confirm the cartβ
When the Customer has paid and the transaction must be persisted, send the same cart to POST /carts/realtime.
curl --request POST 'https://streaming.loyal.guru/carts/realtime' \
--header 'X-Api-Key: YOUR_API_KEY' \
--header 'X-Api-Secret: YOUR_API_SECRET' \
--header 'X-Api-Version: 1' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": 20260717002,
"customer_id": 123456,
"apply_discounts": true,
"country": "ES",
"location_id": 1001,
"payment_method": "card",
"total": 45.00,
"lines": [
{
"product_id": 10045,
"product_code": "SKU-10045",
"quantity": 3,
"unit_price": 15.00,
"total": 45.00
}
]
}'
Two rules that decide whether this integration survives production:
- Reuse the cart ID only for the same business transaction. A reused ID for a different purchase is a data corruption, not a duplicate.
- Generate the cart ID once, at the origin of the sale, and send that same ID on every retry. A timeout tells you nothing about whether the cart was persisted, and the cart
idis what protects the retry: a cart that is not unique is not processed a second time, so no voucher is double-consumed. The catch is that the endpoint does not report the duplicate either β it answers as if it had succeeded while applying no effects β so a retry is not confirmation, and the transaction has to be reconciled. TheIdempotency-Keyheader is a different mechanism, declared in the reference on the point redemption endpoints; see Reliability.
Confirmation is the point of no return: it is where vouchers are consumed and points awarded. Everything about retries, timeouts, degraded mode and compensation is on Reliability β read it before go-live, not after the first incident.
Step 6 β Handle what happens afterβ
A confirmed cart is not always final. Plan for these before launch:
| Situation | What to do |
|---|---|
| Payment fails after confirmation | Run the cancellation flow agreed for the integration β POST /carts/cancellation. |
| Return or refund | Same cancellation path; confirm with the project team whether points and vouchers are reverted. |
| Loyal Guru is unreachable at checkout | Never block the sale. Complete the purchase without benefits and reconcile afterwards β see Reliability. |
| A downstream system needs to react to the purchase | Do not poll. Subscribe to the event β see Webhooks. |
Before go-liveβ
- Test eligible and ineligible Customers against the same campaign.
- Test retries with the original cart ID, duplicate and reused cart IDs, cancellation and rollback.
- Confirm the checkout behaves correctly when Loyal Guru does not answer in time.
- Confirm endpoint schemas against the API Reference.
- Work through the Integration checklist for the rest of the launch sequence.
Related API Referenceβ
Troubleshootingβ
| Symptom | What to check |
|---|---|
| Simulation returns no effects | Campaign status and date window, Customer eligibility, product and location scope, cart total, and whether the identifiers in the cart exist in the catalog. |
| Realtime returns a different result than simulate | The campaign changed between the two calls, Customer or voucher state changed, or the confirmed payload differs from the simulated one. |
| Duplicate cart error | The cart ID was reused for a different transaction. A retry that carries the original cart ID is not reprocessed β but it is not flagged as a duplicate either, so reconcile the transaction instead of reading the response as a fresh confirmation. |
| Voucher consumed but payment failed | Run the agreed cancellation flow and verify the voucher state afterwards. |
| Checkout totals differ from the Loyal Guru response | Confirm which scope the Company runs in. apply_discounts: true means Loyal Guru calculated the amounts; false means your system did. |
403 Forbidden | Check X-Api-Key, X-Api-Secret and X-Api-Version. |