How to Integrate Paytm in Aps.Net

By | February 16, 2017

Here we will learn, how to integrate Paytm payment gateway in website.
First we need to signup in Paytm through this link   and  then upload the required document and compliance through this link. Now come to the installation and configuration steps as below.

Installation and Configuration Steps for .net

These installation steps are for all versions of .net

  1. Add provided “paytm.dll” as a “Reference” in your project.
  2. Import namespace “paytm” in your project/solution with statement “using paytm”.
  3. The Generate CheckSum and Verify CheckSum methods are given below. Their respective usage is given in the next few points.
    string return method CheckSum.generateCheckSum(String merchantKey, Dictionary<String, String> parameters)
    Boolean return method CheckSum.verifyCheckSum(String merchantKey, Dictionary<String, String> parameters, String checkSum)
  4. For Generating CheckSum, use the following code snippet.  Note: Replace all the values with the respective values provided by Paytm at the time of registration.
    String merchantKey = “merchantKey value” ;
    Dictionary<string, string> parameters = new Dictionary<string, string>();
    parameters.Add("MID", "mid value");
    parameters.Add("CHANNEL_ID", "channel id value");
    parameters.Add("INDUSTRY_TYPE_ID","industry value");
    parameters.Add("WEBSITE", "website value");
    parameters.Add("EMAIL", "email value");
    parameters.Add("MOBILE_NO", "mobile value");
    parameters.Add("CUST_ID", "cust id");
    parameters.Add("ORDER_ID", "order id");
    parameters.Add("CALLBACK_URL","url"); //This parameter is not mandatory. Use this to pass the callback url dynamically.
    string checksum = CheckSum.generateCheckSum(merchantKey, parameters);
  5. Define the Staging server Url here. Replace this with the Production server Url once you move to the production setup.
    string paytmURL = "" + orderid;
  6. Use the following code snippet to make a form post. This will redirect the request to Paytm Payment Gateway.
    string outputHTML = "<html>";
    outputHTML += "<head>";
    outputHTML += "<title>Merchant Check Out Page</title>";
    outputHTML += "</head>";
    outputHTML += "<body>";
    outputHTML += "<center><h1>Please do not refresh this page...</h1></center>";
    outputHTML += "<form method='post' action='" + paytmURL + "' name='f1'>";
    outputHTML += "<table border='1'>";
    outputHTML += "<tbody>";
    foreach (string key in parameters.Keys)
       outputHTML += "<input type='hidden' name='" + key + "' value='" + parameters[key] + "'>";
    outputHTML += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "'>";
    outputHTML += "</tbody>";
    outputHTML += "</table>";
    outputHTML += "<script type='text/javascript'>";
    outputHTML += "document.f1.submit();";
    outputHTML += "</script>";
    outputHTML += "</form>";
    outputHTML += "</body>";
    outputHTML += "</html>";
  7. Use the following code snippet to Get the response and verify the checksumhash.
    String merchantKey = “merchantKey value” ; // Replace the with the Merchant Key provided by Paytm at the time of registration.
    Dictionary<string, string> parameters = new Dictionary<string, string>();
    string paytmChecksum = "";
    foreach (string key in Request.Form.Keys)
       parameters.Add(key.Trim(), Request.Form[key].Trim());
    if (parameters.ContainsKey("CHECKSUMHASH"))
       paytmChecksum = parameters["CHECKSUMHASH"];
    if (CheckSum.verifyCheckSum(merchantKey, parameters, paytmChecksum))
       Response.Write("Checksum Matched");
       Response.Write("Checksum MisMatch");

Download the Source Code


I hope you will enjoy how to integrate Paytm in Aps.Net. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Like it? Share it
  • Brijesh Tiwari

    This site is awesome. Thanks for continuously posting sir

  • karthikeyan v

    why you are using paytmurl at the last orderid, and its refer for what?