By the end of this lesson you will know who does what in an online payment, the safe 9-step flow your app must follow, and why your server, never the browser, decides that an order is paid.
You need: nothing installed yet, only a notes app to jot down the flow · Time: 8 minutes
Meera runs the Pune Photography Workshop. Every month she sells 30 seats at ₹499. Today people pay her on WhatsApp by UPI, she checks her bank app, and she types names into a notebook. Mistakes happen: a seat is given twice, a payment is missed, someone says "I paid!" with a cropped screenshot.
She asks you, a freelancer who builds with an AI agent, for a registration page: fill in name, email and phone, pay ₹499 by UPI or card, and get a seat automatically.
To collect the money you will use a payment gateway: a company that takes the payment from the customer's card, UPI app or net banking and sends it to the business's bank account. In this course the gateway is Razorpay. Your AI agent writes the code. You prompt, test with fake money, check, and decide.
Why?One real example through all five lessons means each lesson adds one piece to the same page. By the end you have a pattern you can reuse for tuition fees, coaching batches or event passes.
Every online payment has the same five actors. Learn their names, because your prompts and the AI's code will use them:
- Customer: the person paying, for example Asha on her phone.
- Browser: your registration page, running on Asha's phone. It shows forms and buttons. It is on her device, so she can change anything in it.
- Your server: your code running on a computer you control (for example on Vercel), plus your database, where you keep the list of registrations.
- Razorpay: shows the payment window (called Checkout), talks to banks and UPI, and tells your server what happened.
- Bank or UPI app: where Asha actually approves the payment, for example with her UPI PIN.
Match them Match each actor with its job
Tap an item on the left, then its meaning on the right.
Why?Most payment bugs come from giving a job to the wrong actor, usually letting the browser do your server's job. If you know who should do what, you can spot it in the AI's code.
Here is the flow Razorpay's own guide describes, drawn as nine numbered steps. The lines going down are the actors; each arrow is one message.
Nine steps. The browser starts it, but your server makes every decision. - Book. Asha fills the form and taps Pay ₹499. The browser tells your server only which ticket she wants.
- Create order. Your server looks up the price in its own list and asks Razorpay to create an order for ₹499. Razorpay counts money in paise (1 rupee = 100 paise), so ₹499 is
49900. Razorpay replies with anorder_id. - order_id comes back to the browser.
- Open Checkout. The browser opens Razorpay's payment window with your public Key ID and that
order_id. - Customer pays in her UPI app or with her card.
- Payment id and signature. Razorpay gives the browser a
razorpay_payment_idand arazorpay_signature: a code only Razorpay and your server can produce. - Send to server. The browser forwards these to your server.
- Verify. Your server re-calculates the signature with its secret key. Only if it matches does it mark the registration as paid.
- Webhook. Separately, Razorpay calls your server directly (a webhook) to say "order paid". This arrives even if Asha's phone died after step 5.
Why?Every step exists because something goes wrong without it. The order fixes the price, the signature proves the payment is real, and the webhook covers the cases where the browser never comes back.
The browser runs on the customer's phone, and anyone can open the browser's developer tools and change what it sends. Three things go wrong when an app trusts it:
- The amount is changed. If the browser sends "amount: 49900" to your server, a user can change it to "100" and get a ₹499 seat for ₹1. Fix: the browser sends only the ticket id; your server takes the price from its own list.
- A fake success. If your page marks a seat as paid when it lands on a "/success" page, or when the browser says "paid: true", anyone can type that address or send that message. Fix: your server verifies the signature (step 8).
- The tab closes. Asha pays, then her battery dies or the network drops before step 7. Money is taken, no seat. Fix: the webhook (step 9) updates your database anyway.
This is the same rule as in Logins, permissions and database rules: checks that matter happen on the server, every time.
CarefulA screenshot of "Payment successful" is not proof either. Your database row, written by your server after a verified signature or webhook, is the only thing that counts.
Now, without looking at the picture, put the flow in order:
Put in order Put the safe payment flow in the right order
Tap the steps in the order you would do them. Tap a placed step to remove it.
- 1
Why?If you can recite this order, you can read any AI-written payment plan and see which step is missing. That is your main job in this course.
Razorpay has two separate worlds:
- Test mode: fake money. You get test keys (the Key ID starts with
rzp_test_), and you pay with Razorpay's test cards and test UPI IDs. Nothing real is charged. Razorpay lets you use test mode before the business's account is verified. - Live mode: real money from real customers. It needs the business's account to be activated, and it uses a different pair of live keys.
You will build and test everything in test mode (lessons 2 to 4) and switch only in lesson 5. Test and live also have separate webhooks and separate secrets.
Why?Test mode lets you break things safely: try failed payments, closed tabs and duplicate webhooks a hundred times without anyone losing a rupee.
- Test mode: fake money. You get test keys (the Key ID starts with
You don't need this today, but a client will ask, so here is the short version (lesson 5 has the details):
- The client owns the account. Meera, as the business owner, signs up and completes KYC (identity checks: PAN, bank account and business details). The money goes to her bank account, not yours.
- Her website needs policy pages. Razorpay asks for links to pages like About us, Contact us, Pricing, Terms and conditions, Privacy policy and Cancellation/Refund policy before live keys are available.
- Fees. Razorpay takes a fee from each successful payment and sends the rest to the bank account, usually 2 working days after the payment is captured. Today the pricing page shows a standard platform fee of about 2% for common methods (some, like business credit cards, cost more), plus GST on that fee, and no setup or yearly fee. Offers and rates change, so check razorpay.com/pricing when you quote a client.
For GST on her ticket sales and invoices, Meera should ask a CA. That is not something you or the AI should guess.
- Five actors: customer, browser, your server (with the database), Razorpay, bank or UPI app.
- The safe flow: server creates the order, browser opens Checkout, server verifies the signature, webhook confirms.
- Never trust the browser for the price, for "success", or to come back at all.
- Build in test mode with fake money; the client's own account goes live later.
- Next: Test mode and API keys.
Create a free account to save your progress and open every lesson. Create free account