简体   繁体   English

如何将 PayTm 网关与 nodeJS 或 Reactjs 集成?

[英]How to integrate PayTm gateway with nodeJS or with Reactjs?

I am integrating Paytm payment gateway in my web app.我正在我的网络应用程序中集成 Paytm 支付网关。 I am using React for front end and nodeJs for back end.我在前端使用 React,后端使用 nodeJs。

I've made paytm post request successfully and everything is working fine but my callback url is making problems.我已成功发出 paytm post 请求,一切正常,但我的回调 url 出现问题。 I am getting data successfully I can see it in my network tab but when I am console logging req.body it is showing an empty object.我成功获取数据我可以在我的网络选项卡中看到它但是当我在控制台记录req.body它显示一个空对象。

This is response I am getting from paytm这是我从 paytm 得到的回应

这是我从 paytm 得到的回应

This where I am posting up the data这是我发布数据的地方

app.get('/user/recharge/mywallet' , (req, res) => {

    /* initialize an object with request parameters */
    var paytmParams = {
        "MID" : "my merchant id",
        "WEBSITE" : "WEBSTAGING",
        "INDUSTRY_TYPE_ID" : "Retail",

        /* WEB for website and WAP for Mobile-websites or App */
        "CHANNEL_ID" : "WEB",

        /* Enter your unique order id */
        "ORDER_ID" : "2213211",

        /* unique id that belongs to your customer */
        "CUST_ID" : "3221211",
        /**
        * Amount in INR that is payble by customer
        * this should be numeric with optionally having two decimal points
        */
        "TXN_AMOUNT" : "200",

        /* on completion of transaction, we will send you the response on this URL */
        "CALLBACK_URL" : "http://localhost:3001/true/paytmresp",
    };

    checksum.genchecksum(paytmParams, "My Merchant Key", function(err, checksum){
        /* for Staging */
        let url = "https://securegw-stage.paytm.in/order/process";
        /* Prepare HTML Form and Submit to Paytm */
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write('<html>');
        res.write('<head>');
        res.write('<title>Merchant Checkout Page</title>');
        res.write('</head>');
        res.write('<body>');
        res.write('<center><h1>Please do not refresh this page...</h1></center>');
        res.write('<form method="post" action="' + url + '" name="paytm_form">');
        for(let x in paytmParams){
            res.write('<input type="hidden" name="' + x + '" value="' + paytmParams[x] + '">');
        }
        res.write('<input type="hidden" name="CHECKSUMHASH" value="' + checksum + '">');
        res.write('</form>');
        res.write('<script type="text/javascript">');
        res.write('document.paytm_form.submit();');
        res.write('</script>');
        res.write('</body>');
        res.write('</html>');
        res.end();
        if(err) {
            console.log("err: ", err);
        }
        console.log('checksum: ', checksum);
    })
})

    app.post('/true/paytmresp', (req, res) => {
        console.log("body: ", req.body);
    })

I want to put my paytm response into variables so I can verify and add that to db我想将我的 paytm 响应放入变量中,以便我可以验证并将其添加到 db

You have missed adding body-parser in app.js你错过了在 app.js 中添加 body-parser

const bodyParser = require("body-parser"); const bodyParser = require("body-parser");

app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.urlencoded({extended: true }));

app.use(bodyParser.json()) app.use(bodyParser.json())

Same issue for me too! 我也遇到同样的问题! Can you share the solution if you found? 如果找到,可以分享解决方案吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM