Integrate Razorpay Subscription in react.js and node.js

npm install razorpay
var Razorpay = require(‘razorpay’);
let instance = new Razorpay(
{
key_id: hotel.key_id,
key_secret: hotel.key_secret
}
);
  1. Create Plan
const params ={   
"period": "monthly",
"interval": 6,
"item": {
"name": "Test plan - Weekly",
"amount": 69900,
"currency": "INR",
"description": "Description for the test plan"
},
"notes": {
"notes_key_1": "Tea, Earl Grey, Hot",
"notes_key_2": "Tea, Earl Grey… decaf."
}
}'
instance.plans.create(params)
const params = { 
“plan_id”:”plan_00000000000001",
“total_count”:6, “quantity”: 1,
“customer_notify”:1,
“start_at”:1580453311,
“expire_by”:1580626111,
“addons”:[
{
“item”:{
“name”:”Delivery charges”,
“amount”:30000,
“currency”:”INR”
}
}
],
“offer_id”:”offer_JHD834hjbxzhd38d”,
“notes”:{
“notes_key_1”:”Tea, Earl Grey, Hot”,
“notes_key_2”:”Tea, Earl Grey… decaf.”
}
}’
const response = instance.subscriptions.create(params)
<script src = “https://checkout.razorpay.com/v1/checkout.js"></script>
function handleSubscription(){   var options = { 
“key”: “key_id”,
“subscription_id”: “sub_00000000000001”,
“name”: “Acme Corp.”,
“description”: “Monthly Test Plan”,
“image”: “/your_logo.png”,
“handler”: function(response) {
alert(response.razorpay_payment_id) alert(response.razorpay_subscription_id) alert(response.razorpay_signature)
},
“prefill”: {
“name”: “Gaurav Kumar”,
“email”: “gaurav.kumar@example.com”,
“contact”: “+919876543210”
},
“notes”: {
“note_key_1”: “Tea. Earl Grey. Hot”,
“note_key_2”: “Make it so.”
},
“theme”: {
“color”: “#F37254”
}
};
var paymentObject = new Razorpay(options);
paymentObject.open()
}
{
“razorpay_payment_id”: “pay_00000000000001”,
“razorpay_subscription_id”: “sub_00000000000001”,
“razorpay_signature”: “c04ff297db507f08ab701ea9aa36a1dc90679c2a8c80cb2ea7995e119f3f0c5e”
}
const crypto = require('crypto')app.post("/verification/", async (req, res) => {   const crypt = crypto.createHmac('sha256', razorpay.key_secret)
crypt.update(req.body.razorpay_payment_id+'|'+req.params.sid)
const digest = digest('hex');
if(digest === req.body.razorpay_signature){
console.log('request is legit')
}else{
console.log('request is not legit')
}
})

--

--

--

MERN Stack Developer, Co-founder of TalkingBeat, Head Developer at MentoMeet, Freelancer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

OOP: From Pseudo-classical class instantiation to Class instantiation

Using The Underscore.js Library

Introducing Flicking v4 with more customization and UI preserving

First steps with Caluma

JavaScript -: The Data Types are weird

Add Newsletter Subscription Form to React Website

All things about NodeJs

Build a E-Commerce site using MERN Stack! STEP 4A: Postman Testing - GET.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Gupta

Abhishek Gupta

MERN Stack Developer, Co-founder of TalkingBeat, Head Developer at MentoMeet, Freelancer

More from Medium

How to write and run your first Node.js Program

“Hello Side Project” — Tips to building a meaningful side project

Fetching from an API

Importance of Nodejs