Add money to your customer’s Paytm Wallet with Paytm Payment Gateway

Overview of Add Money


If a customer does not have enough balance for an order/ transaction on your website/app, you can trigger an add money request to Paytm so that you can complete the payment for your order. Customer can select a pre-set amount or enter a custom amount to add. After customer submits the request, you need to do the following:

  1. Create an order in your order system and generate checksumhash at your server end for payment request. Checksumhash is used for detecting errors or tampering introduced during transmission of request. Checksum is generated using Merchant Key which should be kept only on server side for security reasons. You have to send an additional parameter in the add money request:

    REQUEST_TYPE: ADD_MONEY
    
  2. POST the payload and checksumhash in an HTML. This redirects the customer to Paytm's add money checkout page

  3. Customer fills payment details and completes the payment authentication. Once the payment is complete, response is posted in HTML form POST on your app/website's callback URL

  4. Verify checksumhash received in response to ensure that it has not been tampered with

  5. Customer will now have the money added to her Paytm Wallet and you can continue with checkout

Steps in Add Money via Paytm Payment Gateway


Step 1 :

At the click of Add money button by customer on your website, create an order in your system and generate the required payload for payment request. Parameters of payload are provided below

Request Attributes


PARAMETERDESCRIPTION
REQUEST_TYPE Alpha(50)Transaction Type: ADD_MONEY
MID String(20) MandatoryThis is the “Merchant Identifier” that is issued by Paytm to the Merchant. This is unique for each merchant that integrates with Paytm
ORDER_ID String(50) MandatoryThe “Order ID” is the Merchant’s Transaction ID which should be unique for every transaction. Duplicate order id will be rejected by the Paytm gateway
CUST_ID String(64) MandatoryThe “Customer ID” is the customer identifier. This could be a unique user Id that the Merchant has assigned to its customers. This parameter is required for correlating the user to a transaction. Multiple transactions can have the same Application User Name if the same customer is performing multiple transactions. The Application User Name is used by Paytm’s fraud prevention engine for detecting fraudulent transactions/users. Special characters e.g @, ! ,_ $ are allowed
TXN_AMOUNT String(10) MandatoryThis is the “Transaction Amount” that is to be charged the customer’s credit card /debit card /bank account / Paytm Wallet. Should contain digits up to two decimal points. Only special character allowed is (“.”) . Please ensure that the amount is in the same currency as defined for the Merchant ID being used.
CHANNEL_ID String(3) MandatoryChannel ID need to pass in this parameter. Ex:
1. WEB – for desktop websites
2. WAP – for mobile websites
INDUSTRY_TYPE_ID String(20) MandatoryIndustry type should pass here. This will be provided by Paytm. Ex: “Retail1”
WEBSITE String(30) MandatoryWEBSITE Name should passed here. This will be provided by Paytm
CHECKSUMHASH String(108)Checksum calculated based on pre-defined logic. Checksum is used to ensure data is not tempered when request is posted on the Paytm URLS. In case of checksum mismatch due to data tempering Paytm will reject the transaction.
SSO_TOKEN String(36)SSO_TOKEN of user

Step 2 :


Generate checksumhash using Paytm library with parameters in key value pairs. Using the payload and checksumhash make an HTML form post and redirect customer to Paytm server. Code snippets and Github links for the checksum utility and HTML form post are provided below.

String merchantMid = "rxazcv89315285244163";
// Key in your staging and production MID available in your dashboard
String merchantKey = "xxxxxxxxxxxxxxxx";
// Key in your staging and production merchant key available in your dashboard
String orderId = "order1";
String sso_token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
String channelId = "WEB";
String custId = "cust123";
String mobileNo = "7777777777";
String email = "username@emailprovider.com";
String txnAmount = "100.12";
String website = "WEBSTAGING";
// This is the staging value. Production value is available in your dashboard
String industryTypeId = "Retail";
// This is the staging value. Production value is available in your dashboard
String callbackUrl = "https://<Merchant_Response_URL>";
TreeMap<String, String> paytmParams = new TreeMap<String, String>();
paytmParams.put("MID",merchantMid);
paytmParams.put("REQUEST_TYPE", "ADD_MONEY");
paytmParams.put("SSO_TOKEN", sso_token);
paytmParams.put("ORDER_ID",orderId);
paytmParams.put("CHANNEL_ID",channelId);
paytmParams.put("CUST_ID",custId);
paytmParams.put("MOBILE_NO",mobileNo);
paytmParams.put("EMAIL",email);
paytmParams.put("TXN_AMOUNT",txnAmount);
paytmParams.put("WEBSITE",website);
paytmParams.put("INDUSTRY_TYPE_ID",industryTypeId);
paytmParams.put("CALLBACK_URL", callbackUrl);
String paytmChecksum = CheckSumServiceHelper.getCheckSumServiceHelper().genrateCheckSum(merchantKey, paytmParams);
StringBuilder outputHtml = new StringBuilder();
outputHtml.append("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
outputHtml.append("<html>");
outputHtml.append("<head>");
outputHtml.append("<title>Merchant Checkout Page</title>");
outputHtml.append("</head>");
outputHtml.append("<body>");
outputHtml.append("<center><h1>Please do not refresh this page...</h1></center>");
$transactionURL="https://securegw-stage.paytm.in/theia/processTransaction";  	// for staging
// $transactionURL="https://securegw.paytm.in/theia/processTransaction";  // for production
outputHtml.append("<form method='post' action='"+transactionURL+"' name='f1'>");
for(Map.Entry<String,String> entry : paytmParams.entrySet()) {
    outputHtml.append("<input type='hidden' name='"+entry.getKey()+"' value='"+entry.getValue()+"'>");
}
outputHtml.append("<input type='hidden' name='CHECKSUMHASH' value='"+paytmChecksum+"'>");
outputHtml.append("</form>");
outputHtml.append("<script type='text/javascript'>");
outputHtml.append("document.f1.submit();");
outputHtml.append("</script>");
outputHtml.append("</body>");
outputHtml.append("</html>");
Endpoints:
Staging: https://securegw-stage.paytm.in/theia/processTransaction
Production: https://securegw.paytm.in/theia/processTransaction

HTML Form Post

<html>
    <head>
        <title>Merchant Check Out Page</title>
    </head>
    <body>
        <center><h1>Please do not refresh this page...</h1></center>
        <form method="post" action="https://securegw-stage.paytm.in/theia/processTransaction?ORDER_ID=order1" name="f1">
            <table border="1">
                <tbody>
                    <input type="hidden" name="MID" value="xxxxxxxxxxxxxxxxxxxx">
                    <input type="hidden" name="WEBSITE" value="WEBSTAGING">
                    <input type="hidden" name="REQUEST_TYPE" value="ADD_MONEY">
                    <input type="hidden" name="SSO_TOKEN" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">
                    <input type="hidden" name="ORDER_ID" value="order1">
                    <input type="hidden" name="CUST_ID" value="cust123">
                    <input type="hidden" name="MOBILE_NO" value="7777777777">
                    <input type="hidden" name="EMAIL" value="username@emailprovider.com">
                    <input type="hidden" name="INDUSTRY_TYPE_ID" value="Retail">
                    <input type="hidden" name="CHANNEL_ID" value="WEB">
                    <input type="hidden" name="TXN_AMOUNT" value="100.12">
                    <input type="hidden" name="CALLBACK_URL" value="https://Merchant_Response_URL>">
                    <input type="hidden" name="CHECKSUMHASH" value="ZWdMJOr1yGiFh1nns2U8sDC9VzgUDHVnQpGpVnHyrrPb6bthwro1Z8AREUKdUR/K46x3XvFs6Xv7EnoSOLZT29qbZJKXXvyEuEWQIJGkw=">
                </tbody>
            </table>
        <script type="text/javascript">
            document.f1.submit();
        </script>
        </form>
    </body>
</html>

Step 3 :


Customer fills the payment details and is redirected to bank page for authorization. Once the transaction is authorized, Paytm receives the response from the bank and returns a status to your website via your callback URL. Response attributes description and sample HTML form post is provided below :

Response Sent by Paytm


ParameterDescription
MID String(20)This is a unique merchant Id provided to merchant by Paytm at the time of merchant creation
TXNID String (length: upto 64 digits, datatype: long)This is a unique Paytm transaction Id that is issued by Paytm for each valid transaction request received from the merchant.
ORDERID String(50)This is the application transaction Id that was sent by merchant to Paytm at the time of transaction request.
BANKTXNID StringThe transaction Id sent by the bank/wallet (NULL or empty string if the transaction doesn't reaches to the bank).
TXNAMOUNT String(10)The amount of the transaction.
CURRENCY String(3)Currency used for transaction.
INR
USD
STATUS String(20)This contains the transaction status and has only three values:
TXN_SUCCESS
TXN_FAILURE
TXN_PENDING
RESPCODE String(10)Codes refer to a particular reason of payment failure/success. List in this PDF
RESPMSG String(500)Description message is linked with each respcode. List in this PDF
TXNDATE DateTimeDate of transaction.
GATEWAYNAME String(15)Gateway used by Paytm (ICICI/CITI/WALLET etc)
BANKNAME String(500)Bank name of the card issuing bank.
PAYMENTMODE String(15)The payment mode used for transaction.
CHECKSUMHASH String(108)Checksum calculated based on pre-defined logic
<html>
   <head>
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     <title>Paytm Secure Online Payment Gateway</title>
   </head>
   <body>
      <table align='center'>
            <tr>
            <td><STRONG>Transaction is being processed,</STRONG></td>
            </tr>
            <tr>
            <td><font color='blue'>Please wait ...</font></td>
            </tr>
            <tr>
            <td>(Please do not press 'Refresh' or 'Back' button</td>
            </tr>
      </table>
      <FORM NAME='TESTFORM' ACTION='https://<Merchant_Response_URL>' METHOD='POST'>
            <input type='hidden' name='CURRENCY' value='INR'>
            <input type='hidden' name='CUST_ID' value='cust123'>
            <input type='hidden' name='GATEWAYNAME' value='XYZ'>
            <input type='hidden' name='RESPMSG' value='Txn Success'>
            <input type='hidden' name='BANKNAME' value='XYZ'>
            <input type='hidden' name='PAYMENTMODE' value='PPI'>
            <input type='hidden' name='MID' value='rxazcv89315285244163'>
            <input type='hidden' name='RESPCODE' value='01'>
            <input type='hidden' name='TXNID' value='20180821111212800110168085600021958'>
            <input type='hidden' name='TXNAMOUNT' value='100.12'>
            <input type='hidden' name='ORDERID' value='order1'>
            <input type='hidden' name='STATUS' value='TXN_SUCCESS'>
            <input type='hidden' name='BANKTXNID' value='5357590'>
            <input type='hidden' name='TXNDATE' value='2018-08-21 15:16:11.0'>
            <input type='hidden' name='CHECKSUMHASH'   value='YjtlLUVs6gQhR8RuUltwOsGnGXBg7gpdMRAKYU/ qiTZCeJZmwbciUFmwtT6RmwBmpwVswSiknJK7iEBch27q627uzTXKxJ0vzoMs68AE9A='>
      </FORM>
   </body>
 <script type="text/javascript">  document.forms[0].submit();</script>    
</html> 

Step 4 :


Checksumhash received in response of transaction needs to be verified on merchant server using Paytm library with all the parameters in key value pairs. Code snippets and Github links for the checksum utility are provided below

Step 5 :


Customer will be able to see the added amount in his/her Wallet.