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

时间:2019-08-25 07:42:29

标签: node.js reactjs paytm

This is response I am getting from paytm我正在将Paytm付款网关集成到我的Web应用程序中。我在前端使用React,在后端使用nodeJs。

我已经成功发出了paytm post请求,并且一切正常,但是我的回调URL出现了问题。我成功获取数据,可以在“网络”选项卡中看到它,但是当我在控制台记录req.body时,它显示了一个空对象

我已经成功发出了paytm post请求,并且一切正常,但是我的回调URL出现了问题。我成功获取数据,可以在“网络”选项卡中看到它,但是当我在控制台记录req.body时,它显示了一个空对象

这是我要发布数据的地方 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);
})

我想将我的paytm响应放入变量中,以便可以验证并将其添加到db

1 个答案:

答案 0 :(得分:0)

您错过了在app.js中添加正文解析器

const bodyParser = require(“ body-parser”);

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

app.use(bodyParser.json())