All entries

    Razorpay Webhook Verification and Duplicate Event Handling

    Verify Razorpay’s signature against the exact webhook body and make processing safe when an event is retried.

    A signed delivery box sits beside a stamp and a duplicate-delivery symbol
    Conceptual pixel-art illustration.

    Verify Razorpay’s signature against the exact webhook body and make processing safe when an event is retried.

    Build the example

    Read raw bytes before any JSON parsing. Compute HMAC-SHA256 with the webhook secret and compare digests with a constant-time comparison after validating length. After verification, use the Razorpay event ID to deduplicate delivery, then apply the verified state update and record the event atomically where possible. Checkout signature verification has a separate message format.

    Exercise a valid signed event whose order amount differs from the fixture’s amount. The signature check should pass and the transition should refuse the update. Also sign malformed JSON using the dummy secret and confirm the handler handles parsing safely. These checks distinguish verified delivery from acceptable content and an eligible business effect.

    EXPLAINED / SEQUENCE

    Signed delivery and durable effects

    Verify Razorpay’s signature against the exact webhook body and make processing safe when an event is retried.

    Example

    1. Verify

      hash the original bytes

    2. Deduplicate

      look up the verified event reference

    3. Commit

      record event and apply the effect atomically where possible

    THE KEY DISTINCTION

    record event and apply the effect atomically where possible

    Conceptual diagram for the synthetic example in this guide.

    Watch the failure boundary

    Verify signatures before inspecting the event as trusted data. A webhook sender can retry after your response is lost, so a memory-only set does not provide durable deduplication. Store the provider event reference and an internal effect reference. If side effects happen outside the database, give their delivery path its own idempotency key.

    Verify the behavior

    Use synthetic payloads with a dummy secret. Verify an original payload, reject the same JSON reserialized with different spaces, and replay the original event. Expect one durable business effect. A signature proves authenticity of the bytes, while amount, currency and payment state still need to match the operation.

    FURTHER READING

    Sources

    Technical references checked .

    END OF ENTRY / 55
    Eeshan Singh with Big Ben in London
    BEHIND THE JOURNAL

    Eeshan Singh

    I’m Eeshan Singh Pokharia, an AI Full Stack Developer and CoFounder of UltraFit360. I work across AI features, full-stack product development, and web and mobile experiences—from Figma and frontend interactions to the systems behind them.

    Verify signatures before inspecting the event as trusted data. A webhook sender can retry after your response is lost, so a memory-only set does not provide durable deduplication. Store the provider event reference and an internal effect reference. If side effects happen outside the database, give their delivery path its own idempotency key.

    Meet the author
    THE CONVERSATION

    Your side of the story.