# QuataPay webhook verification Each delivery is `POST` with JSON `{ "event": "...", "data": { ... } }` and the headers `X-QuataPay-Timestamp` (Unix seconds) and `X-QuataPay-Signature` (`sha256=` + lowercase hex). ``` signed_payload = X-QuataPay-Timestamp + "." + raw_body signature = "sha256=" + hex(HMAC_SHA256(QUATAPAY_WEBHOOK_SECRET, signed_payload)) ``` 1. Use the raw bytes of the request body, before any JSON parsing. 2. Compare in constant time. 3. Reject a timestamp more than 300 seconds from now. 4. Answer 400 on any failure and do nothing else. Test vector: secret `test_secret_do_not_use`, timestamp `1791370800`, body `{"data":{"amount":5000,"id":"pay-1"},"event":"gateway.payment.succeeded"}` gives `sha256=1c3a8d850ee6a783931573bb1066171269e25dcf1a8d9709ecb6bac778e3b121`. The timestamp is old, so a correct verifier rejects it unless the test fixes the clock. Events: `gateway.payment.succeeded`, `gateway.payment.failed`, `gateway.payment.cancelled`, `gateway.payment.expired`, `gateway.payment.escrowed`, `gateway.payment.released`. Fulfil on `gateway.payment.succeeded`; it can follow `gateway.payment.expired` when a Mobile Money approval is confirmed late. `data` fields: `id`, `payment_id`, `slug`, `mode`, `amount`, `currency`, `status`, `customer_reference`, `metadata`, `payment_method`, `transaction_id`, `completed_at`, `created_at`; `failure_reason` on failed, `cancel_reason` on cancelled, `simulated: true` on sandbox simulations. Delivery: answer 2xx within 5 seconds. 5 attempts (1 minute, 5 minutes, 30 minutes, 2 hours), only for events younger than 24 hours. The same event can arrive twice or out of order: insert `(data.id, event)` under a UNIQUE constraint and skip duplicates; each body also carries `sequence` (only grows, same on retries) and `created_at`: handle every event type when it arrives (never skip one because another event for the payment had a higher `sequence`), use `sequence` only to keep the newest copy of `data`, and take the current state from `data.status`; compare `data.amount` and `data.customer_reference` with your order before marking it paid. Endpoints must be public https URLs; the signing secret is shown once when the endpoint is created (merchant panel, Developer, Webhooks).