Skip to main content

Cart Preview

A cart preview runs a checkout event through your rules exactly as it would run live, and returns what would happen: each discount with the amount it takes off each line, the net total, the points the purchase would earn, and the rewards the member could spend points on. Nothing is stored or sent, and no balance, coupon use or cap moves, so you can preview the same cart as often as the shopper changes it.

For example, a coffee chain's online store calls the preview every time a shopper edits the basket, shows "You save $3.00 and earn 135 points", and lists the rewards the shopper can afford.

Send a preview​

Post the checkout event to POST /events with simulate=true. Target the member the same way as a live event.

curl -X POST "https://api.loomloyalty.com/events?entityType=CUSTOMER&entityId=cust_123&simulate=true&include=burnOptions" \
-H "Authorization: Bearer $LOOM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"eventTypeCode": "online-checkout",
"description": "Basket preview",
"eventData": { "couponCodes": ["WELCOME10"] },
"lineItems": [
{ "lineItemReference": "beans-1", "sku": "BEANS-1KG", "category": "coffee-beans", "quantity": 1, "unitPrice": 100, "amount": 100 },
{ "lineItemReference": "mug-1", "sku": "MUG-BLUE", "category": "merchandise", "quantity": 1, "unitPrice": 50, "amount": 50 }
]
}'
ParameterDescription
simulate=truePreviews the event instead of recording it. Needs the events:write scope.
include=burnOptionsAdds the rewards the member can afford and could spend points on in this cart. Ignored without simulate=true.

The event gets a throwaway eventId. An Idempotency-Key header and eventReference are ignored. A member signed in to the Rewards Portal can't call the preview; it's for your integration.

To let shoppers enter codes, send them in eventData.couponCodes. The event type's data model needs that array, and an event rule with an apply-coupon action reads it.

Read the response​

The response's data is the event as it would run, with simulated: true, each rule action with its result under eventActions, and the discounts under checkout:

{
"data": {
"simulated": true,
"status": "PROCESSED",
"checkout": {
"discountTotal": 15,
"shippingDiscount": 0,
"netAmount": 135,
"stackingPolicy": "BEST_FOR_SHOPPER",
"discounts": [
{
"couponCode": "WELCOME10",
"applied": true,
"amount": 15,
"lines": [
{ "lineReference": "beans-1", "amount": 10 },
{ "lineReference": "mug-1", "amount": 5 }
]
},
{
"eventRuleCode": "mug-promo",
"applied": false,
"reason": "LOST_TO_STACKING",
"amount": 0
}
],
"burnOptions": [
{
"offerCode": "free-pastry",
"programCurrencyCode": "points",
"cost": 500,
"discountAmount": 4.5
}
]
}
}
}
FieldDescription
discountTotalEverything taken off, shipping included.
shippingDiscountThe part of discountTotal taken off shipping.
netAmountThe lines' total after discounts, shipping excluded.
stackingPolicyHow the discounts were chosen (below).
discountsEach discount a rule or entered code proposed, applied or not, with the amount per line.
burnOptionsUp to 20 rewards the member can afford, best saving first, each with its cost and what it would take off on top of the applied discounts. Nothing is held or spent.

An earn rule that reads $.checkout.netAmount shows its forecast in eventActions. In the example, it would award 135 points.

Why a discount didn't apply​

A discount with applied: false carries a reason:

ReasonMeaning
MINIMUM_SPENDThe cart is under the discount's minimum spend.
OUT_OF_SCOPENo line matches the products or categories the discount covers.
NOTHING_TO_DISCOUNTThe lines it covers are already fully discounted.
LOST_TO_STACKINGAnother set of discounts won under the stacking policy.
NOT_CONFIGUREDThe discount lacks a setting its type needs, such as an older coupon offer with no discount set.
UNKNOWN, EXPIRED, USED_UP, DUPLICATE_CODE, CURRENCY_MISMATCHAn entered code doesn't exist, has expired, has no uses left, was entered twice, or states an amount in another currency.

An unknown code doesn't fail the call. The preview still answers 200 and lists the code as not applied. Accept reasons added later.

Stacking​

When several discounts match, the program's stackingPolicy decides which apply:

  • BEST_FOR_SHOPPER (the default): the set of discounts with the largest total wins.
  • BEST_FOR_BRAND: the highest-priority exclusive discount wins. With none, the smallest set of stackable discounts wins.

Set it on the program with PUT /programs/{programId}.

Shipping​

A free-shipping or shipping discount takes off the shipping amount. The rule's discount action names where that amount is in the event, such as $.eventData.shippingAmount.

Check out for real​

When the shopper pays, send the same event without simulate=true. Rules run again on the final cart and record the result.