
Introduction
If you are building a website or app and want to accept online payments in India, Razorpay is one of the most popular choices.
Razorpay helps you accept:
UPI
Credit and debit cards
Net banking
Wallets
EMI
Pay Later
This blog is written for developers. It explains:
How Razorpay works behind the scenes
Important technical terms
How to set up your account
The correct payment flow
How to start integration safely
We will use simple English and real code examples.
Note: This is Part 1. Part 2 will include full frontend + backend code, webhook setup, testing, and production checklist.
What is Razorpay?
Razorpay is a payment gateway.
A payment gateway is a service that connects:
your customer
your business
the customer’s bank
payment networks (UPI, Visa, Mastercard, RuPay, etc.)
When a customer clicks Pay Now, Razorpay handles the secure payment process and tells your system whether the payment succeeded or failed.
Why developers use Razorpay
Easy checkout UI
Strong API support
Good documentation
Works with websites and mobile apps
Supports subscriptions, refunds, and webhooks
Trusted by many Indian startups and businesses
How Razorpay Works (Simple Flow)
Here is the full payment flow in plain language:
Customer clicks Pay on your website
Your backend creates a Razorpay Order
Your frontend opens Razorpay Checkout
Customer pays using UPI/card/net banking
Razorpay sends payment result
Your backend verifies the payment signature
You mark the order as paid
Razorpay later settles money to your bank account
Payment Flow Diagram
Important: Two Different Things
Many beginners confuse these:
| Term | Meaning |
|---|---|
| Payment Success | Customer paid successfully |
| Settlement | Money transferred to your bank account |
Payment can succeed today, but settlement may happen later based on Razorpay’s cycle.
Razorpay Account Setup (Developer View)
Step 1: Create account
Go to https://razorpay.com and sign up.
Step 2: Complete KYC
You may need:
PAN
Aadhaar
Business details
Bank account details
GST (if applicable)
Step 3: Get API keys
In Razorpay Dashboard:
Settings → API Keys
You will get:
Key ID (public, can be used in frontend)
Key Secret (private, backend only)
Example:
RAZORPAY_KEY_ID=rzp_test_xxxxxxxx
RAZORPAY_KEY_SECRET=your_secret_key_here
Test Mode vs Live Mode
| Mode | Use Case |
|---|---|
| Test Mode | Development and testing |
| Live Mode | Real customer payments |
Always build and test in Test Mode first.
Important Razorpay Concepts for Developers
Before writing code, understand these terms.
1. Order
An Order is created on your backend before payment.
Why?
Fixes the amount on server side
Prevents amount tampering
Helps track payments properly
Example order data:
{
"amount": 50000,
"currency": "INR",
"receipt": "receipt_101"
}
Note: Razorpay amount is in paise.
Rs 500 =50000paise
2. Payment ID
Every successful payment gets a unique ID like:
pay_Nxxxxxxxxxxxx
Store this in your database.
3. Signature Verification
After payment, Razorpay sends:
razorpay_order_idrazorpay_payment_idrazorpay_signature
Your backend must verify the signature.
Never trust only the frontend success message.
This protects you from fake payment success.
4. Webhook
A webhook is an automatic POST request from Razorpay to your server when an event happens.
Examples:
payment.capturedpayment.failedrefund.processed
Webhooks are important because:
Customer may close the browser after payment
Your server still gets the final status
More reliable than frontend-only flow
Recommended Integration Architecture
A safe Razorpay setup has 3 parts:
Frontend responsibilities
Show product and price
Call backend to create order
Open Razorpay Checkout
Send payment response to backend
Backend responsibilities
Create order
Verify signature
Save payment status
Handle webhooks
Mark order as paid
Never do this
❌ Put Key Secret in frontend
❌ Mark order paid without verification
❌ Trust browser success popup only
Tech Stack We Will Use (Part 2 Preview)
In Part 2, we will build a complete example using:
Node.js + Express (backend)
HTML/JavaScript (frontend)
Razorpay Checkout
Webhook verification
Project structure:
razorpay-demo/
├── .env
├── package.json
├── server.js
├── routes/
│ └── payment.js
├── public/
│ └── index.html
└── utils/
└── verifySignature.js
Step-by-Step Integration Overview
Here is the developer flow we will implement in Part 2.
Step 1: Install Razorpay SDK
npm install razorpay express dotenv cors
Step 2: Create order on backend
const Razorpay = require('razorpay');
const razorpay = new Razorpay({
key_id: process.env.RAZORPAY_KEY_ID,
key_secret: process.env.RAZORPAY_KEY_SECRET,
});
const order = await razorpay.orders.create({
amount: 50000, // Rs 500
currency: 'INR',
receipt: 'receipt_001',
});
Step 3: Open checkout on frontend
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
const options = {
key: 'rzp_test_xxxxxxxx',
amount: order.amount,
currency: order.currency,
name: 'My Store',
description: 'Test Payment',
order_id: order.id,
handler: function (response) {
// Send response to backend for verification
},
};
const rzp = new Razorpay(options);
rzp.open();
Step 4: Verify payment on backend
const crypto = require('crypto');
function verifyPayment(orderId, paymentId, signature) {
const body = orderId + '|' + paymentId;
const expectedSignature = crypto
.createHmac('sha256', process.env.RAZORPAY_KEY_SECRET)
.update(body)
.digest('hex');
return expectedSignature === signature;
}
Step 5: Update order in database
Only after verification:
if (verifyPayment(orderId, paymentId, signature)) {
// Mark order as PAID
} else {
// Reject fake or invalid payment
}
Database Design (Simple Example)
Store payment data properly.
orders table
| Column | Type | Example |
|---|---|---|
| id | int | 1 |
| amount | int | 50000 |
| currency | string | INR |
| razorpay_order_id | string | order_xxx |
| status | string | created / paid / failed |
| created_at | datetime | now |
payments table
| Column | Type | Example |
|---|---|---|
| id | int | 1 |
| order_id | int | 1 |
| razorpay_payment_id | string | pay_xxx |
| razorpay_signature | string | abc123... |
| status | string | success / failed |
| created_at | datetime | now |
This helps with:
support
refunds
accounting
debugging
Security Best Practices (Must Read)
1. Keep secret key on server only
✅ Backend: RAZORPAY_KEY_SECRET
❌ Frontend: never expose secret
2. Always verify signature
Frontend success ≠ real payment
Backend verification = real payment
3. Use HTTPS
Your website must use HTTPS in production.
4. Use webhooks
Frontend can fail. Webhooks are more reliable.
5. Prevent duplicate payments
Before marking paid, check:
if (order.status === 'paid') {
return res.json({ message: 'Already paid' });
}
6. Log everything
Store:
order ID
payment ID
webhook events
timestamps
Common Payment Statuses
| Status | Meaning | What to do |
|---|---|---|
created |
Order created, not paid yet | Wait for payment |
authorized |
Payment approved, may need capture | Check flow type |
captured |
Payment successful | Mark order paid |
failed |
Payment failed | Allow retry |
refunded |
Money returned | Update records |
Testing Razorpay (Before Going Live)
In test mode, Razorpay provides test cards and UPI flows.
Example test card (check latest docs)
Card Number: 4111 1111 1111 1111
Expiry: Any future date
CVV: Any 3 digits
OTP: Any
Always confirm test credentials from official Razorpay docs because they can change.
What to test
successful payment
failed payment
cancelled payment
webhook delivery
duplicate payment prevention
refund flow
Real Example: Online Course Purchase
Let’s say you sell a course for Rs 1,999.
Flow
Student clicks Buy Course
Backend creates order for
199900paiseRazorpay Checkout opens
Student pays with UPI
Razorpay returns payment details
Backend verifies signature
Course access is unlocked
Email receipt is sent
Settlement happens later in your bank
Common Developer Mistakes
Mistake 1: Amount in rupees instead of paise
// Wrong
amount: 500
// Correct (Rs 500)
amount: 50000
Mistake 2: Marking paid on frontend only
// Wrong
handler: function () {
alert('Payment successful');
}
// Correct
handler: function (response) {
fetch('/verify-payment', {
method: 'POST',
body: JSON.stringify(response),
});
}
Mistake 3: No webhook handler
If the user closes the tab, you may miss the final status.
Mistake 4: Exposing secret in GitHub
Use .env and add .env to .gitignore.
What’s Coming in Part 2
In the next part, you will get:
Full working Node.js backend code
Complete frontend checkout page
Payment verification API
Webhook setup with signature validation
Refund API example
Postman testing steps
Production deployment checklist
FAQ for common Razorpay errors
Conclusion
Razorpay makes it easy to accept online payments, but a secure integration requires more than just adding a checkout button. By understanding the payment flow, creating orders on the backend, verifying payment signatures, and using webhooks, you can build a reliable and secure payment system. In the next part, we'll put these concepts into practice by building a complete Razorpay integration with frontend and backend code, payment verification, webhook handling, and production-ready best practices.
Connect with :
Hashnode: hashnode.com/@Nehal71
Twitter : twitter.com/IngoleNehal
LinkedIn: linkedin.com/in/nehal-ingole
GitHub : github.com/Ingole712521
About the author
- 🚀 Greetings World! 🌐 Meet a dynamic Frontend Developer, UI/UX Designer, and avid explorer of Cloud & DevOps realms! Uncover the journey of a professional deeply passionate about crafting seamless user experiences, designing visually stunning interfaces, and navigating the cloud with a DevOps mindset. 🔧 Skills Snapshot: - Frontend Mastery: HTML, CSS, and JavaScript expert, specializing in React, Angular, and Vue.js. - Design Wizardry: Proficient in wireframing, prototyping, and Adobe Creative Suite and Figma for captivating designs. - Cloud Maestro: Fluent in AWS, Azure, and Google Cloud Platform, adept at architecting scalable solutions. - DevOps Guru: Skilled in Docker, Kubernetes, Jenkins, and Git, contributing to efficient development workflows. 🔗 Let's Connect: Open to collaborating on exciting projects and sharing industry insights, I invite connections for networking or discussions. Reach out for potential collaborations. 📧 Contact Me: -Portfolio:[https://www.nehalingole.in/] - GitHub: [GitHub Profile](https://github.com/Ingole712521) - Email: [nehalingole2001@gmail.com](mailto:nehalingole2001@gmail.com) - Mobile: 7397966719 - Figma: [Figma Profile](https://www.figma.com/@nehalingole) - Twitter: [Twitter Profile](https://twitter.com/IngoleNehal) - HashNode: [HashNode Profile](https://hashnode.com/@Nehal71) - LinkedIn : [LinkedIn Profile](https://www.linkedin.com/in/nehal-ingole/)
Comments
Join the discussionNo comments yet. Be the first to comment.




