How to paytm payment integration in website

How to paytm payment integration in website

paytm payment gateway integration in website

Here, Integrate Paytm payment in your website, first you have to create business account in paytm.

follow the below-mentioned steps to create your Paytm account

1.  Visit Paytm.com
2. Click on ‘Log In/Sign Up’ on the top-right corner of the page
3. Click on ‘Sign Up’
4. Enter your mobile number, email address and a password
5. Click on 'Create your Paytm Wallet'
6. Enter the OTP, your First Name, Last Name and click on 'Create your Paytm Wallet'
7. Your account will be created


enroll yourself as a merchant now and start accepting payments directly to your bank account.

Becoming a Paytm merchant comes with lot of advantages, you will have to worry less about tracking your business, let’s have a look why:

Power to transfer money to bank account anytime, anywhere
Real- Time Payment Tracking
Accepting payments directly from customer’s bank account
Various Offers applicable to your account
An option to promote your business to millions of Paytm user
Freedom to view/edit details from an App/Merchant Dashboard
Getting support from our informative Blog, FAQs and 24×7 Merchant Helpdesk

Business the Paytm Advantage
Instant account activation
Get paid instantly
Accept every payment

In-app and Online Payments:

1. Accept payments using India's most trusted payment platform - used by 350 million customers and merchants
2. Accept payments from India’s most popular Wallet by default
3. Go from sign up to production readiness with minimal documentation
4. Enable faster checkout by tapping into a vault of 150 million saved cards on Paytm
5. Track your business performance and growth with a powerful dashboard

The payment process starts at the click of pay button on merchant order summary page. On this click, you need to:

  1. Create an order in your order system and then generate checksumhash at your server end for payment request. Checksumhash is used for detecting errors or tampering introduced during its transmission of request. Checksum is generated using merchant Key which should be kept only on server side for security reasons
  2. Post the payload and checksumhash in an HTML form POST on Paytm's server. This redirects the customer to Paytm's payment 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 website's callback URL
  4. Verify checksumhash received in response to ensure that it has not been tampered
  5. Lastly, verify transaction status with Transaction Status API via server to server call. This protects you from scenarios where your account credentials are compromised or request/response has been tampered

Step 1 :

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

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.

Dictionary<String, String> paytmParams = new Dictionary<String, String>();
String merchantMid = "rxazcv89315285244163";
// Key in your staging and production MID available in your dashboard
String merchantKey = "gKpu7IKaLSbkchFS";
// Key in your staging and production merchant key available in your dashboard
String orderId = "order1";
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>";
paytmParams.Add("MID", merchantMid);
paytmParams.Add("CHANNEL_ID", channelId);
paytmParams.Add("WEBSITE", website);
paytmParams.Add("CALLBACK_URL", callbackUrl);
paytmParams.Add("CUST_ID", custId);
paytmParams.Add("MOBILE_NO", mobileNo);
paytmParams.Add("EMAIL", email);
paytmParams.Add("ORDER_ID", orderId);
paytmParams.Add("INDUSTRY_TYPE_ID", industryTypeId);
paytmParams.Add("TXN_AMOUNT", txnAmount);
// for staging string transactionURL = "https://securegw-stage.paytm.in/theia/processTransaction";
// for production // string transactionURL = "https://securegw.paytm.in/theia/processTransaction"; try {
string paytmChecksum = paytm.CheckSum.generateCheckSum(merchantKey, paytmParams);
string outputHTML = "<html>";
outputHTML += "<head>";
outputHTML += "<title>Merchant Checkout Page</titl>";
outputHTML += "</head>";
outputHTML += "<body>";
outputHTML += "<center><h1>Please do not refresh this page...</h1></cente>";
outputHTML += "<form method='post' action='" + transactionURL + "' name='f1>";
foreach (string key in paytmParams.Keys) {
outputHTML += "<input type='hidden' name='" + key + "' value='" + paytmParams[key] + "'>'";
}
outputHTML += "<input type='hidden' name='CHECKSUMHASH' value='" + paytmChecksum + ">";
outputHTML += "<script type='text/javascript>";
outputHTML += "document.f1.submit();";
outputHTML += "</script>";
outputHTML += "</form>";
outputHTML += "</body>";
outputHTML += "</html>";
Response.Write(outputHTML);
} catch (Exception ex) {
Response.Write("Exception message: " + ex.Message.ToString());

Html Form

<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" name="f1">
<table border="1">
<tbody>
<input type="hidden" name="MID" value="rxazcv89315285244163">
<input type="hidden" name="WEBSITE" value="WEBSTAGING">
<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="ZWdMJOr1yGiFh1nns2U8sDC9VzgUDHVnQpG
pVnHyrrPb6bthwro1Z8AREUKdUR/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.

<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='GATEWAYNAME' value='WALLET'>
<input type='hidden' name='RESPMSG' value='Txn Success'>
<input type='hidden' name='BANKNAME' value='WALLET'>
<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. 

String merchantKey = "gKpu7IKaLSbkchFS" ;
Dictionary<String, String> paytmParams = new Dictionary<String, String>();
string paytmChecksum = "";
foreach (string key in Request.Form.Keys) {
paytmParams.Add(key.Trim(), Request.Form[key].Trim());
}
if (paytmParams.ContainsKey("CHECKSUMHASH")) {
paytmChecksum = paytmParams["CHECKSUMHASH"];
paytmParams.Remove("CHECKSUMHASH");
}
bool isValidChecksum=CheckSum.verifyCheckSum(merchantKey, paytmParams, paytmChecksum);
if (isValidChecksum) {
Response.Write("Checksum Matched");
} else {
Response.Write("Checksum MisMatch");
}

Step 5 :

Validate transaction response via server side request using Transaction Status API. This API requires checksumhash in request and its verification in response. The status should be treated as the final status of the transaction

Post completion of integration on your staging environment, do a complete transaction from order summary page on your website or mobile app

  1. Attempt a test transaction using test paymodes credentials
  2. Ensure you re-verify transaction response with Transaction Status API via server to server call in payment flow and not separately as a one time activity
  3. See the transaction details in “Test Data” mode on your dashboard

Once the test transaction is complete, move your code to live environment with production account details. Note that production accounts details are available after you have activated your account on the dashboard

 

Write Your Reviews