An online order and its refund
An online store works like a till, with three differences: the customer is a signed-in store account rather than a card on the counter, spending happens at checkout before the money is taken, and orders get refunded. This guide follows Bilal, who signed up from the store in Signing a customer up. His store account’s id comes from that guide’s answer, and the order numbers are made from the clock so the guide can be run again; your store sends its own:
export PASSKAAR_API=https://api.passkaar.com/integrations/v1printf 'Your key: '; read -rs PASSKAAR_KEY; echo; export PASSKAAR_KEYCUSTOMER=$(jq -r '.customer.external_id' enrolment-online.json); RUN=$(date +%s)echo "$CUSTOMER ORDER-$RUN-1"The order is paid: give points
Section titled “The order is paid: give points”Record an order when it is paid, not when it is placed. Order ORDER-$RUN-1 came to Rs 4,500,
of which Rs 500 was tax and Rs 200 delivery:
curl -sS "$PASSKAAR_API/awards" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d "{\"card\": {\"external_id\": \"$CUSTOMER\"}, \"reference\": \"ORDER-$RUN-1\", \"bill\": {\"total\": 4500, \"tax\": 500, \"delivery\": 200, \"currency\": \"PKR\"}}" | jq .{ "id": "40dced9d-d9ef-469f-bd72-4e0cd5ceaba0", "reference": "ORDER-1795315715-1", "card": { "id": "6eec7c6a-8f73-4a25-8f0a-468b96fcd96b", "card_id": "GB9-GB9-W9G" }, "type": "points", "earned": { "points": 450 }, "balance": { "type": "points", "points": 500, "unit_name": "beans", "next_reward": null, "expiring": null }, "rewards_unlocked": [], "tier_reached": null, "occurred_at": "2026-11-22T02:48:37.488Z", "recorded_at": "2026-11-22T02:48:37.488Z", "replayed": false}Send tax and delivery when you have them. Whether they earn is the shop owner’s choice, made in
the portal on your connection: this one earns on the full bill, so Rs 4,500 earned 450 beans; set to
before tax and delivery, it would have earned on Rs 3,800. Use the order number as reference,
so a webhook from your store platform that arrives twice records the order once.
An order that is paid on delivery is recorded once it is delivered and paid, with
"paid_on_delivery": true; a shop that gives nothing on such orders answers
operation_not_allowed. A late order carries its real time in occurred_at.
Spending at checkout: hold, then confirm
Section titled “Spending at checkout: hold, then confirm”At checkout you do not yet know whether the payment will go through. Instead of spending, hold the value against the order. A hold reserves it on the card for 15 minutes, so it cannot be spent twice, and takes it off the order total in your store:
curl -sS "$PASSKAAR_API/redemption-holds" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d "{\"card\": {\"external_id\": \"$CUSTOMER\"}, \"reference\": \"ORDER-$RUN-2\", \"spend\": {\"type\": \"points\", \"points\": 200}}" \ | tee hold.json | jq .201 Created:
{ "id": "ea9a70eb-5b82-4e56-ab48-ebbb366f072b", "reference": "ORDER-1795315715-2", "card": { "id": "6eec7c6a-8f73-4a25-8f0a-468b96fcd96b", "card_id": "GB9-GB9-W9G" }, "status": "open", "held": { "points": 200, "value_rupees": 200 }, "expires_at": "2026-11-22T03:03:39.850Z", "available": { "type": "points", "points": 300, "unit_name": "beans", "next_reward": null, "expiring": null }, "redemption": null, "created_at": "2026-11-22T02:48:39.850Z", "replayed": false}Take value_rupees (Rs 200) off the order. available is what is left to spend while the hold is
open. When the payment succeeds, confirm the hold; that spends it:
HOLD=$(jq -r '.id' hold.json)curl -sS -X POST "$PASSKAAR_API/redemption-holds/$HOLD/confirm" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{}' | jq .{ "id": "ea9a70eb-5b82-4e56-ab48-ebbb366f072b", "reference": "ORDER-1795315715-2", "card": { "id": "6eec7c6a-8f73-4a25-8f0a-468b96fcd96b", "card_id": "GB9-GB9-W9G" }, "status": "confirmed", "held": { "points": 200, "value_rupees": 200 }, "expires_at": "2026-11-22T03:03:39.850Z", "available": { "type": "points", "points": 300, "unit_name": "beans", "next_reward": null, "expiring": null }, "redemption": { "id": "ff9e4ea2-7634-4a86-adeb-213895cbd17f" }, "created_at": "2026-11-22T02:48:39.850Z", "replayed": false}If the payment fails or the customer takes the discount off, release the hold instead, and the value is back on the card at once:
curl -sS "$PASSKAAR_API/redemption-holds" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -d "{\"card\": {\"external_id\": \"$CUSTOMER\"}, \"reference\": \"ORDER-$RUN-3\", \"spend\": {\"type\": \"points\", \"points\": 20}}" \ | tee hold-2.json | jq '{id, status, held}'curl -sS -X POST "$PASSKAAR_API/redemption-holds/$(jq -r '.id' hold-2.json)/release" \ -H "Authorization: Bearer $PASSKAAR_KEY" | jq '{id, reference, status, held, available}'{ "id": "8e45c4bc-d391-4fa2-9dd2-0b835ec59fd7", "reference": "ORDER-1795315715-3", "status": "released", "held": { "points": 20, "value_rupees": 20 }, "available": { "type": "points", "points": 300, "unit_name": "beans", "next_reward": null, "expiring": null }}A hold nobody confirms or releases ends by itself after 15 minutes. If the order is paid after
that, spend it with POST /redemptions under the same reference;
it is refused if the card no longer holds enough. An order paid days later, such as cash on
delivery, should not be held at all.
Only a store account your connection signed up, or one the customer proved with the card ID
through POST /cards/link, may hold and spend. One linked from a phone
number alone answers card_required.
A partial refund
Section titled “A partial refund”Bilal returns part of ORDER-$RUN-1, Rs 1,500 of it. Reverse the award with the refund’s amount and
the refund’s own number:
curl -sS "$PASSKAAR_API/awards/ORDER-$RUN-1/reverse" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d "{\"refund\": {\"total\": 1500, \"currency\": \"PKR\"}, \"refund_reference\": \"REFUND-$RUN-1\"}" | jq .{ "id": "a17addae-98d3-412f-aa27-5b7e59fb8361", "award": { "id": "40dced9d-d9ef-469f-bd72-4e0cd5ceaba0", "reference": "ORDER-1795315715-1" }, "card": { "id": "6eec7c6a-8f73-4a25-8f0a-468b96fcd96b", "card_id": "GB9-GB9-W9G" }, "kind": "partial", "reversed": { "points": 150 }, "shortfall": null, "balance": { "type": "points", "points": 150, "unit_name": "beans", "next_reward": null, "expiring": null }, "occurred_at": "2026-11-22T02:48:46.736Z", "recorded_at": "2026-11-22T02:48:46.736Z", "replayed": false}A third of the bill came back, so a third of what it earned goes: 150 of the 450 beans. Each
partial refund needs its own refund_reference; sending the same one again answers this result
instead of taking more. The order’s reference goes in the path; percent-encode one that holds a
/ (INV/24-25/001 becomes INV%2F24-25%2F001).
Cancelling the rest, when the beans are already spent
Section titled “Cancelling the rest, when the beans are already spent”Now the rest of the order is cancelled. Leave out refund to reverse whatever is left of the award:
curl -sS "$PASSKAAR_API/awards/ORDER-$RUN-1/reverse" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d '{}' | jq .{ "id": "34d9286f-b7a0-4194-b328-8681329f68a9", "award": { "id": "40dced9d-d9ef-469f-bd72-4e0cd5ceaba0", "reference": "ORDER-1795315715-1" }, "card": { "id": "6eec7c6a-8f73-4a25-8f0a-468b96fcd96b", "card_id": "GB9-GB9-W9G" }, "kind": "full", "reversed": { "points": 150 }, "shortfall": { "points": 150 }, "balance": { "type": "points", "points": 0, "unit_name": "beans", "next_reward": null, "expiring": null }, "occurred_at": "2026-11-22T02:48:48.776Z", "recorded_at": "2026-11-22T02:48:48.776Z", "replayed": false}300 beans were left to take back, but Bilal had already spent 200 of his beans at checkout and the
card held only 150. Passkaar never takes a card below zero: it took the 150 there were and reports
the other 150 as shortfall. It also sends a refund.unresolved webhook, so your system or the
shop can settle the difference with the customer, for example by keeping it off the refund.
A reversal undoes only your own connection’s awards. Sending the full reversal again, even with a
new Idempotency-Key, answers the first one with replayed: true and takes nothing more.
Next: verifying a webhook.