问题描述
我正在使用Paytm付款网关进行交易。我的前端在reactjs中,后端在nodejs和expressjs中。我希望在成功付款后,可以重定向下一页。
后端代码- 用于检查校验和和交易。
PaytmChecksum.generateSignature(JSON.stringify(paytmParams.body),paytmconfig.merchantkey).then(function(checksum){
paytmParams.head = {
"signature" : checksum
};
var post_data = JSON.stringify(paytmParams);
var options = {
/* for Staging */
hostname: 'securegw-stage.paytm.in',/* for Production */
// hostname: 'securegw.paytm.in',port: 443,path: '/v3/order/status',method: 'POST',headers: {
'Content-Type': 'application/json','Content-Length': post_data.length
}
};
// Set up the request
var response = "";
var post_req = https.request(options,function(post_res) {
post_res.on('data',function (chunk) {
response += chunk;
});
post_res.on('end',function(){
console.log('Response: ',response);
res.write(response)
});
});
// post the data
post_req.write(post_data);
post_req.end();
});
onPayment= async(e)=>{
e.preventDefault();
try {
var amount="1.00";
var mobile_number="+919999999999";
var email="abcd@gmail.com";
var orderId="ORDER_ID"+(new Date().getTime());
let params={
orderId:orderId,email:email,amount:amount,mobile_number:mobile_number
}
var url="http://localhost:4000/payment/payNow";
var request={
url:url,params:params,method:"get"
}
const response = await Axios(request);
const processparams=await response.data;
console.log(processparams);
var details={
action : "https://securegw-stage.paytm.in/order/process",// params : params
params : processparams
}
this.post(details);
} catch (error) {
}
}
解决方法
您可以使用react-router-dom
import {useHistory} from 'react-router-dom'
const history = useHistory()
history.push('yourNextPage',{details:detail})
history.replace都应该起作用:
history.replace('yourNextPage',{details:detail})
编辑
{details:detail}是要让您将下一页的状态传递到上一页的状态
如果您不想通过任何状态
就足够了
history.push('yourNextPage')
,
请参考以下存储库中可用的代码,以获取node.js中的校验和。
https://github.com/paytm/Paytm_Node_Checksum
您还可以参考以下存储库以进行响应(前端)