skip to Main Content

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


    1. There is no mechanism for approving multiple v2/checkout/orders purchase_units with the JS checkout.
    2. The deprecated methods should also not be used

    How do I send a payment to multiple merchants now adays?

    You don’t — not simultaneously, anyway. Each is its own separate checkout/approval event.

    Login or Signup to reply.
    1. You have to create app as platform in your sandbox or live account
    2. its best user experience to use js integration with multi seller checkout
    3. You have pass merchantids on url and in js section as below
      if multiple seller use this

    multiple seller

    <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>
    

    single seller

    <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>
    

    Then you have to use js sdk integration with div as below

    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');
    

    For how to create order please check the documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search