A sale at the counter
At a till, the customer shows their card. Your system reads it, records the sale on it, and later lets the customer spend what they earned. This guide does that for Ayesha, who signed up in the previous guide.
export PASSKAAR_API=https://api.passkaar.com/integrations/v1printf 'Your key: '; read -rs PASSKAAR_KEY; echo; export PASSKAAR_KEYThe card ID comes from that guide’s answer, kept in enrolment.json in the same folder. At a real
till the cashier types it from the card, or your scanner reads the card’s QR code:
CARD_ID=$(jq -r '.card.card_id' enrolment.json); echo "$CARD_ID"Each sale below has its own invoice number. A test shop keeps every reference for ever, so these are made from the clock and the guide can be run again; your till sends its own invoice numbers:
RUN=$(date +%s); echo "INV-$RUN-1"How a till names a card
Section titled “How a till names a card”A request names the card in card, by exactly one of these:
card |
When |
|---|---|
{"serial": "…"} |
Your scanner read the card’s QR code. The QR holds the card’s serial, nothing else. |
{"card_id": "GB9-Y2Z-H6B"} |
The cashier typed the card ID printed under the QR. Case, spaces and dashes do not matter. |
{"phone": "03001234567"} |
The customer gave their phone number. It can earn, but never spend. |
{"email": "…"} |
As the phone number. |
{"external_id": "…"} |
Your own id for the customer, sent at sign-up. Online stores use it. |
Spending needs the card itself (serial or card_id), or a store account linked with the card,
because a phone number is easy to know and a card is not.
Look the card up
Section titled “Look the card up”Before the sale, show the cashier whose card it is and what it holds:
curl -sS "$PASSKAAR_API/cards/lookup" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -d "{\"card_id\": \"$CARD_ID\"}" | jq .{ "data": [ { "id": "8a851af1-d5e8-463a-9354-69e605e01879", "card_id": "GB9-NND-YFC", "program": { "id": "259975f9-719a-48c8-8dc9-eb7128114ebf", "name": "Bean points", "type": "points" }, "customer": { "id": "6824ad24-355d-49fd-8360-2a821d861384", "first_name": "Ayesha", "phone_masked": "+92 300 •••••••", "email_masked": null, "external_id": null }, "status": "active", "ended_on": null, "in_wallet": false, "wallets": [], "claimable": true, "issued_at": "2026-11-22T02:47:58.889Z", "last_activity_at": "2026-11-22T02:47:58.907Z", "balance": { "type": "points", "points": 50, "unit_name": "beans", "next_reward": null, "expiring": null } } ]}The API shows the customer’s first name and a masked phone number, never their full details.
balance is what the card holds now: 50 beans from joining.
Record the sale
Section titled “Record the sale”The bill comes to Rs 2,450, invoice INV-$RUN-1. Send the invoice number as reference: it is
yours, it is unique in your system, and Passkaar keeps it with the sale for ever. Also make an
Idempotency-Key for this attempt and keep it until you have an answer:
KEY=$(uuidgen)curl -sS "$PASSKAAR_API/awards" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $KEY" \ -d "{\"card\": {\"card_id\": \"$CARD_ID\"}, \"reference\": \"INV-$RUN-1\", \"bill\": {\"total\": 2450, \"currency\": \"PKR\"}}" | jq .201 Created:
{ "id": "e3849049-9ae8-4977-90f2-24c7cb389f6f", "reference": "INV-1795315692-1", "card": { "id": "8a851af1-d5e8-463a-9354-69e605e01879", "card_id": "GB9-NND-YFC" }, "type": "points", "earned": { "points": 245 }, "balance": { "type": "points", "points": 295, "unit_name": "beans", "next_reward": null, "expiring": null }, "rewards_unlocked": [], "tier_reached": null, "occurred_at": "2026-11-22T02:48:17.183Z", "recorded_at": "2026-11-22T02:48:17.183Z", "replayed": false}You sent the bill, and Passkaar applied the shop’s rule: Rs 2,450 at 1 bean per Rs 10 is 245 beans.
Print earned and balance on the receipt. Passkaar also updates the card on Ayesha’s phone.
When the network fails
Section titled “When the network fails”Mobile data drops. If your request timed out and you do not know whether it arrived, send the same
request again with the same Idempotency-Key. Run the curl command above again, without making a
new KEY. The answer is the first one, with replayed now true, and no second award is made
(200 OK; trimmed here to the fields that tell):
{ "id": "e3849049-9ae8-4977-90f2-24c7cb389f6f", "reference": "INV-1795315692-1", "earned": { "points": 245 }, "replayed": true}The rest of the answer is as before. The same reference protects you even without the header,
at any age: a sale already recorded under INV-$RUN-1 is never recorded twice, and sending it again
answers the first one. Two different sales need two different references.
Spend at the next visit
Section titled “Spend at the next visit”Ayesha comes back and wants 100 beans off her bill. Spending names the card itself:
curl -sS "$PASSKAAR_API/redemptions" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d "{\"card\": {\"card_id\": \"$CARD_ID\"}, \"reference\": \"INV-$RUN-2\", \"spend\": {\"type\": \"points\", \"points\": 100}}" | jq .{ "id": "81d56cdd-f06f-4150-a114-ff26db53e020", "reference": "INV-1795315692-2", "card": { "id": "8a851af1-d5e8-463a-9354-69e605e01879", "card_id": "GB9-NND-YFC" }, "type": "points", "spent": { "points": 100, "value_rupees": 100 }, "balance": { "type": "points", "points": 195, "unit_name": "beans", "next_reward": null, "expiring": null }, "occurred_at": "2026-11-22T02:48:20.099Z", "recorded_at": "2026-11-22T02:48:20.099Z", "replayed": false}value_rupees is what the beans are worth: take Rs 100 off the bill. Then record the sale for what
Ayesha actually paid, as above. It may carry the same invoice number: sales and spends are counted apart.
Spending by phone number alone is refused, whichever number it is:
curl -sS "$PASSKAAR_API/redemptions" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -d "{\"card\": {\"phone\": \"03001234567\"}, \"reference\": \"INV-$RUN-3\", \"spend\": {\"type\": \"points\", \"points\": 10}}" | jq .422:
{ "type": "https://passkaar.com/developers/errors/card_required", "title": "Spending needs the card itself or a store account linked with it", "status": 422, "code": "card_required", "request_id": "60411094c92fbe8e4b5b896b7a7b94bd"}Ask the customer for their card.
A refund at the counter
Section titled “A refund at the counter”Ayesha brings back part of what she bought on INV-$RUN-1: Rs 490 of the Rs 2,450. Reverse the
sale by its invoice number, with the refund’s amount and the refund’s own number. It works exactly
as it does for an online order:
curl -sS "$PASSKAAR_API/awards/INV-$RUN-1/reverse" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: $(uuidgen)" \ -d "{\"refund\": {\"total\": 490, \"currency\": \"PKR\"}, \"refund_reference\": \"REFUND-$RUN-1\"}" | jq .{ "id": "36b9ae00-3351-4a4e-ae28-06b54a62b155", "award": { "id": "e3849049-9ae8-4977-90f2-24c7cb389f6f", "reference": "INV-1795315692-1" }, "card": { "id": "8a851af1-d5e8-463a-9354-69e605e01879", "card_id": null }, "kind": "partial", "reversed": { "points": 49 }, "shortfall": null, "balance": { "type": "points", "points": 146, "unit_name": "beans", "next_reward": null, "expiring": null }, "occurred_at": "2026-11-22T02:48:23.992Z", "recorded_at": "2026-11-22T02:48:23.992Z", "replayed": false}A fifth of the bill came back, so a fifth of the 245 beans it earned goes: 49. Leave out refund
to take back all that is left of the sale.
An online order and its refund
shows both, and what happens when the beans are already spent.
card.card_id is null here, although the sale’s answer showed it. The API answers a card’s
printed ID only to a call that named the card itself (by card_id or serial), to the sign-up that
made it, or for a store account linked with the card. A reversal names a sale, not the card, so it
answers the card’s id alone; your till has the card ID from the sale. Webhook events follow the
same rule: they carry card_id only for a store account linked with the card, and null for a card
your system knows from the counter.
The card’s history
Section titled “The card’s history”Every change to a card, from your system, the shop’s own cashiers or anywhere else, is in its
history. Use the card’s id from the lookup:
CARD=$(curl -sS "$PASSKAAR_API/cards/lookup" -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" -d "{\"card_id\": \"$CARD_ID\"}" | jq -r '.data[0].id')curl -sS "$PASSKAAR_API/cards/$CARD/transactions" \ -H "Authorization: Bearer $PASSKAAR_KEY" | jq .{ "data": [ { "id": "097e73dd-7d1b-4562-bb20-cff92e32dcfe", "kind": "reversal", "change": { "points": -49 }, "occurred_at": "2026-11-22T02:48:23.936Z", "recorded_at": "2026-11-22T02:48:23.936Z", "branch": null, "source": "integration", "reference": "REFUND-1795315692-1", "reversed_by": null, "reverses": "e3849049-9ae8-4977-90f2-24c7cb389f6f" }, { "id": "81d56cdd-f06f-4150-a114-ff26db53e020", "kind": "redemption", "change": { "points": -100 }, "occurred_at": "2026-11-22T02:48:20.099Z", "recorded_at": "2026-11-22T02:48:20.099Z", "branch": null, "source": "integration", "reference": "INV-1795315692-2", "reversed_by": null, "reverses": null }, { "id": "e3849049-9ae8-4977-90f2-24c7cb389f6f", "kind": "award", "change": { "points": 245 }, "occurred_at": "2026-11-22T02:48:17.183Z", "recorded_at": "2026-11-22T02:48:17.183Z", "branch": null, "source": "integration", "reference": "INV-1795315692-1", "reversed_by": null, "reverses": null }, { "id": "eb91b77d-4334-4838-9d8e-bb3c2472c06f", "kind": "award", "change": { "points": 50 }, "occurred_at": "2026-11-22T02:47:58.907Z", "recorded_at": "2026-11-22T02:47:58.907Z", "branch": null, "source": "integration", "reference": null, "reversed_by": null, "reverses": null } ], "next_cursor": null}The newest change comes first. reference is shown only on your own connection’s rows; the
refund’s row carries its refund_reference.
The refund is a row of its own, of kind reversal, and its reverses names the sale it took back.
The sale’s own row does not change, so its reversed_by stays null: a sale can be refunded in
several parts, and each part is its own row pointing back at it. To find what was refunded of a sale,
look for the rows whose reverses is the sale’s id. reversed_by is set only when the shop undoes
a whole row from its portal. The row’s id is the history’s own; the reversal’s answer has an id
of its own too, for the reversal itself.
A card read
by its id (GET /cards/{id}) answers card_id as null, because an id alone does not prove the
card is in front of you; a lookup by card_id or serial answers it.
Branches
Section titled “Branches”A shop with several branches names them in GET /branches. Send the
branch’s id as branch on each sale so the shop’s reports show where it happened. A connection the
owner tied to one branch records there by itself.