如何使用PayPal v2 JavaScript向多个商户发送付款



我有一个电子商务平台,有多个卖家在销售产品,我想使用PayPal checkout v2 Javascript向多个商家发送付款。

使用v2 JavaScript API:https://www.paypal.com/sdk/js?client-id=CLIENT_id&禁用资金=信用卡

paypal.Buttons({        
onInit: function(data, actions)  {
},        
createOrder: function(data, actions) {
return actions.order.create({
"purchase_units": [              
{
"reference_id": "1",
"amount": {
"currency_code": "AUD",
"value": "20.00",
"breakdown": {
"item_total": {
"currency_code": "AUD",
"value": "20.00"
}
}
},                    
"payee": {
"email_address": "payee1@business.example.com"
}
},
{
"reference_id": "2",
"amount": {
"currency_code": "AUD",
"value": "10.00",
"breakdown": {
"item_total": {
"currency_code": "AUD",
"value": "10.00"
}
}
},                    
"payee": {
"email_address": "payee2@business.example.com"
}
}
]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {        
alert('Transaction completed by ' + details.payer.name.given_name);
});
},        
onError: function (err)  {
alert(err.message);
}
}).render('#paypal-button'); 

我可以作为付款人登录,看到总共30美元,当我点击"立即支付"时,它会显示错误";订单无法获取";。如果我删除第二个购买单位对象(收款人2(,则交易被批准。

我阅读了PayPal论坛和api文档,看到了大多数不推荐的方法。我现在如何向多个商家付款?

  1. 没有使用JS签出批准多个v2/checkout/orders purchase_units的机制
  2. 也不应使用不推荐使用的方法

现在如何向多个商家发送付款?

无论如何,你不会同时这样做。每个都是自己单独的签出/批准事件。

  1. 您必须在沙箱或实时帐户中创建应用程序作为平台
  2. 使用js与多卖家结账集成的最佳用户体验
  3. 你已经在url和js部分传递了merchantids,如下所示如果多个卖家使用此

多个卖家

<script 
src="https://www.paypal.com/sdk/js?client-id=client_id&intent=capture&disable-funding=credit&merchant-id=*&currency=USD"  
data-partner-attribution-id="bn_code" 
data-merchant-id="merchant_id1,merchant_id2"
>
</script>

单一卖方

<script 
src="https://www.paypal.com/sdk/js?client-id=client_id&intent=capture&disable-funding=credit&merchant-id=merchant_id1&currency=USD" 
data-partner-attribution-id="bn_code" 
data-merchant-id="merchant_id1"
>
</script>

然后,您必须使用js-sdk与div的集成,如下所示

paypal.Buttons({
style : {
color: 'gold',
shape: 'pill',
label: 'pay',
},
createOrder: function (data, actions) {
return actions.order.create(data.json);
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
//redirect to your server
window.location.replace(base_url+'paypal/create_order/'+details.id)
})
},
onCancel: function (data) {
console.log(data);
},
onError: function (err) {
// For example, redirect to a specific error page
console.log(err);
}
}).render('#paypal-payment-button');

有关如何创建订单,请查看文档。

最新更新