Crypto payment webhooks and signature verification
A webhook is how your server learns that an invoice was paid. This page shows the headers, the payload, and working verification code you can paste into your handler.
How the webhook works
When an invoice reaches PAID, OVERPAID, PARTIAL, EXPIRED or CANCELLED, OpenBCP sends a JSON POST to the callback_url you gave when creating the invoice. Each request has two headers:
X-openbcp-Timestamp: Unix time in seconds when the event was sent.X-openbcp-Signature: hexHMAC-SHA256of"{timestamp}.{raw_body}", keyed with your API key.
Payload
{
"invoice_id": 42,
"external_id": "order-123",
"status": "PAID",
"amount_usdt": "30.020000",
"amount_received": "30.020000",
"shortfall": "0.000000",
"overpaid_by": "0.000000",
"deposit_address": "0x...",
"txid": "0x...",
"paid": true,
"paid_at": "2026-01-01T12:00:03Z"
}
Verify the signature
Python
import hmac, hashlib, time
def verify(api_key: str, raw_body: bytes, timestamp: str, signature: str) -> bool:
if abs(time.time() - int(timestamp)) > 300:
return False
expected = hmac.new(
api_key.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature)
Node.js (Express)
import crypto from "node:crypto";
import express from "express";
const app = express();
// Use the raw body for this route, not express.json()
app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => {
const ts = req.get("X-openbcp-Timestamp") || "";
const sig = req.get("X-openbcp-Signature") || "";
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return res.sendStatus(400);
const expected = crypto
.createHmac("sha256", process.env.PAYGATE_API_KEY)
.update(`${ts}.`)
.update(req.body)
.digest("hex");
const ok =
sig.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
if (!ok) return res.sendStatus(401);
const event = JSON.parse(req.body.toString("utf8"));
// fulfil the order here if event.status is PAID or OVERPAID
res.sendStatus(200);
});
PHP
<?php
$raw = file_get_contents("php://input");
$ts = $_SERVER["HTTP_X_OPENBCP_TIMESTAMP"] ?? "";
$sig = $_SERVER["HTTP_X_OPENBCP_SIGNATURE"] ?? "";
if (abs(time() - (int)$ts) > 300) { http_response_code(400); exit; }
$expected = hash_hmac("sha256", $ts . "." . $raw, getenv("PAYGATE_API_KEY"));
if (!hash_equals($expected, $sig)) { http_response_code(401); exit; }
$event = json_decode($raw, true);
// fulfil the order here if $event["status"] is PAID or OVERPAID
http_response_code(200);
Retries and idempotency
- Respond with any
2xxquickly. Do the slow work after responding. - Server errors and timeouts are retried a limited number of times with increasing delay.
- A
4xxresponse is treated as declined and is not retried. - Redirects are not followed.
- A webhook can arrive more than once. Key your fulfilment on
external_idorinvoice_idso a repeat does nothing.
Handling each status
| Status | What to do |
|---|---|
PAID | Fulfil the order. |
OVERPAID | Fulfil the order. Consider refunding overpaid_by. |
PARTIAL | Do not fulfil. shortfall shows what is still needed. |
EXPIRED / CANCELLED | Release any reserved stock. |
Callback URL rules
The URL must be a publicly reachable http(s) address. Localhost, private network addresses and cloud metadata addresses are rejected. To test from your laptop, use the sandbox with a tunnel such as ngrok or cloudflared.
Back to the crypto checkout API guide.
Frequently asked questions
How are OpenBCP webhooks signed?
Each request carries X-openbcp-Timestamp and X-openbcp-Signature. The signature is a hex HMAC-SHA256 of the timestamp, a dot and the raw request body, keyed with your API key.
Why verify the raw body?
If you parse and re-serialize the JSON, the bytes change and the signature check fails. Always compute the HMAC on the exact bytes you received.
What happens if my server is down?
Server errors and timeouts are retried with increasing delay. Respond with any 2xx quickly. Make your handler idempotent, because a webhook can be delivered more than once.
Which events are sent?
A webhook is sent when an invoice reaches PAID, OVERPAID, PARTIAL, EXPIRED or CANCELLED.
Can I test webhooks on my laptop?
Yes. Use the sandbox with a tunnel such as ngrok or cloudflared so the callback URL is publicly reachable.