Webhooks
Event types, payload format, HMAC-SHA256 signature verification in Node, PHP and Python, retries and best practices.
Webhooks tell your server when an invoice changes state, so you can fulfil orders automatically. Every delivery is signed with your endpoint's secret so you can prove it came from FlatCryptoPay.
Set up an endpoint
- In the dashboard, open Webhooks and add a public HTTPS URL. Up to 5 endpoints per account.
- Copy the signing secret (
whsec_...). It is shown once and stored encrypted; if you lose it, rotate it. - Click Send test event to deliver a
test.pingand check the response code.
Events
| Event | When | Typical action |
|---|---|---|
invoice.processing | A matching transaction was seen, waiting for confirmations. | Show "payment received, confirming". Do not ship yet. |
invoice.paid | Payment confirmed (crypto) or approved (card). | Fulfil the order. |
invoice.expired | No payment before expiry. | Release reserved stock. |
invoice.canceled | You canceled the invoice. | Close the order. |
test.ping | You clicked "Send test event". | Return 200. |
Payload
POST /webhooks/fcp HTTP/1.1
Content-Type: application/json
User-Agent: FlatCryptoPay-Webhooks/1.0
X-FCP-Event: invoice.paid
X-FCP-Event-Id: evt_Qm2x8LrT4cWb9nZ0aYk1Fd
X-FCP-Timestamp: 1764669600
X-FCP-Signature: 5f2b0c7e...(64 hex chars)
{"id":"evt_Qm2x8LrT4cWb9nZ0aYk1Fd","type":"invoice.paid","created":1764669600,"livemode":true,
"data":{"invoice":{"id":"inv_8fK2mQ9xLr3TzW1bN0aYc4","object":"invoice","status":"paid",
"amount":"49.00","currency":"USD","order_id":"1001","metadata":{},
"payment":{"via":"crypto","method":"usdt_tron","amount":"49.0037","asset":"USDT","network":"tron","tx_hash":"9f1c..."}, ...}}} Verify the signature
The signature is the lowercase hex HMAC-SHA256 of timestamp + "." + rawBody using your endpoint secret. Always:
- Use the raw request body exactly as received (do not parse and re-serialize JSON first).
- Compare with a constant-time function.
- Reject timestamps more than 5 minutes from your clock to stop replays.
- Deduplicate on
X-FCP-Event-Id: retries reuse the same id.
import crypto from 'node:crypto';
export function verifyFcp(rawBody, headers, secret) {
const ts = headers['x-fcp-timestamp'], sig = headers['x-fcp-signature'] || '';
if (!/^\d+$/.test(ts) || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
const expected = crypto.createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex');
return sig.length === expected.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
} $raw = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_FCP_TIMESTAMP'] ?? '';
$sig = $_SERVER['HTTP_X_FCP_SIGNATURE'] ?? '';
$expected = hash_hmac('sha256', $ts . '.' . $raw, getenv('FCP_WEBHOOK_SECRET'));
if (!ctype_digit($ts) || abs(time() - (int) $ts) > 300 || !hash_equals($expected, $sig)) {
http_response_code(400); exit;
}
$event = json_decode($raw, true); import hmac, hashlib, time
@app.post("/webhooks/fcp")
def fcp():
raw = request.get_data(as_text=True)
ts, sig = request.headers.get("X-FCP-Timestamp", ""), request.headers.get("X-FCP-Signature", "")
expected = hmac.new(SECRET.encode(), f"{ts}.{raw}".encode(), hashlib.sha256).hexdigest()
if not ts.isdigit() or abs(time.time() - int(ts)) > 300 or not hmac.compare_digest(expected, sig):
abort(400)
event = request.get_json()
return "", 200 Retries
Return any 2xx status within 10 seconds to acknowledge. Anything else (or a timeout) is retried with backoff: after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours, for up to 6 attempts in total. You can see every attempt and re-send a delivery from the dashboard.
Best practices
- Acknowledge quickly and do slow work (emails, provisioning) in a background job.
- Treat webhooks as a signal: for high-value orders, fetch
GET /api/v1/invoices/:idand checkstatus,amountandcurrencybefore fulfilling. - Handle events out of order:
invoice.paidcan arrive without a priorinvoice.processing. - Check
livemodeif one endpoint receives both test and live events.