Skip to main content

Handle Repeat Cashfree Webhooks Without Fulfilling Twice

Design a payment handoff that verifies incoming events, reconciles the order, and applies fulfilment only once.

Two payment slips entering one gate and a single fulfilment receipt leaving it with the headline “One Payment. One Fulfilment.”.

Your server receives a successful payment event, updates the order and times out before responding. Cashfree retries delivery. The next request should receive an acknowledgement, and the customer should still get one fulfilment. A second request may also be a genuinely different payment attempt for the same order. The code has to tell those cases apart.

Verify before changing state

Read the raw request body and verify the signature using Cashfree’s current instructions. Parse after verification, since JSON reserialisation can change the signed bytes. Match the order, currency and amount to the expected record. Handle each payment attempt according to its provider status. A failed attempt should not overwrite a successful one for the same order.

Keep the provider payment ID and your own order ID separately. One identifies an attempt. The other identifies the thing you intend to fulfil.

Incoming eventRetainFulfilment decision
Repeat of an already recorded successful attemptExisting payment referenceReuse the existing fulfilment intent
Failed attempt for an unpaid orderAttempt outcome for supportLeave the order unfulfilled
Different successful payment reported for a paid orderBoth payment references for reconciliationKeep one fulfilment and raise the discrepancy

Apply the business change once

In one database transaction, record the verified payment, transition the eligible order to paid and insert an outbox entry keyed to the order and fulfilment type. Put a uniqueness constraint on the outbox identity. A separate worker can process it after the transaction commits. If your app responds before recording the outcome, it can lose work even if the provider never retries.

The fulfilment worker also needs its own retry policy. Using a unique row prevents creating two intents. If it sends an external command and loses the response, use the same external idempotency key or reconcile what happened. The payment webhook and the fulfilment action have different failure boundaries.

Test replays in a sandbox with recognised fixtures. Try success twice, a failure after success and two different attempts arriving close together. Review the resulting payment and order state, then count downstream fulfilments. A 200 response alone tells you that the handler acknowledged the event.

Sources

Build a project

© 2026 All rights reserved.