错误:响应状态:400 PayPal Rest SDK



我在 NodeJS 的帮助下创建了一个带有一些PayPal支付的平台,直到现在一切都运行良好,我不知道为什么它会给我抛出这个错误。 1小时前 我做了付款,现在它不会让我。我没有修改任何代码或类似的东西。

这是错误

/用户/卡

利诺纳卡/桌面/谱系-笔记副本/控制器/饲料.js:863 抛出错误; ^

错误:响应状态:400 在来电消息。(/Users/calinonaca/Desktop/pedigree-NOTES copy/node_modules/PayPal-rest-sdk/lib/client.js:130:23( at IncomingMessage.emit (events.js:203:15( 在结尾可读NT (_stream_readable.js:1145:12( 在process._tickCallback(内部/进程/next_tick.js:63:19(

这是我的函数

exports.postPayment = (req,res,next) => {
const uploadedBy = req.body.noteOwner;
const finalprice = req.body.finalprice;
const notename = req.body.notename;
const loggedInUser = req.session.user._id;
const noteprice = req.body.noteprice;


const create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost/successPayment/"+finalprice+"/"+notename+"/"+uploadedBy+"/"+noteprice+"/"+loggedInUser,
"cancel_url": "http://localhost/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": "Note",
"sku": "001",
"price": finalprice,
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": finalprice
},
"description": "Note you ordered"
}]
};

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);
}
}
}
});
}

直到现在一切都很好,我不知道出了什么问题,你能帮帮我吗?谢谢!

我希望这会有所帮助,我遇到了同样的问题,我不得不挖掘几乎所有可能的链接和资源,我发现你必须映射 与这里完全相同的对象

"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "30.11",
"currency": "USD",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "0.03",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "0.01"
}
},
"description": "The payment transaction description.",
"custom": "EBAY_EMS_90048630024435",
"invoice_number": "48787589673",
"payment_options": {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"soft_descriptor": "ECHI5786786",
"item_list": {
"items": [
{
"name": "hat",
"description": "Brown hat.",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "USD"
},
{
"name": "handbag",
"description": "Black handbag.",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "USD"
}
],
"shipping_address": {
"recipient_name": "Brian Robinson",
"line1": "4th Floor",
"line2": "Unit #34",
"city": "San Jose",
"country_code": "US",
"postal_code": "95131",
"phone": "011862212345678",
"state": "CA"
}
}
}
],
"note_to_payer": "Contact us for any questions on your order.",
"redirect_urls": {
"return_url": "https://example.com/return",
"cancel_url": "https://example.com/cancel"
}

只有在我复制并粘贴此对象后,我才获得了带有重定向 url 的成功响应。我希望这对你有帮助。我会玩弄对象,看看是否有任何可以忽略的地方。

最新更新