Docs / API reference / Webhooks & signatures

Webhooks & signatures

bit2pay calls your server when a payment changes state. Always verify the signature before trusting an event.

Events

TypeSent when
payment.pendingA method was chosen; waiting for the transfer.
payment.confirmingTransfer detected, awaiting confirmations.
payment.paidConfirmed — fulfil the order.
payment.underpaidLess than the amount due was received.
payment.expiredThe payment expired unpaid.
payment.latePaid after expiry; waiting for merchant approval.
{
  "id": "evt_4f1d0c2b9a8e7d6c5b4a3f2e",
  "type": "payment.paid",
  "created": 1763548200,
  "data": {
    "id": "pay_9f2c1a7e3b4d5e6f7a8b9c0d",
    "order_id": "ORD-1042",
    "status": "paid",
    "amount": "25.00",
    "amount_received": "25.00",
    "method": "trc20",
    "tx_hash": "a1b2c3…",
    "confirmations": 21,
    "fee": "0.1250",
    "metadata": {"user_id": "42"}
  }
}

Verify the signature

Every request has the header B2P-Signature: t=<unix>,v1=<hex> where v1 = HMAC_SHA256(whsec_…, t + "." + raw_body). Compare in constant time, reject if |now − t| > 300 seconds, and verify against the raw body — not re-serialised JSON.

import crypto from "node:crypto";

export function verify(rawBody, header, secret) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false; // replay window
  const expected = crypto.createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
  const a = Buffer.from(expected), b = Buffer.from(parts.v1 ?? "");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}
// Express: use express.raw({ type: "application/json" }) so rawBody is the exact bytes.

Delivery & retries

Return a 2xx within 10 seconds. Anything else is retried after: 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours, 12 hours, 24 hours. Redirects are not followed. Events can arrive more than once or out of order — deduplicate on the evt_ id and use data.status as the source of truth.

Webhook URLs must be public https addresses; private, loopback and cloud-metadata addresses are refused.

Test mode

Use an sk_test_ key and a test-mode endpoint, then press Simulate payment on the test payment to receive payment.confirming and payment.paid. Any past delivery can be re-sent from the delivery log in Developers.