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
After a successful payment, the browser hands your server three values:
razorpay_payment_id,razorpay_order_idandrazorpay_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:
- Take the
order_idfrom your own database row (not the one the browser sent). - Join it with the payment id:
order_id + "|" + razorpay_payment_id. - Calculate an HMAC-SHA256 of that text with your Key Secret (an HMAC is a fingerprint that only someone with the secret can produce).
- 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
razorpayNode package has a helper,validatePaymentVerification, that does exactly this.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.
- Take the
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:
- Build the confirm route
- Add a webhook for the payments the browser misses
- Verify every webhook, on the raw body
- The usual AI mistakes, and how to spot them
- Recap