Verifying a webhook
Passkaar tells your server when something happens to the shop’s cards: a sign-up, an award, a
card added to a phone, a refund that could not take everything back. It sends each event as an
HTTPS POST to an address you register, signed so you can tell it came from Passkaar. Anyone can
send a POST to your server, so check the signature of every event before you act on it.
This guide builds a receiver in Node.js with no dependencies, gives it a public address, registers
it, and watches real events arrive. You need Node.js 18 or later, and a key whose connection may
be told the moment things happen (webhooks:manage); a test shop’s key may.
export PASSKAAR_API=https://api.passkaar.com/integrations/v1printf 'Your key: '; read -rs PASSKAAR_KEY; echo; export PASSKAAR_KEY1. The receiver
Section titled “1. The receiver”Save this as receiver.mjs:
import { createHmac, timingSafeEqual } from 'node:crypto';import { createServer } from 'node:http';
const secret = process.env.PASSKAAR_WEBHOOK_SECRET;const key = Buffer.from(secret.slice('whsec_'.length), 'base64');
function verify(headers, body) { const id = headers['webhook-id']; const timestamp = headers['webhook-timestamp']; const signatures = headers['webhook-signature']; if (!id || !timestamp || !signatures) return false; if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 5 * 60) return false; const expected = createHmac('sha256', key).update(`${id}.${timestamp}.${body}`).digest(); return signatures.split(' ').some((signature) => { const [version, mac] = signature.split(','); if (version !== 'v1' || !mac) return false; const given = Buffer.from(mac, 'base64'); return given.length === expected.length && timingSafeEqual(given, expected); });}
const seen = new Set();
createServer((req, res) => { const chunks = []; req.on('data', (chunk) => chunks.push(chunk)); req.on('end', () => { const body = Buffer.concat(chunks).toString('utf8'); if (req.method !== 'POST' || !verify(req.headers, body)) { console.log('refused a request that is not signed by Passkaar'); res.writeHead(400).end(); return; } res.writeHead(204).end(); if (seen.has(req.headers['webhook-id'])) return; seen.add(req.headers['webhook-id']); const event = JSON.parse(body); console.log('verified', event.type, JSON.stringify(event.data)); });}).listen(8787, () => console.log('listening on http://localhost:8787'));What it checks, in order:
- The three headers are there:
webhook-id,webhook-timestampandwebhook-signature. - The timestamp is within five minutes of your clock, so an old event recorded by someone cannot be sent again later.
- The signature. Passkaar computes an HMAC-SHA256 over
{webhook-id}.{webhook-timestamp}.{body}with your endpoint’s secret (the part afterwhsec_, decoded from base64), and sends it in base64 asv1,<signature>. The header can hold several, separated by spaces (for a day after you roll the secret, it holds both), and one match is enough. Compare in constant time.
Use the raw body exactly as it arrived. A body parsed as JSON and written out again is not the same bytes, and its signature will not match.
Then it answers 204 at once and only afterwards does the work. Passkaar waits 15 seconds at most,
and retries anything that is not a 2xx. A retry carries the same webhook-id, which is why the
receiver remembers the ids it has handled (your real one keeps them in its database).
This is the Standard Webhooks scheme, so any Standard Webhooks library for your language can check it instead.
2. A public address
Section titled “2. A public address”Passkaar sends only to https addresses on the public internet. On a server, use its own address.
To try it from your computer, open a tunnel in a second terminal, for example with Cloudflare’s
free cloudflared:
cloudflared tunnel --url http://localhost:8787It prints an address like https://seasonal-burner-europe-since.trycloudflare.com. Back in
the first terminal, keep it:
URL=https://seasonal-burner-europe-since.trycloudflare.com/passkaar(Use the address your tunnel printed, not this one.)
3. Register the endpoint
Section titled “3. Register the endpoint”Choose the events you want; the events page lists them all:
curl -sS "$PASSKAAR_API/webhook-endpoints" \ -H "Authorization: Bearer $PASSKAAR_KEY" \ -H "Content-Type: application/json" \ -d "{\"url\": \"$URL\", \"events\": [\"card.created\", \"award.created\", \"award.reversed\", \"redemption.created\", \"refund.unresolved\"], \"description\": \"My receiver\"}" \ | tee endpoint.json | jq .201 Created:
{ "id": "32242268-9150-49b1-8c34-1df1e217fbdb", "url": "https://seasonal-burner-europe-since.trycloudflare.com/passkaar", "events": [ "card.created", "award.created", "award.reversed", "redemption.created", "refund.unresolved" ], "description": "My receiver", "enabled": true, "disabled_reason": null, "last_success_at": null, "last_failure_at": null, "created_at": "2026-11-22T02:50:27.763Z", "secret": "whsec_NTLx…"}secret is the endpoint’s signing secret, shown in this answer only. Keep it as you keep your key.
Start the receiver with it:
PASSKAAR_WEBHOOK_SECRET=$(jq -r '.secret' endpoint.json) node receiver.mjs & RECEIVER=$!listening on http://localhost:87874. Hear an event
Section titled “4. Hear an event”Ask Passkaar to send a test event to the endpoint:
ENDPOINT=$(jq -r '.id' endpoint.json)curl -sS -X POST "$PASSKAAR_API/webhook-endpoints/$ENDPOINT/test" \ -H "Authorization: Bearer $PASSKAAR_KEY" | jq .{ "event_id": "6607bcd1-ad12-41de-91a3-248e009bdc35"}A moment later the receiver prints:
verified webhook.test {"endpoint":{"id":"32242268-9150-49b1-8c34-1df1e217fbdb"}}Now something real. Record a sale for Bilal from the online guide, under a new order number:
CUSTOMER=$(jq -r '.customer.external_id' enrolment-online.json)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-$(date +%s)\", \"bill\": {\"total\": 1200, \"currency\": \"PKR\"}}" > /dev/nullverified award.created {"card":{"id":"6eec7c6a-8f73-4a25-8f0a-468b96fcd96b","card_id":"GB9-GB9-W9G"},"customer":{"id":"b704e4c6-f6c9-49ac-bd79-6692683c4a31","external_id":"store-customer-1795315683"},"program":{"id":"259975f9-719a-48c8-8dc9-eb7128114ebf","type":"points"},"award":{"id":"f05ce8f1-c301-4244-a81d-931c33533cfa","reference":"ORDER-1795315842"},"earned":{"points":120},"balance":{"type":"points","points":120,"unit_name":"beans","next_reward":null,"expiring":null},"occurred_at":"2026-11-22T02:50:42.956Z","source":"integration","branch_id":null}An event carries ids and facts, never a customer’s name, phone number or email: fetch what you need
with your key. It tells you about every change to the shop’s cards, whoever made it: your system,
the shop’s cashiers, or the customer’s own phone (source says which). card.card_id is here
because your connection signed Bilal’s store account up with this card; an event about a card your
system knows only from the counter, such as Ayesha’s, carries card_id: null, so match events to
cards by card.id.
And a request that is not from Passkaar is turned away:
curl -sS -o /dev/null -w '%{http_code}\n' -X POST http://localhost:8787/passkaar \ -H 'webhook-id: msg_fake' -H "webhook-timestamp: $(date +%s)" -H 'webhook-signature: v1,AAAA' \ -d '{"type": "award.created"}'400refused a request that is not signed by Passkaar5. When your receiver was down
Section titled “5. When your receiver was down”Failed deliveries are retried for about three days, at growing gaps. To catch up sooner, or to
check you missed nothing, read the event feed. It holds your connection’s events of the last 30 days, oldest first, and each page hands you a next_cursor to read on from:
curl -sS "$PASSKAAR_API/events?limit=3" \ -H "Authorization: Bearer $PASSKAAR_KEY" | tee events.json | jq '{events: [.data[] | {id, type, timestamp}], next_cursor}'{ "events": [ { "id": "83f2e44d-86d8-47cc-8b73-93fa57ed09ef", "type": "card.created", "timestamp": "2026-11-22T00:21:12.712Z" }, { "id": "2dcdb68f-a7e4-4fc8-92a7-fa9f08eb574e", "type": "award.created", "timestamp": "2026-11-22T00:21:53.429Z" }, { "id": "d5221878-c7d1-4748-a7f4-356fe47e603d", "type": "redemption.created", "timestamp": "2026-11-22T00:22:06.368Z" } ], "next_cursor": "WyIyMDI2LTExLTIyVDAwOjIyOjA2LjUwMloiLCIzIl0"}The first read, with no cursor, starts at your connection’s first event. Ask again with the
answer’s next_cursor for the next page:
CURSOR=$(jq -r '.next_cursor' events.json)curl -sS "$PASSKAAR_API/events?limit=3&cursor=$CURSOR" \ -H "Authorization: Bearer $PASSKAAR_KEY" | jq '{events: [.data[] | {id, type, timestamp}], next_cursor}'{ "events": [ { "id": "9ec405d6-400c-42db-abb3-9ee2fd37b760", "type": "card.created", "timestamp": "2026-11-22T00:22:42.532Z" }, { "id": "b64ae018-4126-4bc6-82b2-4d168f7f9d99", "type": "award.created", "timestamp": "2026-11-22T00:22:53.089Z" }, { "id": "c82b4bdc-4340-4fca-9971-59e5623d5a78", "type": "hold.created", "timestamp": "2026-11-22T00:22:54.013Z" } ], "next_cursor": "WyIyMDI2LTExLTIyVDAwOjIyOjU0LjA1NloiLCI2Il0"}The feed has no last page, so a cursor is never used up:
- Keep the last
next_cursoryou were given in your database, after you have handled that page’s events. When your receiver comes back, read on from it until a page holds fewer events thanlimit: you have caught up. Then keep that page’snext_cursorand ask again later. - With no cursor kept (a new system, or a lost one), read from the start without
cursor, and skip the events you have already handled by theirid. - An event joins the feed about ten seconds after it happens, so a feed read straight after a sale
may not show it yet.
typereads one kind only, such as?type=award.created.
An event’s id is the same as the webhook-id it was delivered with, so one store of handled ids
serves both.
6. Tidy up
Section titled “6. Tidy up”Stop the receiver, remove the endpoint you made, and stop the tunnel with Ctrl-C in its terminal:
kill "$RECEIVER"curl -sS -o /dev/null -w '%{http_code}\n' -X DELETE "$PASSKAAR_API/webhook-endpoints/$ENDPOINT" \ -H "Authorization: Bearer $PASSKAAR_KEY"204An endpoint that keeps failing is switched off after ten attempts with nothing delivered, and the
shop’s owner is told. An endpoint that answers 410 Gone is switched off at once. To change the
secret, use roll the secret; both secrets sign for 24 hours.
Next: from test to live.