Payment Integration (Razorpay / Stripe)
Payment Integration (Razorpay & Stripe)
এই টিউটোরিয়ালে আমরা Express.js ব্যবহার করে কীভাবে Razorpay এবং Stripe payment gateway integrate করতে হয় তা step-by-step শিখবো।
💳 Payment Gateway কেন প্রয়োজন?
- Online payment collect করার জন্য
- Subscription / Course selling
- Secure & trusted transaction
- Auto invoice ও payment tracking
🔷 Razorpay
- 🇮🇳 India-focused payment gateway
- UPI, Card, NetBanking support
- Easy onboarding
🔷 Stripe
- 🌍 International payment gateway
- Card, Wallet, Subscription
- Highly secure & scalable
🧩 Razorpay Integration (Express.js)
📦 Install Packages
npm install razorpay crypto
⚙️ Backend Code (Express.js)
const Razorpay = require("razorpay");
const crypto = require("crypto");
const razorpay = new Razorpay({
key_id: process.env.RAZORPAY_KEY_ID,
key_secret: process.env.RAZORPAY_KEY_SECRET,
});
app.post("/create-order", async (req, res) => {
const options = {
amount: 50000, // 500 INR
currency: "INR",
receipt: "order_rcptid_11",
};
const order = await razorpay.orders.create(options);
res.json(order);
});
app.post("/verify-payment", (req, res) => {
const { razorpay_order_id, razorpay_payment_id, razorpay_signature } = req.body;
const sign = razorpay_order_id + "|" + razorpay_payment_id;
const expectedSign = crypto
.createHmac("sha256", process.env.RAZORPAY_KEY_SECRET)
.update(sign)
.digest("hex");
if (expectedSign === razorpay_signature) {
res.json({ success: true });
} else {
res.json({ success: false });
}
});
🧩 Stripe Integration (Express.js)
📦 Install Package
npm install stripe
⚙️ Backend Code (Express.js)
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
app.post("/create-payment-intent", async (req, res) => {
const paymentIntent = await stripe.paymentIntents.create({
amount: 50000, // 500 INR
currency: "inr",
automatic_payment_methods: {
enabled: true,
},
});
res.send({
clientSecret: paymentIntent.client_secret,
});
});
🔐 Security Best Practices
- API keys কখনো frontend-এ রাখবেন না
- Environment variable (.env) ব্যবহার করুন
- Payment verification অবশ্যই backend-এ করুন
- HTTPS বাধ্যতামূলক
🎯 Real-Life Use Case
👉 Online Course Purchase 👉 Premium Subscription 👉 Donation System 👉 SaaS Product Billing
👼 Quiz
/