Hey @Pratik_Shah
RazorPay has introduced a new version for Payment Links API. I was figuring out last week how we can integrate in such a way that it interacts with us faster and smoother process.
In this method, we’ll be sending Payment Links (UPI & Standard) to customers.
When a button clicks, we’ll fire an API that is located at Apps Script. Then, the Customer will receive a text message or email message of the payment procedure.
Types of Payment Links:
First of all, we need to check, we have a legacy API Contract configured or a new one.
For that, you need to refer to this Payment Links
For mine, it’s a new API contract
UPI: It’s working on Android Only as of now. When the customer clicks the payment link, all UPI apps installed on the phone will appear.
Standard: For all type of payment methods.
Fire an API
Step: 1
Create API key from RazorPay Dashboard
Step: 2 We're going to create UPI enabled payment link. Copy this code
function doGet(e) {
//Displays the text on the webpage.
return ContentService.createTextOutput("This is a GET Request!");
}
function doPost(e) {
var body = JSON.parse(e.postData.contents);
var name = body["params"]["Name"]["value"];
var email = body["params"]["Email"]["value"];
var number = body["params"]["Number"]["value"];
var Desc = body["params"]["Description"]["value"];
var Fees = body["params"]["Fees"]["value"];
var Rfrnc = body["params"]["Reference"]["value"];
var headers = {
“Authorization”: Basic ${Utilities.base64Encode("API KEY:VALUE")}
};
var customer = {
“name”: name,
“email”: email,
“contact”: number
};
var payload = {
“amount”: Fees,
“currency”: “INR”,
“description”: Desc,
“customer”: customer,
“notify”: {
“sms”: true,
“email”: true
},
“upi_link”: “true”,
“callback_url”: “https://example-callback-url.com/”,
“callback_method”: “get”
}
var options = {
“method” : “post”,
“payload” : JSON.stringify(payload),
‘headers’: headers,
‘contentType’: ‘application/json’,
};
var url = “https://api.razorpay.com/v1/payment_links”;
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
Step 3: Click deploy button on right top corner of the apps script. Click on setting button then deploy it as a web app. Then select access as anyone. After final clicking on deploy button, you’ll have a URL. Copy that URL.
Step: 4 Make a Webhook Action Button on Glide App.
Paste URL to API Input Value.
Add the Following Values and Link them with your tables.
Name
Email
Number
Description
Fees
Reference
Note: You can add more parameter. Here is API Reference, Payment Links Copy Parameters from Request body. Add them to Payload and also fetch it from postdata.
Note: If you want to make a link for 245 Rs then the value of your fees will be 24500. You’ve to add paise as two figure value. Don’t add (.)
Note: Reference ID Should be Unique. You can even assign Row ID.
Getting Back to the Sheets
Whenever user pays successfully, razorpay's webhook will send us data.
Step: 1
Create a new Apps Script Project. Don't add to the existing File. Because Already one web app deployed over there.
Step: 2
Copy this code, enter the fields you need to print in sheet. Enter extra parameters from this sample payload,
https://razorpay.com/docs/webhooks/payloads/#payment-link-paid
Code:
function doGet(e) {
//Displays the text on the webpage.
return ContentService.createTextOutput(“This is a GET Request!”);
}
function doPost(e) {
var body = JSON.parse(e.postData.contents);
var amount = body["payload"]["payment_link"]["entity"]["amount"];
var description = body["payload"]["payment_link"]["entity"]["description"];
var email = body["payload"]["payment_link"]["entity"]["customer"]["email"];
var contact = body["payload"]["order"]["entity"]["customer"]["contact"];
var created_at = body["payload"]["payment_link"]["entity"]["created_at"];
// Add Extra Fields you need
//Converting Created Date (Unix) to GMT Formatted
var formattedDate = Utilities.formatDate(created_at, "GMT+5:30", "MM-dd-yyyy HH:mm:ss");
var sheet = SpreadsheetApp.getActive().getSheetByName("Webhook");
sheet.appendRow([amount,description,email,contact,formattedDate]);
}
Step: 3
Deploy it as a web app and copy url.
Step: 4
Go to RazorPay Dashboard → Settings → Webhook → Add New Webhook → Paste COPIED URL → Scroll to the last → Activate “payment_link.paid” Action
Now it’ll automatically send data to the sheets.
Let me know If any error occurs. This also can be integrate with Integromat and it’s also so much easy. But this saves a lot of bucks. There are many methods/ API you can integrate with razorpay and glide. It depends upon your usecase.
@Manan_Mehta Hey Dude, Check this. I’ve made it through Webhook Actions.
@Amal Hey, Sorry for the late. This tutorial will surely help you to understand how this works.