AI & automation10 min readReviewed by the Softivum team,

How do I set up Cashfree webhooks so no payment is missed?

Short answer

Add a public HTTPS endpoint in the Cashfree Merchant Dashboard under Developers, Webhooks, and pick the events you act on. Verify x-webhook-signature as a Base64 HMAC-SHA256 of the timestamp plus the raw body, return 200 quickly, queue the work, skip duplicates by cf_payment_id, and confirm any doubtful order with the Get Order API.

A shopkeeper's counter in an Indian store with a card machine at the edge of the frame and a laptop behind it showing a blurred list of paid orders.

The key points

  • The browser redirect after payment can fail; the webhook is Cashfree's server calling yours, and the order status should depend on it.
  • Cashfree signs each delivery with the timestamp and the raw body, so the body must be checked before any JSON parsing.
  • A response outside 2xx, including a redirect, is a failure, and the retry schedule depends on the policy set on the endpoint.
  • Delivery is at least once and not ordered, so each handler skips repeats and checks the order's current state.
  • A reconciliation job and the dashboard's Batch Resend cover the payment whose webhook never arrived.

Why should the order status depend on the webhook and not the return page?

A customer who pays on Cashfree is sent back to your site, and that page proves nothing about the payment. Worse, the customer may close the tab, lose signal, or leave a UPI app and never return. The payment still succeeded. Only a message from Cashfree's server to yours reliably tells you so.

That message is the webhook. Cashfree's webhooks overview describes it as an HTTP POST to a URL you register, sent when an event happens, such as a payment succeeding. The return page can show a thank-you screen. The order moves to paid only when a verified webhook, or a call to Cashfree's API, says so.

If you have not yet picked a gateway or checkout, start with accepting UPI and card payments on an Indian website. If you also use Razorpay, the matching guide is setting up Razorpay webhooks correctly.

How do you add a webhook endpoint in the Cashfree Merchant Dashboard?

Cashfree's endpoint configuration guide gives the route: log in to the Merchant Dashboard, open your product's Webhooks page (for Payment Gateway it sits under Developers), choose Add Webhook URL, enter the URL, and click Test & Add Webhook. Cashfree validates the endpoint before saving it.

The URL must be a public HTTPS endpoint that you control. HTTP is not supported for production, and a server running on your laptop will not do. For local work, use a tunnelling tool such as ngrok, or a request inspector such as webhook.site, with sandbox transactions.

  • Endpoint URL: one dedicated route, for example one that only handles Cashfree, so its logs are easy to read.
  • Webhook version: each Payment Gateway endpoint carries an API version. Newer versions add features, such as the idempotency header available from version 2025-01-01. Choose one version and write your parser for that version only.
  • Retry policy: set per dashboard endpoint. The options and one exception are covered below.
  • Sandbox and production: configure each environment separately, with its own URL and its own credentials, and test in the sandbox first.

Which Cashfree webhook events should you act on?

For a Payment Gateway checkout, Cashfree's payment webhook reference lists three events. PAYMENT_SUCCESS_WEBHOOK fires when a payment completes successfully. PAYMENT_FAILED_WEBHOOK fires when an attempt fails after a failed response from the bank. PAYMENT_USER_DROPPED_WEBHOOK fires when the customer abandons the flow, for example by never entering the bank OTP or the UPI PIN.

The success payload carries the order block (data.order.order_id and the order amount) and the payment block (data.payment.cf_payment_id, data.payment.payment_status, the payment method and the bank reference). The top-level type field names the event. Cashfree's events-by-product page also lists REFUND_STATUS_WEBHOOK and SETTLEMENT_STATUS_WEBHOOK for refunds and settlements, and separate events for subscriptions and payment links. Tick only the events your code handles.

Follow-up messaging is a natural use of the failed and dropped events. A dropped payment can start a payment reminder on WhatsApp if the customer has opted in.

How do you verify x-webhook-signature?

Cashfree's payloads and signatures guide puts the signature in the x-webhook-signature header and the timestamp in x-webhook-timestamp. The expected signature is the Base64 encoding of an HMAC-SHA256 over the timestamp followed by the raw body, using your client secret as the key. Your endpoint computes the same value and rejects the request if it differs. The official SDKs include a helper for this, named PGVerifyWebhookSignature.

Compute the signature from the raw request body string, every time. Most frameworks parse JSON before your handler runs, and a re-serialised body can differ in whitespace, field order or number format, which fails every check. Capture the raw body on this one route, verify it, and only then parse it. We compare the two values with a constant-time function.

On secret rotation, Cashfree signs each webhook with the secret that was active when the event was sent, so keep the previous secret valid until in-flight deliveries have been processed. Never put the client secret in browser code.

Should you reject old timestamps?

Cashfree's reliability and operations guide says that for Payment Gateway you should reject requests whose x-webhook-timestamp is older than five minutes. This blocks someone replaying a captured request later.

Test this rule before you switch it on. A retry that arrives after the first attempt failed should not be thrown away by your own freshness check. In the sandbox, make your endpoint fail once on purpose, wait for the retry, and confirm your code accepts it. If the retry is rejected, the rule is too tight for your retry policy, and the signature plus the duplicate check carry the protection instead.

What happens when your endpoint is slow or down?

Cashfree retries any delivery that does not get HTTP 200, and counts 3xx redirects as failures. A common cause is a redirect from http to https or from a bare domain to www, so give Cashfree the final URL.

For Payment Gateway the retry policy is set per endpoint in the dashboard. The default is up to 3 retries at 2, 10 and 30 minutes. Fixed allows up to 10 retries at one interval, Exponential up to 10 with a base interval and multiplier, and Custom up to 10 with each interval set by you. This applies to URLs you add in the dashboard. A URL passed as notify_url in the Create Order request uses Cashfree's fixed NOTIFY_URL configuration with the default policy, so register the endpoint in the dashboard if you want a longer one. For a store, a longer policy such as Exponential gives you room to fix a bad deploy and still receive the events.

Treat speed as a design rule. Verify the signature, write the raw event to a table or queue, return 200, and let a worker do the rest: the invoice email, the stock update, the Tally entry, the customer message. Alert on sustained delivery failures, and name the person who gets the alert.

How do you stop a repeated event from being processed twice?

Cashfree's delivery is at least once, so the same event can arrive twice, for example when a slow response triggers a retry. Cashfree's reliability guide says to use a stable business identifier as the key and to check whether you have processed it before any irreversible action. Use cf_payment_id plus the event type, because a refund event shares its cf_payment_id with the payment. Put a unique constraint on that pair so the database refuses the second insert.

From webhook version 2025-01-01, Cashfree also sends an x-idempotency-key header, unique for each unique payload, which works as a second de-duplication key.

Delivery order is not guaranteed either. A failed event can arrive after a later success for the same order. So the business action is idempotent as well: if the order is already paid, log the event and stop, and let status only move forward. The same pattern for another gateway is written step by step in Stripe webhooks in n8n: idempotency and replay.

How do you catch a payment whose webhook never arrived?

Webhooks can still be missed: an outage longer than your retry policy, a firewall rule, a disabled endpoint. Two tools cover this. The first is the dashboard. The Webhooks Logs page has a Batch Resend button, and Cashfree's overview says you can resend by transaction ids or by a time window of up to 24 hours. It works for payment webhooks only.

The second is your own reconciliation job. Every few minutes it takes orders that are still pending after a set time and asks Cashfree for the truth with the Get Order API, GET /orders/{order_id}. Its order_status is PAID when the order has one successful transaction, ACTIVE when there is none yet, and EXPIRED when the order lapsed unpaid. TERMINATED and TERMINATION_REQUESTED mean the order was cancelled, so close it on your side too. When order matters, reconcile state through the API after the webhook arrives.

Anything Cashfree shows as PAID 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 Cashfree does not is a bug worth an alert. WhatsApp webhooks need the same discipline, as why WhatsApp webhooks fail explains.

Do you need to allow Cashfree's IP addresses?

Cashfree's reliability guide lists sandbox and production IP addresses for webhook calls and says IP allow-listing is optional. If your network policy requires it, allow HTTPS on port 443 from the addresses on that page. If your endpoint stops receiving anything after a firewall change, check this first, then the dashboard delivery logs, then whether the URL still returns 200 for a valid signed request. Read the list from that page when you configure the firewall, because addresses can change.

How do you test before going live?

Run the whole path in the sandbox with a test endpoint. A passing run covers a successful payment, a failed one, a dropped one, a request with a wrong signature (the endpoint must reject it), the endpoint answering with an error once (the retry must not fulfil twice), and the endpoint switched off for an hour (reconciliation or Batch Resend must still recover the payment).

When the rehearsal passes, add the production endpoint with its own URL and credentials. Cashfree's migration advice for versions is a useful habit for any change: add the new endpoint, return 200 on both, move your code across, then disable the old one.

How does Softivum build a Cashfree integration?

We build the endpoint, queue, worker and reconciliation job as one piece, either inside your app as custom software or as an n8n flow through workflow automation. The Cashfree account and API keys stay in your name, and the production webhook goes on only after the sandbox run above passes.

Cashfree webhook behaviours and what your system should do

Cashfree webhook behaviours and what your system should do
TopicWhat Cashfree documentsWhat your system does
Success eventPAYMENT_SUCCESS_WEBHOOK when a payment completesMark the order paid once and start fulfilment
Failed eventPAYMENT_FAILED_WEBHOOK after a failed bank responseLog the reason; send a follow-up if the customer opted in
Dropped eventPAYMENT_USER_DROPPED_WEBHOOK when the customer leaves the flowKeep the order open; optionally remind
SignatureBase64 HMAC-SHA256 of timestamp plus raw body, in x-webhook-signatureVerify on the raw body before parsing; reject a mismatch
FailureAny response outside 2xx, including redirectsReturn 200 right after verification and queue the work
RetriesDefault 3 retries at 2, 10 and 30 minutes; fixed, exponential and custom up to 10Pick a policy that outlasts a bad deploy
DuplicatesAt-least-once delivery, order not guaranteedUnique constraint on cf_payment_id plus event type (or x-idempotency-key); status only moves forward
Missed eventsBatch Resend for payment webhooks, up to a 24-hour windowReconcile pending orders with the Get Order API

Before you switch on the production webhook

  • Sandbox and production endpoints exist, each with its own URL and credentials
  • The URL is public HTTPS and returns 200 directly, with no redirect
  • Only the events your code handles are selected, on one webhook version
  • The signature is checked on the raw body before any parsing
  • The handler stores the event and returns 200 before doing slow work
  • cf_payment_id plus event type (or x-idempotency-key) is saved with a unique constraint and repeats are skipped
  • Order status only moves forward, whichever event arrives first
  • A retry policy that outlasts a bad deploy is set on the dashboard endpoint, not left to notify_url
  • A reconciliation job checks pending orders with the Get Order API
  • Someone reads the delivery logs and failure alerts every day

Sources

Rules and guidance this answer relies on. Policies change, so check the current version before acting on it.

  1. Cashfree Docs: Webhooks overview
  2. Cashfree Docs: Configure webhook endpoints
  3. Cashfree Docs: Webhook payloads and signatures
  4. Cashfree Docs: Webhook reliability and operations
  5. Cashfree Docs: Payment webhooks
  6. Cashfree Docs: Webhook events by product
  7. Cashfree API: Get Order

Questions people also ask

Cashfree signs webhooks with your client secret, the same secret you use for API calls from your server. You do not create a separate one. Keep it in server environment variables, use the sandbox secret for sandbox events, and never expose it in browser code.

Most often the body was parsed and re-serialised before the check, so the bytes differ from what Cashfree signed. Another cause is forgetting to put the x-webhook-timestamp value in front of the raw body when you build the signed string.

Cashfree treats any response outside 2xx as a failure and retries on the policy set for the dashboard endpoint, three times by default. After that, use Batch Resend in the dashboard for payment webhooks, or find the order with the Get Order API.

Want this applied to your business?

Tell us what you are planning in a free 30-minute call, or have your current website checked first with no call needed.

Get a Free 2-Minute Website Audit

Free 30 minutes · no obligation

WhatsAppCall