Razorpay signs each webhook with X-Razorpay-Signature, a hex HMAC-SHA256 of the raw body using the secret you set when creating the webhook. There is no timestamp, so an exact replay of a captured Razorpay webhook still carries a valid signature. Each event also has an X-Razorpay-Event-Id header, and the body names the event: {"entity":"event","event":"payment.captured","payload":{…}}.
Receive Razorpay webhooks on localhost
hwcli listen razorpay-events --forward :3000/webhooks/razorpay --include-sensitive
Add the endpoint URL in the Razorpay Dashboard under Webhooks (use Test Mode while developing) and choose the events you need. HookWatcher recognizes Razorpay requests from their signature and event-ID headers and labels each one with its event, such as payment.captured or order.paid. --include-sensitive delivers the signature header to your handler.
Replay payments
hwcli replay evt_51c8e2d0 # exact, signature still valid hwcli replay evt_51c8e2d0 --duplicate 3 # the same event three times hwcli replay evt_51c8e2d0 --remove-signature # your handler should reject this
Modifying the body invalidates the signature. HookWatcher can generate test signatures for Stripe and GitHub secrets, but not yet for Razorpay, so test modified Razorpay payloads with verification against a test secret, or use them to check your rejection path. HookWatcher doesn't verify Razorpay signatures on capture either; your handler is the place that checks them.
Things to test for Razorpay
- Duplicates: Razorpay retries deliveries that don't get a 2xx, so the same event can arrive more than once. Key on
X-Razorpay-Event-Idand process each event once. - Ordering:
payment.capturedandorder.paidfor the same payment can arrive in either order. Replay them both ways and check the order ends in the same state. - Amounts: Razorpay sends amounts in the smallest currency unit (paise for INR). Use
--setto try a different amount and check your handler compares it with the order. - Raw bodies: compute the HMAC over the bytes received, not over re-serialized JSON.