0

我想創建批量支付與測試沙箱帳戶。 「創建付款」功能在工作絕對罰款正確的響應:貝寶批量支付不工作節點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": "[email protected]" 
      } 
     ] 
    }; 

及主要功能:

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開發者帳戶啓用。

有沒有可能的解決辦法?

回答

0

我剛剛得到了解決。好吧,補充一點,我必須說貝寶應該提供適當的錯誤處理,讓開發人員知道每個錯誤背後的原因。

錯誤是因爲我在配置中設置的貨幣。測試開發者帳戶位於其他某個國家/地區,貨幣代碼設置爲「USD」。 只需創建一個新帳戶,並根據您在創建測試開發者帳戶期間選擇的國家/地區設置配置貨幣代碼。

0

我測試支出,如下面的代碼,它工作正常。您可以將您的代碼與我的示例進行比較,您可以添加'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": "[email protected]", 
 
      "note": "Thank you.", 
 
      "sender_item_id": "item_1" 
 
     }, 
 
     { 
 
      "recipient_type": "EMAIL", 
 
      "amount": { 
 
       "value": 0.90, 
 
       "currency": "USD" 
 
      }, 
 
      "receiver": "[email protected]", 
 
      "note": "Thank you.", 
 
      "sender_item_id": "item_2" 
 
     }, 
 
     { 
 
      "recipient_type": "EMAIL", 
 
      "amount": { 
 
       "value": 2.00, 
 
       "currency": "USD" 
 
      }, 
 
      "receiver": "[email protected]", 
 
      "note": "Thank you.", 
 
      "sender_item_id": "item_3" 
 
     } 
 
    ] 
 
}'