我正在嘗試將 paypal 添加到我的網站。我正在使用他們的 REST API,我想做的是讓用戶確定他們要存入的金額。我可以在創建付款時獲得總計,但我不確定如何在沒有復雜的對象數組系統的情況下將其傳遞到執行部分。有任何想法嗎?以下是我如何創建訂單和執行訂單的示例:router.post('/pay', (req, res) => { console.log(req.body.amount_to_deposit) var create_payment_json = { "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": `${domain}success`, "cancel_url": `${domain}cancel` }, "transactions": [{ "custom": req.user.steamid, "item_list": { "items": [{ "name": "Deposit", "sku": "001", "price": "25", "currency": "USD", "quantity": 1 }] }, "amount": { "currency": "USD", "total": "25" }, "description": `Deposit UserID:${req.user.steamid}` }] }; paypal.payment.create(create_payment_json, function (error, payment) { if (error) { throw error; } else { for(let i = 0;i < payment.links.length;i++){ if(payment.links[i].rel === 'approval_url'){ res.redirect(payment.links[i].href); } } } }); }); router.get('/success', (req, res) => { const payerId = req.query.PayerID; const paymentId = req.query.paymentId; console.log(req.query) const execute_payment_json = { "payer_id": payerId, "transactions": [{ "amount": { "currency": "USD", "total": "25" } }] }; paypal.payment.execute(paymentId, execute_payment_json, function (error, payment) { if (error) { console.log(error.response); throw error; } else { if (payment.transactions[0].custom) { console.log(payment.transactions[0].custom) } res.send('Success'); } }); });我可以使用 body 參數獲取用戶想要支付的金額,但是如何將其發送到成功路徑,從而執行支付 json 對象?
匹配交易總額的最簡單方法?
撒科打諢
2023-09-21 17:17:47