I have an ecommerce platform that has multiple sellers selling products and I want to use PayPal checkout v2 Javascript to send a payment to multiple merchants.
Using v2 JavaScript API:
https://www.paypal.com/sdk/js?client-id=CLIENT_ID&disable-funding=credit,card
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": "[email protected]"
}
},
{
"reference_id": "2",
"amount": {
"currency_code": "AUD",
"value": "10.00",
"breakdown": {
"item_total": {
"currency_code": "AUD",
"value": "10.00"
}
}
},
"payee": {
"email_address": "[email protected]"
}
}
]
});
},
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');
I can login as a payer and see total $30, when I click Pay Now it says error "Order can not be captured". If I remove the second purchase unit object (payee 2) the transaction is approved.
I read on PayPal forums and api documentations and see mostly deprecated methods. How do I send a payment to multiple merchants now adays?
2
Answers
You don’t — not simultaneously, anyway. Each is its own separate checkout/approval event.
if multiple seller use this
multiple seller
single seller
Then you have to use js sdk integration with div as below
For how to create order please check the documentation.