Paypal批量支付在node js api中不起作用



我正试图用一个测试沙箱帐户创建一个批量支付。"创建支付"功能运行良好,响应正确:

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 }

然而,我确信通过的凭证是正确的,在创建支付的情况下,它们可以完美地工作。我这么做首先是为了测试。此外,支付功能是为这个相应的测试贝宝开发者帐户启用的。

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

我刚刚得到了解决方案。好吧,补充一下,我必须说贝宝应该提供适当的错误处理,让开发者知道每个错误背后的原因。

错误是由于我在配置中设置的货币。测试开发人员帐户来自其他国家,货币代码设置为"USD"。只需创建一个新帐户,并根据您在创建测试开发人员帐户时选择的国家/地区在配置中设置货币代码。

我测试支出,如下代码所示,它运行良好。您可以将您的代码与我的示例进行比较,也可以添加"sender_batch_id"参数进行尝试。

curl -v https://api.sandbox.paypal.com/v1/payments/payouts/ 
-H "Content-Type:application/json" 
-H "Authorization: *****" 
-d '{
    "sender_batch_header": {
        "sender_batch_id": "batch_25",
        "email_subject": "You have a payment"
    },
    "items": [
        {
            "recipient_type": "EMAIL",
            "amount": {
                "value": 0.99,
                "currency": "USD"
            },
            "receiver": "aaabbb@email.com",
            "note": "Thank you.",
            "sender_item_id": "item_1"
        },
        {
            "recipient_type": "EMAIL",
            "amount": {
                "value": 0.90,
                "currency": "USD"
            },
            "receiver": "bbbb@gmail.com",
            "note": "Thank you.",
            "sender_item_id": "item_2"
        },
        {
            "recipient_type": "EMAIL",
            "amount": {
                "value": 2.00,
                "currency": "USD"
            },
            "receiver": "cccc@gmail.com",
            "note": "Thank you.",
            "sender_item_id": "item_3"
        }
    ]
}'

相关内容

  • 没有找到相关文章

最新更新