Skip to content

Bad internet and going live

Every guide starts here
export PASSKAAR_API=https://api.passkaar.com/integrations/v1
printf 'Your key: '; read -rs PASSKAAR_KEY; echo; export PASSKAAR_KEY

If a call times out, you do not know whether it arrived. Send it again exactly as it was: the same Idempotency-Key, the same reference, the same body. If it was recorded, you get the first answer with replayed: true. If it was not, it is recorded now. It is never counted twice.

Wait about 10 seconds for an answer before giving up on a try.

What came back What to do
No answer, 500, 503 Send the same again: after a few seconds, then 30, then every few minutes.
429 rate_limited Wait the seconds in the Retry-After header, then send the same again.
409 request_in_progress The first try is still running. Wait a moment, send the same again.
401 unauthorized Stop and keep the queue. The key is wrong, stopped or paused: tell the shop’s owner.
400, 404, other 409, 422 Sending it again changes nothing. Put it aside and show a person code and detail.

Keep the Idempotency-Key with the sale in your database. It is remembered for 24 hours. The invoice number is remembered for ever, so a sale resent a week later is still safe.

A live key may send 10 requests a second, in bursts of 20. A test key may send 2, in bursts of 5. A queue that sends one at a time and obeys 429 never needs to count.

A sale closed without internet is saved and sent when the line is back. Keep the real time of the sale and send it as occurred_at:

Terminal window
CARD=$(cat card.json); RUN=$(date +%s); SOLD_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ); KEY=$(uuidgen)
Terminal window
curl -sS "$PASSKAAR_API/awards" \
-H "Authorization: Bearer $PASSKAAR_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $KEY" \
-d "{\"card\": $CARD, \"reference\": \"INV-$RUN-3\", \"bill\": {\"total\": 800, \"currency\": \"PKR\"}, \"occurred_at\": \"$SOLD_AT\"}" \
| jq '{reference, earned, balance, occurred_at, recorded_at}'
{
"reference": "INV-1795596416-3",
"earned": {
"points": 80
},
"balance": {
"type": "points",
"points": 80,
"unit_name": "beans",
"next_reward": null,
"expiring": null
},
"occurred_at": "2026-11-25T08:46:56.000Z",
"recorded_at": "2026-11-25T08:46:58.561Z"
}
  • Save before you send, so a till that loses power loses nothing.
  • Send the oldest first, sales and refunds in one queue. A refund that overtakes its sale answers not_found.
  • Any past time is accepted. A time more than a minute ahead of Passkaar’s clock is refused, so keep the till’s clock right. 2026-11-24T21:40:00+05:00 is the form with Pakistan’s time.
  • A late sale counts toward the card’s daily limit on the day it arrives.
  • Offline, the till can scan the card or type the phone number, but cannot check it. A card that turns out wrong is put aside, as in the table above.

Never redeem offline. Redeeming needs an answer, because the balance must be checked. Tell the customer it works when the internet is back.

Retry it while the customer waits. If you must go on without an answer, give no discount, and do not put the redemption in the queue: sent later, it would spend their points for nothing. When the internet is back, read the card’s history, which changes nothing, and look for your invoice number:

Terminal window
CARD_UUID=$(jq -r '.data[0].id' lookup.json); INVOICE=$(cat invoice-2.txt)
curl -sS "$PASSKAAR_API/cards/$CARD_UUID/transactions" \
-H "Authorization: Bearer $PASSKAAR_KEY" \
| jq -c ".data[] | select(.reference == \"$INVOICE\") | {kind, reference, change}"
{"kind":"reversal","reference":"INV-1795596398-2","change":{"points":-110}}
{"kind":"award","reference":"INV-1795596398-2","change":{"points":110}}
{"kind":"redemption","reference":"INV-1795596398-2","change":{"points":-100}}

A redemption (or, on a prepaid card, a deduction) line means it was spent: ask the shop’s owner to undo it in the portal. No such line means it never arrived.

The whole rule in one file. Node 18 or later, nothing to install. Your own queue is a table in your database:

queue.mjs
import { randomUUID } from 'node:crypto';
import { readFileSync } from 'node:fs';
const { PASSKAAR_API, PASSKAAR_KEY } = process.env;
async function send(row) {
let res;
try {
res = await fetch(PASSKAAR_API + row.path, {
method: 'POST',
headers: {
Authorization: `Bearer ${PASSKAAR_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': row.key,
},
body: JSON.stringify(row.body),
signal: AbortSignal.timeout(10_000),
});
} catch {
return { next: 'retry', after: 30 };
}
const answer = await res.json().catch(() => ({}));
if (res.ok) return { next: 'done', answer };
if (res.status === 429 || res.status >= 500 || answer.code === 'request_in_progress') {
return { next: 'retry', after: Number(res.headers.get('retry-after')) || 30 };
}
return { next: res.status === 401 ? 'stop' : 'aside', answer };
}
// Saved when the bill is paid, before the first send.
const card = JSON.parse(readFileSync('card.json', 'utf8'));
const sale = (reference, total) => ({
path: '/awards',
key: randomUUID(),
body: {
card,
reference,
bill: { total, currency: 'PKR' },
occurred_at: new Date().toISOString(),
},
});
const run = Math.floor(Date.now() / 1000);
const queue = [sale(`INV-${run}-4`, 900), sale(`INV-${run}-5`, 5), sale(`INV-${run}-6`, 1250)];
while (queue.length > 0) {
const { next, after, answer } = await send(queue[0]);
console.log(queue[0].body.reference, next, answer?.earned ?? answer?.code ?? '');
if (next === 'retry') await new Promise((done) => setTimeout(done, after * 1000));
else if (next === 'stop')
break; // the key was refused: keep the queue, tell the owner
else queue.shift(); // done, or put aside for a person
}
Terminal window
node queue.mjs
INV-1795596422-4 done { points: 90 }
INV-1795596422-5 aside operation_not_allowed
INV-1795596422-6 done { points: 125 }

Invoice 5 is the Rs 5 bill that is too small to earn. It is put aside and the queue goes on.

Test these ten on the test shop:

  1. Scan a card from a phone screen, and type a card ID in small letters without dashes.
  2. Scan something that is not a card, such as the shop’s join QR code or a product. The sale goes on.
  3. Add for a bill. The receipt shows what was earned and the new balance.
  4. Send the same invoice twice. The balance moves once.
  5. Redeem, then add for what was paid, on one invoice.
  6. Redeem more than the card holds, and redeem by phone number. Both are refused and no discount is given.
  7. Return part of a bill, then the rest. Void a bill whose points are already spent, and see shortfall on the screen.
  8. Pull the network cable in the middle of a sale, plug it back and see the sale arrive once.
  9. Close three sales offline and one refund, and see them arrive in order.
  10. Stop on 401 with a wrong key: the queue is kept, the cashier is told, and sales go on.

Then, with the shop’s owner:

  • Swap the psk_test_ key for the shop’s psk_live_ key, on the server only. The calls are the same.
  • Read the programs and branches again. Ids from the test shop mean nothing in the real one.
  • Check the five ticks, and that Largest bill is above the shop’s biggest bill.
  • Make one small real sale on the owner’s own card, look at it in the portal’s History, and reverse it.
  • Log every error’s request_id. Passkaar support finds the call by it: support@passkaar.com.
  • Agree who is told when the queue stops.

The fields of each call are in the reference: look up, add, redeem and reverse. Every error code has its page.