gpt4 book ai didi

javascript - 向 PayPal Payouts REST API 发送请求返回 HTTP 代码 204 且无内容

转载 作者:太空宇宙 更新时间:2023-11-03 16:39:20 26 4
gpt4 key购买 nike

我想调用我的服务器,然后它会调用 PayPal Payouts REST API 来进行特定的支付。我设置了必要的帐户,当我尝试使用 Postman 时,一切都很好!我使用 token 和 Content-Type 设置为 application/json 和正文

{
"sender_batch_header": {
"sender_batch_id": "Payouts_2018_100013",
"email_subject": "You have a payout!",
"email_message": "You have received a payout from ****! Thanks for using our service!"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": "9.87",
"currency": "EUR"
},
"receiver": "****@*****.com"
}]
}

这将返回类似

的内容
{
"batch_header": {
"payout_batch_id": "F5YLETFEWFLUS",
"batch_status": "PENDING",
"sender_batch_header": {
"sender_batch_id": "Payouts_2018_100012",
"email_subject": "You have a payout!",
"email_message": "You have received a payout from realnote! Thanks for using our service!"
}
},
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payouts/F5YLETFEWFLUS",
"rel": "self",
"method": "GET",
"encType": "application/json"
}
]
}

使用 HHTP 代码 201(已创建)。这是完全正确的,当使用答案中的 payout_batch_id 调用相应的 URL 时,我可以看到我的付款状态。

但是,如果我尝试从我的 NodeJS 服务器进行相同的调用,就会出现问题。我得到了 token ,一切正常,但随后我创建了这样的请求:

const options = {
url: "https://api.sandbox.paypal.com/v1/payments/payouts",
headers: {
'Content-Type': 'application/json'
},
auth: {
'bearer': token
},
form: {
"sender_batch_header": {
"sender_batch_id": "***_payment_***",
"email_subject": "You have a payout!",
"email_message": "You have received a payout from ****! Thanks for using our service!"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": "10.0",
"currency": "EUR"
},
"receiver": "*****@*****.com"
}]
}
};

然后我使用带有以下代码的 request 模块发送请求:

request.post(options, function(err,httpResponse,body){
if (err) {
console.error('Sending money failed:', err);
} else {
console.log('Response from PayPal successful! Server responded with:', body);

//var payPalAnswer = JSON.parse(body);
}
})

但这将导致获得状态代码为 204(无内容)的答案,并且它包含,毫无疑问,没有内容,因此不可能像我使用的服务器答案那样获得我的付款状态 postman 。我的错误在哪里?

最佳答案

request.post(options, {data: "..."},function(err,httpResponse,body){
if (err) {
console.error('Sending money failed:', err);
} else {
console.log('Response from PayPal successful! Server responded with:', body);

//var payPalAnswer = JSON.parse(body);
}
})

你必须使用你的数据作为第二个参数

关于javascript - 向 PayPal Payouts REST API 发送请求返回 HTTP 代码 204 且无内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58325865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com