Skip to content
FlatCryptoPay

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

  1. In the dashboard, open Webhooks and add a public HTTPS URL. Up to 5 endpoints per account.
  2. Copy the signing secret (whsec_...). It is shown once and stored encrypted; if you lose it, rotate it.
  3. Click Send test event to deliver a test.ping and check the response code.

Events

EventWhenTypical action
invoice.processingA matching transaction was seen, waiting for confirmations.Show "payment received, confirming". Do not ship yet.
invoice.paidPayment confirmed (crypto) or approved (card).Fulfil the order.
invoice.expiredNo payment before expiry.Release reserved stock.
invoice.canceledYou canceled the invoice.Close the order.
test.pingYou clicked "Send test event".Return 200.

Payload

Request
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:

  1. Use the raw request body exactly as received (do not parse and re-serialize JSON first).
  2. Compare with a constant-time function.
  3. Reject timestamps more than 5 minutes from your clock to stop replays.
  4. Deduplicate on X-FCP-Event-Id: retries reuse the same id.
Node.js
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));
}
PHP
$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);
Python (Flask)
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/:id and check status, amount and currency before fulfilling.
  • Handle events out of order: invoice.paid can arrive without a prior invoice.processing.
  • Check livemode if one endpoint receives both test and live events.
Start free: no fees, no documents