Verifying Webhook Signatures
What we send
Each webhook is a JSON POST to your store's webhook URL with these headers:
ArionPay-Event: one ofinvoice.pending,invoice.partial,invoice.paid,invoice.expiredorinvoice.needs_review.ArionPay-Event-Id: a unique ID. Store it and ignore repeats.ArionPay-Signature:t=<timestamp>,v1=<hex>, where v1 is the HMAC-SHA256 of<timestamp>.<raw body>signed with your store's webhook secret.
Before you fulfil an order
- Compute the signature from the raw request body and compare it in constant time.
- Reject old timestamps (we suggest more than 5 minutes).
- Use the event ID so a repeated delivery doesn't ship an order twice.
- Find the order by
data.invoice.id(saved when you created the invoice) and checkamountFiatandcurrency. - Answer with a 2xx status within 10 seconds. Other answers, redirects and timeouts are retried for about 3 days.
Webhooks from test invoices are marked as test (livemode: false). In production, act only on livemode: true. The webhook secret (whsec_…) is not your API secret: you get it on the Webhooks page with "Replace secret".
// Node.js
const crypto = require('crypto');
// rawBody: the request body exactly as received (a string), before any JSON parsing
function verifyArionPayWebhook(rawBody, header, secret, toleranceSec = 300) {
const parts = Object.fromEntries(header.split(',').map((p) => p.trim().split('=')));
const ts = parts.t || '';
const given = parts.v1 || '';
if (!/^\d+$/.test(ts) || Math.abs(Date.now() / 1000 - Number(ts)) > toleranceSec) return false;
if (!/^[0-9a-f]{64}$/.test(given)) return false;
const expected = crypto
.createHmac('sha256', secret)
.update(`${ts}.${rawBody}`)
.digest();
return crypto.timingSafeEqual(expected, Buffer.from(given, 'hex'));
}