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.

How to Fix "We're Sorry, A Server Error Occurred While Reading From Storage. Error Code Not_Found" Error in Google Apps Script

 Google Apps Script is a powerful scripting language that enables users to automate various tasks within the Google Suite of applications, including Google Sheets, Docs, and Forms. However, like any other programming language, it's not uncommon to encounter errors when working with Google Apps Script.


One common error that you may encounter is the "We're sorry, a server error occurred while reading from storage. Error code: not_found." This error message can be frustrating, as it doesn't provide much information on which library is causing the issue.


In this blog post, we'll discuss what causes this error and provide a step-by-step guide on how to fix it.


Understanding the "We're Sorry, A Server Error Occurred While Reading From Storage. Error Code Not_Found" Error:


The "We're sorry, a server error occurred while reading from storage. Error code: not_found" error message typically appears when a Google Apps Script is trying to access a library that has been deleted or no longer exists. It can also occur when a script is trying to use a library version that is no longer available.


To determine which library is causing the issue, follow the steps below:


Open the script editor for the script that's producing the error.

Click on the "Resources" menu and select "Libraries.

A list of libraries being used in the script will appear. The library causing the error will be marked with an error icon.

Once you've identified the problematic library, you can follow the steps below to fix the issue.


How to Fix the "We're Sorry, A Server Error Occurred While Reading From Storage. Error Code Not_Found" Error:


To fix the "We're sorry, a server error occurred while reading from storage. Error code: not_found" error in Google Apps Script, you'll need to change the library version from the header to the deployed version and then redeploy the library.


Follow the steps below to resolve the error:

Step -1: Go to the project and check libraries.

Step-2: Go to that library from the account in which have access.


Step-3: Check libraries in that project.


Step-4: Check the version and change it from header to deployed project.


Step-5: Deploy new version as library.


Step-6: Select latest version of library in main project in which getting error.


Step-7: Run code error should be solved.




Test the script to ensure the error is resolved.

Conclusion:


Encountering errors when working with Google Apps Script can be frustrating, but with the right solutions, these errors can be easily resolved. The "We're sorry, a server error occurred while reading from storage. Error code: not_found" error is a common error that can occur when a script is trying to access a deleted or non-existent library or an outdated library version. By following the steps outlined in this blog post, you can easily fix this error and continue working on your Google Apps Script project.

Google Apps Script Library Security

Google Apps Script Library Security

Google Apps Script Library Security: The Importance of Using Script Properties in Functions

Google Apps Script is a powerful platform that allows users to automate tasks and add functionality to Google Apps. However, with the power of scripting comes the responsibility to secure the code and data that it interacts with. This is especially important when using libraries, which are collections of pre-written code that can be easily imported and used in your own scripts.




One of the key ways to maintain the security of your code and data when using Google Apps Script libraries is to use script properties. Script properties are key-value pairs that are stored with your script and can be used to store sensitive information, such as API keys or secrets.

When using script properties in your code, it's important to use them correctly in order to maintain the security of your data. If you use a script property in the top-level scope of your code, it can be easily accessed by others who view your code. This means that any sensitive information stored in the script property is at risk of being compromised.

To avoid this, it's best to use script properties within functions. This way, the code is not directly accessible in the top-level scope and is instead only accessible through the function.

One way to use script properties within a function is to use the following code:

function code() { eval(PropertiesService.getScriptProperties().getProperty('code')) }



In this code, the function code uses the eval function to execute the code stored in the script property named "code". By using the eval function, the code stored in the script property is executed within the context of the function, making it more secure.

Another way to use script properties within a function is to use the following code:

function code() { eval(PropertiesService.getScriptProperties().getProperty('code')); return val; }

In this code, the function code uses the eval function to execute the code stored in the script property named "code". The code stored in the script property should define a variable named val, which will then be returned by the function.

To use this code, you would first set the script property "code" to contain the following code:


var val = "key";

or some other function that returns a value. This way, when the function code is called, it will execute the code stored in the script property and return the value stored in the val variable.

By using script properties within functions, you can ensure that sensitive information stored in your code is more secure and less accessible to others who may view your code. So if you're using Google Apps Script libraries, make sure to use script properties in your functions to maintain the security of your data.