Webhooks
Configuring gateway webhooks, how signatures are verified, and what your relay endpoint receives.
Webhooks are the only path to SUCCESS. Polling can advance a payment through intermediate
states but never to a captured one, so the webhook pipeline is load-bearing rather than a
convenience.
Configure your gateway dashboard
| Gateway | Endpoint |
|---|---|
| Razorpay | https://api.checkoutos.in/webhooks/razorpay |
| Paytm | https://api.checkoutos.in/webhooks/paytm |
What checkoutOs does with one
Verifies the signature
Per gateway, with a dedicated function. Razorpay is HMAC-SHA256 over the raw body; Paytm
uses its CHECKSUMHASH scheme over a form-encoded body. A failure returns
401 GATEWAY_INVALID_SIGNATURE.
Applies the state transition
Valid transitions are applied; invalid ones are ignored with a warning, not errors. A late
payment.failed for an already-succeeded payment is a no-op.
Backfills gatewayPaymentId
This is the only place gatewayPaymentId (e.g. pay_XXXX) is ever set, which is why a
refund cannot precede a webhook.
Relays a normalized event
Fire-and-forget to WEBHOOK_RELAY_URL, 5-second timeout. Redis is updated before the relay is
attempted.
Body-parsing order
This order in src/app.ts is load-sensitive
1. express.raw() for /webhooks/razorpay
2. express.urlencoded() for /webhooks/paytm
3. mount the webhook router
4. express.json() for every other routeRazorpay's signature is computed over raw bytes, so a JSON round-trip invalidates it. Paytm
posts form-encoded. Reordering this middleware breaks webhooks silently — the endpoint still
returns 200, it just never verifies.
What your relay endpoint receives
{
"paymentId": "chk_a1b2c3d4e5f6a7b8",
"gateway": "razorpay",
"gatewayPaymentId": "pay_ABC123",
"gatewayOrderId": "order_ABC123",
"event": "payment.captured",
"status": "SUCCESS",
"amount": 50000,
"currency": "INR",
"raw": {}
}Your application always receives a chk_ prefixed paymentId, which is the stable key to use
in your own records. The payload is built as { paymentId, ...event }, so the gateway-native
IDs and the raw gateway payload are forwarded too. Treat those as informational; do not key
your ledger on them.
Relay failures do not fail the webhook
Deliberate asymmetry
A relay failure logs a warning and still returns 200 to the gateway. A gateway retrying
forever because your server is down is worse than a dropped relay you can reconcile by
polling GET /payments/:chkId.
Treat the relay as an optimisation, not a guarantee. If your ledger must be exact, reconcile against the status endpoint on a schedule rather than trusting that every relay landed.
Testing webhooks locally
For Razorpay, post a signed body yourself — the signature is HMAC-SHA256 of the raw payload
with RAZORPAY_WEBHOOK_SECRET.
For Paytm, send a form-encoded body with a valid CHECKSUMHASH, or exercise the mock gateway
handlers used by the integration suite.