Search code examples
node.jsnativescriptpaytm

How to generate checksum on click of a button


I'm trying to generate checksum for paytm integration in my app.

So, i downloaded https://github.com/Paytm-Payments/Paytm_App_Checksum_Kit_NodeJs the github repository.

Then on my server side, I created a folder name "paytm_mobile" in which the uploaded structure looks like below.

two muppets Then I updated the file "paytm_config" inside "paytm" folder with my details

module.exports = {
  paytm_config: {
    MID: 'V******************3',
    WEBSITE: 'WEBSTAGING',
    CHANNEL_ID: 'WAP',
    INDUSTRY_TYPE_ID: 'Retail',
    MERCHANT_KEY : '0Un**********y3R'
    }
}

Then, as per the steps provided in the above link which is

  • Copy the 'paytm' folder, index.js, router.js and server.js into your project directory.
  • Please set the required parameters in 'paytm/paytm_config.js' file. These parameters will be received after completing the registration process with Paytm.
  • For the Generate Checksum URL, please use the case for '/generate_checksum' in the router.js file. For example, a generate checksum URL may look like yoursite/generate_checksum.
  • For the Verify Checksum URL, please use the case for '/verify_checksum' in the router.js file. For example, a verify checksum URL may look like yoursite/verify_checksum.

I tried to call "yoursite/generate_checksum" as per step 3 on click of a button on my app like below.

exports.generate_cheksum = function(){
    console.log("generate_cheksum");

    const httpModule = require("http");
    httpModule.request({
        url: "http://www.vis******ma.com/paytm_mobile/index.js",
        method: "GET"
    }).then((response) => {
        console.log(response); //[object Object]
        response.map(key=>console.log(key)); //not getting anything
    }, (e) => {
        console.log("----error");
        console.log(e);
    });
}

But one thing I didn't get is how to call this "generate_checksum".

  • I Know the url is not correct. So how can I get checksum in response?
  • any other mistakes found ! Let me know.

Solution

  • write this php file anywhere on server ex: generate_checksum.php

    <?php
    
        require_once("encdec_paytm.php");
    
        define("merchantMid", "V******************3");
        // Key in your staging and production MID available in your dashboard
        define("merchantKey", "0**************R");
    
        // Key in your staging and production merchant key available in your dashboard
        define("orderId", "order1");
        define("channelId", "WEB");
        define("custId", "cust123");
        define("mobileNo", "7777777777");
        define("email", "[email protected]");
        define("txnAmount", "100.12");
        define("website", "WEBSTAGING");
        // This is the staging value. Production value is available in your dashboard
        define("industryTypeId", "Retail");
        // This is the staging value. Production value is available in your dashboard
        define("callbackUrl", "https://<Merchant_Response_URL>");
        $paytmParams = array();
        $paytmParams["MID"] = merchantMid;
        $paytmParams["ORDER_ID"] = orderId;
        $paytmParams["CUST_ID"] = custId;
        $paytmParams["MOBILE_NO"] = mobileNo;
        $paytmParams["EMAIL"] = email;
        $paytmParams["CHANNEL_ID"] = channelId;
        $paytmParams["TXN_AMOUNT"] = txnAmount;
        $paytmParams["WEBSITE"] = website;
        $paytmParams["INDUSTRY_TYPE_ID"] = industryTypeId;
        $paytmParams["CALLBACK_URL"] = callbackUrl;
        $paytmChecksum = getChecksumFromArray($paytmParams, merchantKey);
        $transactionURL = "https://securegw-stage.paytm.in/theia/processTransaction";
        // $transactionURL = "https://securegw.paytm.in/theia/processTransaction"; // for    production
    
        echo $paytmChecksum;
    ?>
    
    

    add this file "require_once("encdec_paytm.php");" in same folder from this link

    https://github.com/Paytm-Payments/Paytm_App_Checksum_Kit_PHP/blob/master/lib/encdec_paytm.php

    passing required fields to php file is left to you. u need to give your mid and mkey there.