【发布时间】:2020-04-09 12:23:26
【问题描述】:
我是 Node.js 的新手,正在部署 Paypal rest SDK,我被困在这一点上,我想将一个参数从 paypal API 调用的“success”api 传递给由 paypal API 调用的原始 API角度
//paypal
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': '',
'client_secret': ''
});
app.post('/pay-online', (req, res) => {
console.log('request came')
console.log(req.body.fare.toString())
var create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "localhost:3000/success",
"cancel_url": "localhost:3000/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": req.body.fare,
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": req.body.fare
},
"description": "This is the payment description."
}]
};
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
throw error;
} else {
console.log("Create Payment Response");
console.log(payment);
res.send(payment.links);
}
});
});
var getSuccess = app.get('/success', (req, res) => {
var paymentId = req.query.paymentId;
var payerId = { payer_id: req.query.PayerID };
paypal.payment.execute(paymentId, payerId, function (error, payment) {
console.log(payment.state)
if (error) {
console.error(JSON.stringify(error));
} else {
if (payment.state == 'approved') {
console.log('payment completed successfully');
} else {
console.log('payment not successful');
}
}
});
});
我需要将 (payment.state) 传递到调用“在线支付”API 的页面的问题,如何将参数传递回页面?
【问题讨论】:
标签: javascript node.js angular paypal