Before you start
- The POS has the
memberIdof the checked-in customer and thecouponIdsthe sale applied, from whichever discount flow you use. - The POS has a
receiptIdfor the sale before it redeems. The same value is the idempotency key, thereceiptIdin the redeem request and the receipt id on the recorded purchase. The offline path and the refund on a return both depend on them matching.
The flow
1
Redeem the coupons
POST /v2/customers/{customerId}/coupons/redeemCall this once the sale has completed. Send five things:- The
Idempotency-Keyheader, set to thereceiptId. It makes a retry safe, lets multi-use coupons count correctly, and is what a later refund refers to. receiptId, the sale’s receipt id. Always send it. Lobyco needs it to give the coupons back itself when a return is recorded.storeId, the store where the sale happened.coupons, each with thevalueit granted.basketValue, the basket total. Together with the store, it feeds the live statistics marketers see.
400 Bad Request listing the ones it could not find.A redeemed coupon is one the response returns in its couponIds. Lobyco marks it as used and counts it against the offer’s redemption limits.2
[Optional] Release the reservation
POST /api/v1/customers/{customerId}/coupons/cancel-reservationIf the sale is abandoned before you redeem, release the coupons that were reserved for it. The customer can then use them at another POS or online straight away. Send thecouponIds and the same reservedBy the reservation was made with. A reservation made under a different reservedBy cannot be released this way. An unreleased reservation frees itself at its reservedUntil time.Returns and refunds
When a customer returns goods, there are two ways to give the coupons back.Cancel the redemption
POST /api/v1/customers/{customerId}/coupons/cancel-redeem When a customer returns goods, the POS can give the coupons back, so the customer can use them again while the offer is still valid. Send theIdempotency-Key the coupons were redeemed with and the coupon ids to return. Lobyco does not work out which coupons a return affects. The POS decides, and it sends one request per original redemption, because a request cancels redemptions under one key only.
Record the return
Where refunds are turned on, the POS can record the return as a purchase instead. Lobyco then works out which coupons the return completes, and gives them back. See Returns and refunds.Offline redemption
Coupon retrieval and discount calculation need Lobyco online. Redemption does not. Sometimes the coupons were applied and the sale completed, but the POS cannot reach Lobyco to redeem them. Then put the coupon ids in thecouponIds field of the purchase you send to POST /v1/purchases. Lobyco redeems them when it loads the purchase, with the purchase’s receiptId on each redemption, so a return can give them back.
For this to work, the purchase’s receiptId must equal the Idempotency-Key you would have used in the redeem call. The matching key is how Lobyco recognises coupons that were already redeemed online, so it redeems nothing twice.
Failure and edge cases
If the redeem call does not go through, or the sale changes afterwards, it is one of these.- The redeem call times out. Retry with the same
Idempotency-Key. Lobyco treats the retry as the same request and redeems nothing twice. - A coupon in the request is unknown. The response is
400 Bad Requestwith those ids, and the other coupons are redeemed. Log the ids. The sale itself is not affected. - The refund key does not match. A cancel-redeem under a different key than the redemption cancels nothing. Keep the
receiptIdwith the sale, so a return days later can still find it. - The offer has ended. Cancel-redeem gives a coupon back only while its offer is still valid. After that, Lobyco does not return the coupon.
API reference
Endpoint documentation: Coupons (POS).Related
- Direct coupon service integration — the flow where the POS reserves and chooses the coupons it redeems here.
- Discount integration — the flow where Lobyco chooses and reserves the coupons it redeems here.
- Transaction data — the purchase that carries
couponIdson the offline path, and the call that records the sale.