gpt4 book ai didi

node.js - Paypal 批量付款在 Node js api 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 15:59:06 28 4
gpt4 key购买 nike

我正在尝试使用测试沙盒帐户创建批量付款。“创建付款”功能在正确响应下工作得非常好:

var paypal_sdk = require('paypal-rest-sdk');

var config_opts = {
'host': host, //host defined
'port':'',
'mode':'sandbox',
'client_id': client_id, //clientID defined
'client_secret': client_secret, //clientSecret defined
};

var makePayment = function (req, res, next) {
var create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://mystore.in",
"cancel_url": "http://mystore.in/contact"
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}
]
};

paypal_sdk.payment.create(create_payment_json,config_opts, function (err, data) {
if (err) console.log("ERRRRR", err);
console.log("Create Payment Response");
console.log(data);
//res.send('201');
});
}

makePayment(); //CALLING THE FUNCTION

但是,当我尝试创建新的付款时,将 create_payment_json 编辑为:

var create_payment_json = {
"sender_batch_header": {
"email_subject": "You have a Payout!",
"recipient_type": "EMAIL"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": "1.0",
"currency": "USD"
},
"note": "Thanks for your patronage!",
"sender_item_id": "201403140001",
"receiver": "shirt-supplier-one@mail.com"
}
]
};

主要功能为:

paypal_sdk.payout.create(create_payment_json,config_opts, function (err, data) {
if (err) console.log("ERRRRR", err);
console.log("Create Payment Response");
console.log(data);
//res.send('201');
});

我收到如下错误:

{ [Error: Response Status : 401]
response:
{ error: 'invalid_client',
error_description: 'Client Authentication failed',
httpStatusCode: 401 },
httpStatusCode: 401 }

但是,我确信传递的凭据是正确的,并且在创建付款时它们可以完美地工作。我首先为测试做这一切。此外,还为此相应的测试 Paypal 开发者帐户启用了支付功能。

有什么可能的解决方案吗?

最佳答案

我刚得到解决方案。嗯,补充一下,我必须说 paypal 应该提供适当的错误处理,让开发人员知道每个错误背后的原因。

错误是因为我在配置中设置的货币。测试开发者帐户属于其他国家,货币代码设置为“USD”。只需创建一个新帐户并根据您在创建该测试开发者帐户时选择的国家/地区在配置中设置货币代码。

关于node.js - Paypal 批量付款在 Node js api 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36397584/

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