Skip to content
ArionPay

Knowledge base · 4 min read

Verifying Webhook Signatures

Check the ArionPay-Signature header on every webhook before you fulfil an order.

Verifying Webhook Signatures

What we send

Each webhook is a JSON POST to your store's webhook URL with these headers:

  • ArionPay-Event: one of invoice.pending, invoice.partial, invoice.paid, invoice.expired or invoice.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

  1. Compute the signature from the raw request body and compare it in constant time.
  2. Reject old timestamps (we suggest more than 5 minutes).
  3. Use the event ID so a repeated delivery doesn't ship an order twice.
  4. Find the order by data.invoice.id (saved when you created the invoice) and check amountFiat and currency.
  5. 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'));
}