Get your API key

Lesson 4 of 5

Verify payments and handle webhooks

Check the payment signature on the server, set up a test webhook, verify it on the raw body, ignore repeats, and catch the usual AI mistakes.

9 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson your server will mark a registration as paid only after checking Razorpay's signature, and a test webhook will confirm payments even when the customer's tab closes, safely, once per event.

You need: the registration page from lesson 3, a preview or staging deployment with a public HTTPS address (Test like a user and go live), your coding agent · Time: 9 minutes

  1. After a successful payment, the browser hands your server three values: razorpay_payment_id, razorpay_order_id and razorpay_signature. Anyone can type three values into a request, so your server must check that Razorpay really made them.

    The signature is a code Razorpay calculates with your Key Secret. Your server repeats the same calculation and compares:

    1. Take the order_id from your own database row (not the one the browser sent).
    2. Join it with the payment id: order_id + "|" + razorpay_payment_id.
    3. Calculate an HMAC-SHA256 of that text with your Key Secret (an HMAC is a fingerprint that only someone with the secret can produce).
    4. If the result equals razorpay_signature, the payment is genuine. If not, reject it and change nothing.

    You don't write the maths yourself: the official razorpay Node package has a helper, validatePaymentVerification, that does exactly this.

    Diagram titled "Checking the payment signature (on the server)". Three inputs, order_id from your database, razorpay_payment_id from the browser, and RAZORPAY_KEY_SECRET from .env, flow into an HMAC-SHA256 box of "order_id|payment_id" with the Key Secret. The result is compared with razorpay_signature: yes leads to "Check amount, then mark PAID", no leads to "Reject. Not paid." A note says to use the order_id from your records, not one the browser sends
    Three inputs, one fingerprint, one comparison. Only a match can mark a seat as paid.
    Why?

    The signature turns "the browser says it paid" into "Razorpay says it paid". Without it, anyone could call your confirm route with made-up values and get a free seat.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. Build the confirm route
  2. Add a webhook for the payments the browser misses
  3. Verify every webhook, on the raw body
  4. The usual AI mistakes, and how to spot them
  5. Recap