Paytm Payment Gateway using Google Apps Script

Paytm is India's leading payment gateway and a popular choice for businesses and individuals to receive payments online. With its secure and easy-to-use platform, Paytm offers a range of payment options such as debit/credit card, UPI, and more. Integrating Paytm payment gateway into your Google Apps Script can help you receive payments easily and securely.

In this blog, we will show you how to integrate Paytm payment gateway into your Google Apps Script application. We will be using the Paytm Payment Gateway Library, which is a Google Apps Script library that makes it easy to integrate Paytm into your Google Apps Script application. The library provides a range of functions to handle payment requests, verify payment responses, and more.




Step 1: Purchase the Paytm Payment Gateway Library(30 days free trial Payment details not required.)Plan starting at 5 rs only.

The first step is to purchase the Paytm Payment Gateway Library. You can purchase the library by visiting the following link: https://sites.google.com/view/paytm-payment-library/home (Affiliate Link). Upon purchase, you will receive the library file, which you need to add to your Google Apps Script project.

Step 2: Add the Library to Your Google Apps Script Project

To add the library to your Google Apps Script project, follow these steps:

Open your Google Apps Script project.

In the Google Apps Script Editor, click on the "Resources" menu and select "Libraries."

In the "Add a Library" dialog, enter the library ID (you can find the library ID in the library file you received upon purchase) and select the latest version.

Click the "Add" button to add the library to your project.

Step 3 : Write code 

 var mid = "YOUR_MID";
var paytmMerchantKey = 'YOUR MERCHANT KEY';
var testing = true;// IF USING TESTING MID,METCHANT KEY THEN TRUE ELSE FALSE

var callbackurl =  ScriptApp.getService().getUrl();// CAN USE CUSTOM URL FOR SAME URL USE THIS
var WEBSITE = 'DEFAULT';
if(testing)
   WEBSITE = 'WEBSTAGING';

function check(){
 
  var params = {
    'MID':mid,
    'ORDER_ID':'ORDERID'
  }
  var cksm = Paytm.getChecksum(params,paytmMerchantKey).toString();
  params.CHECKSUMHASH = cksm;
  
  var statusurl = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
  if(testing)
    var statusurl ='https://securegw-stage.paytm.in/merchant-status/getTxnStatus';

var options ={
  'method':'post',
  'payload':JSON.stringify(params)
}
var response =UrlFetchApp.fetch(statusurl,options).getContentText();
console.log(response);
//response contains status of payment

}




function doGet(e){

var params =  {
      'MID': mid,
    'ORDER_ID': 'oid_2_'+ Math.ceil(Math.random()*9999999),
    'CUST_ID': 'cid120',
    'TXN_AMOUNT':1,//AMOUNT 
    'CHANNEL_ID': 'WEB',
    'INDUSTRY_TYPE_ID': 'Retail',
    'WEBSITE': WEBSITE,
    'CALLBACK_URL':callbackurl,
  };

var html = Paytm.getPaymentHtml(params,paytmMerchantKey,testing);
return html;//returns html page for making payment
}

function doPost(e) {

//var params = {"BANKTXNID":"","STATUS":"TXN_FAILURE","RESPMSG":"Your payment has been declined by your bank. Please contact your bank for any queries. If money has been deducted from your account, your bank will inform us within 48 hrs and we will refund the same","CHECKSUMHASH":"CHECKSUM","ORDERID":"ORDERID","TXNAMOUNT":"1.00","MID":"YOUR MID","RESPCODE":"501","CURRENCY":"INR"};

var params = e.parameter;//response from the paytm payment gateway

var check = false;

if(params.CHECKSUMHASH){
  console.log(params.CHECKSUMHASH);
 var check = Paytm.verifychecksum(params,paytmMerchantKey,params.CHECKSUMHASH);
 if(check && params.STATUS == 'TXN_SUCCESS')
{delete params.MID;
    var rs = JSON.stringify(params);
 
}
else{
 delete params.MID;
 
  var rs = JSON.stringify(params);
   if(!check)
    var rs = 'Checksum Missmatched';
}
}else{
  var rs = 'No checksum found';
}

console.log(rs);

return ContentService.createTextOutput().append(rs).setMimeType(ContentService.MimeType.TEXT);//RETURNS RESPONSE CAN BE CUSTOMIZE 

}


Step 4: Update the Configuration

Next, you need to update the configuration of your Google Apps Script project. You need to update the following:

MID: Your Paytm Merchant ID

Paytm Merchant Key: Your Paytm Merchant Key

Testing: Set to true if you are using a testing MID and merchant key, and set to false if you are using a production MID and merchant key.

Step 5: Customize the Design and Functions

The Paytm Payment Gateway Library provides a range of functions to handle payment requests, verify payment responses, and more. You can customize the design and functions of your payment gateway according to your requirements.

Step 6: Deploy and Test Your Payment Gateway

Finally, you need to deploy your payment gateway to the web and test it to ensure that it is working as expected. You can deploy your payment gateway by following these steps:

In the Google Apps Script Editor, click on the "Publish" menu and select "Deploy as web app."

Select the appropriate settings for your web app and click the "Deploy" button.

Copy the URL of your web app and test it to ensure that it is working as expected.

In conclusion, integrating Paytm payment gateway into your Google Apps Script application is easy and straightforward. With the Paytm Payment Gateway Library, you can receive payments easily and securely. If you have any questions or need assistance, please reach out to the library's support team.

No comments:

Post a Comment