The key points
- The checkout callback runs in the customer's browser; the webhook is the server-to-server record the order status depends on.
- Test mode and Live mode have separate webhooks, so each one gets its own URL, secret and event list.
- Razorpay retries a failed delivery with exponential backoff for 24 hours and then disables the webhook until you turn it back on.
- Delivery is at least once and not always in order, so every handler checks the event id and the current order state before acting.
- A scheduled reconciliation job catches the payment whose webhook never arrived.
Why does the order status depend on the webhook and not the checkout?
Two things can tell you a customer has paid. The checkout handler or callback runs in the customer's browser or app, and it fails whenever the tab closes, the phone loses signal or a UPI app takes the customer away and never brings them back. The webhook is Razorpay's server calling your server, and it carries on regardless of what the customer's device does. Razorpay's webhooks overview draws the same line: the callback_url is a checkout parameter for redirect and WebView flows and is not a substitute for webhooks when you track payment status on your server.
So the browser can show a thank-you screen, but the order moves to paid only when a verified webhook, or a reconciliation call to Razorpay's API, says so. If you are still choosing a gateway and checkout, start with accepting UPI and card payments on an Indian website and come back here for the server side.
How do you create the webhook in the Razorpay Dashboard?
Razorpay's payment webhook setup guide gives the path: log in, open Accounts & Settings, click Webhooks under Website and app settings, then + Add New Webhook. The Webhook Setup form asks for four things.
- URL: a public endpoint on your server. Razorpay recommends HTTPS, rejects localhost and allows up to 30 URLs per account.
- Secret: a string you choose, used to sign every delivery. It is optional in the form, recommended by Razorpay, and does not need to be your API key secret. Store it in your server's environment, never in front-end code.
- Alert Email: the inbox that receives failure and deactivation notices. Use a shared address someone reads, not a developer's personal mail.
- Active Events: the events this URL receives. Tick only the ones your code handles.
Why does a correct setup still receive nothing?
Three placement rules catch most first setups. Test and Live mode have separate webhooks, so a Live payment never reaches a URL saved only in Test mode. The webhooks overview says webhook URLs must use port 80 or 443, so an API on port 3000 needs a reverse proxy in front. And Razorpay's webhook IPs must be allowed through your server: a security group that blocks them looks exactly like Razorpay sending nothing.
Which events should you tick?
For one-time payments the order event is the one to fulfil on. Razorpay's payment events page explains that order.paid fires when the order status changes to paid and carries both the order and payment entities, while payment.captured carries only the payment. Why you should never ship on payment.authorized, and what to do when events arrive out of sequence, is covered in Razorpay authorized but not captured.
Add payment.failed if you follow up abandoned payments, for example with a WhatsApp nudge built the way payment reminders on WhatsApp are. Add the refund events if refunds start anywhere other than your own admin screen: refund.processed is the one that closes a return, and refund.failed is the one somebody must see. Payment links have their own paid, expired and cancelled events, which a hotel booking hold uses to confirm or release a room. A banquet hall uses the same payment events to turn a held date into a confirmed one, as set out in how a venue should hold a date and take a deposit.
How do you verify X-Razorpay-Signature?
Razorpay's validation guide states that the signature in the X-Razorpay-Signature header is an HMAC computed with SHA256, using your webhook secret as the key and the webhook request body as the message. Your endpoint computes the same HMAC and rejects any mismatch. The official SDKs ship helpers for this: validateWebhookSignature in Node.js, verify_webhook_signature in Python, verifyWebhookSignature in PHP, Java and .NET.
The guide carries one warning in bold: do not parse or cast the request body before you compute the signature. Most frameworks parse JSON before your handler runs, and a reserialised body that differs by one space from what Razorpay signed fails every check. Capture the raw body on this one route, verify it, and only then parse it. We compare the two signatures with a constant-time function so the check leaks nothing through timing.
Rotating the secret has a catch the guide also spells out: retries of events created before the change are signed with the old secret. Keep the old secret valid for the 24-hour retry window and try both before rejecting.
What happens when your endpoint is slow or down?
The setup guide is exact here. Every delivery must get a 2xx response within 5 seconds; any other status, or a timeout, counts as a failure. A failed event is retried at growing intervals under an exponential backoff policy for 24 hours, and if failures continue for 24 hours the webhook is disabled. Nothing flows again until someone fixes the cause and re-enables it in the Dashboard, and the notice goes to the Alert Email.
Two design choices follow. First, the handler does as little as possible inside those 5 seconds: verify the signature, write the raw event to a table or queue, return 200. Sending the invoice email, updating Tally, or messaging the customer happens in a worker that reads the queue. Second, someone owns the alert inbox, because a disabled webhook leaves every later payment to reconciliation.
How do you stop a retried event from being processed twice?
Razorpay's webhook best practices say delivery follows at-least-once semantics: if your server accepts an event but does not answer within 5 seconds, the session times out and the same event is sent again. The x-razorpay-event-id header is unique per event, so store it with a unique constraint and skip any id you have already recorded.
The event id stops a duplicate delivery. It does not stop two different events, say payment.captured and order.paid, from both trying to mark the same order paid. So the business action is idempotent too: if the order is already paid, the worker logs the event and stops. Status only moves forward. The same pattern, with Stripe's headers instead, is written out step by step in Stripe webhooks in n8n: idempotency and replay.
How do you test webhooks before going live?
Test events fire on transactions made in Test mode, and the validation guide notes the payload structure is the same in Test and Live, so a passing test run is a fair rehearsal. Localhost cannot receive them, because delivery needs a public URL, and Razorpay blacklists many tunnelling and request-inspection domains, ngrok.io and webhook.site among them. The guide suggests a zrok tunnel, or a staging server configured as the Test mode webhook, which is the better rehearsal.
Our pre-launch run covers a successful payment, a failed one, a refund, a wrong secret (the endpoint must reject it), a handler forced past 5 seconds (the retry must not fulfil twice), and the endpoint switched off for an hour (reconciliation must still find the payment).
How do you catch a payment whose webhook never arrived?
Webhooks are near real-time and asynchronous, and the best practices page says you may poll the payment APIs as well for business-critical flows. That is the reconciliation job. Every few minutes, it picks orders that are still pending after a set time and calls GET /v1/orders/{id}/payments, which returns every payment attempt for that order, successful and failed. Once a night, it walks GET /v1/payments with from and to timestamps, in pages of up to 100 using count and skip, and compares the captured payments against your own records.
Anything Razorpay shows as captured that your system does not is a missed webhook: the job marks it paid through the same idempotent worker, so it cannot double up with a late delivery. Anything your system shows as paid that Razorpay does not is a bug worth an alert. WhatsApp webhooks need the same discipline, as why WhatsApp webhooks fail shows, and the Cashfree version of this setup is in Cashfree webhooks: signature, retries and reconciliation.
How does Softivum build a Razorpay integration?
We build the endpoint, queue, worker and reconciliation job as one piece, either as custom software inside your app or as an n8n workflow through workflow automation. For stores it sits inside the ecommerce build, so order, stock and invoice updates read from the same verified event. The Razorpay account, keys and webhook secret stay in your name, and the Live webhook goes on only after the Test mode run above passes. For a venue that takes booking deposits by payment link, the same verified event confirms the date, as in what banquet hall booking software should do.
Razorpay webhook events and what your system should do with each
| Event | When Razorpay sends it | What your system does |
|---|---|---|
| order.paid | The order status changes to paid; payload holds the order and the payment | Mark the order paid and start fulfilment, once |
| payment.captured | A payment is successfully captured; payload holds only the payment | Mark paid if the order is not already; otherwise just log it |
| payment.authorized | A payment is authorised (it may already be captured when the event arrives) | Capture it if you use manual capture; never fulfil on it |
| payment.failed | A payment fails; not sent if it fails during the first authorisation, and it can be followed by payment.captured after a retry | Log the reason; trigger a follow-up message if the customer opted in |
| payment.pending | On Standard Checkout, a cash on delivery order is placed but not collected | Hold the order in a COD state for confirmation |
| refund.processed | A refund completes | Close the return and update the invoice or credit note |
| refund.failed | Razorpay cannot process a refund | Alert a person; the customer is still owed money |
Before you switch on the Live mode webhook
- Separate Test and Live webhooks exist, each with its own secret stored on the server
- The URL is public HTTPS on port 443 and Razorpay's webhook IPs are allowed through the firewall
- Only the events your code handles are ticked
- The signature is checked on the raw body before any parsing
- The handler stores the event and returns 200 well inside 5 seconds
- x-razorpay-event-id is saved with a unique constraint and repeats are skipped
- Order status only moves forward, whichever event arrives first
- A reconciliation job checks pending orders and the previous day's payments
- The Alert Email goes to a shared inbox that someone reads daily
Sources
Rules and guidance this answer relies on. Policies change, so check the current version before acting on it.
- Razorpay Docs: Webhooks overview
- Razorpay Docs: Set up and edit payment webhooks
- Razorpay Docs: Validate and test webhooks
- Razorpay Docs: Webhook best practices
- Razorpay Docs: Payment webhook events
- Razorpay Docs: Refund webhook events
- Razorpay API: Fetch payments for an order
- Razorpay API: Fetch all payments
