Search code examples
paypalpaypal-sandbox

PayPal Smart Button / Orders V2 API Shipping Value


Is it possible to add a customized shipping fee to a PayPal checkout, like the items?

enter image description here

Here's some sample code with static values for reference.

var paypalAmount = {"value":"78.95","breakdown":{"item_total":{"currency_code":"USD","value":"78.95"}}};

var paypalItems = [{"name":"sample item","unit_amount":{"currency_code":"USD","value":"39.95"},"quantity":"1","category":"PHYSICAL_GOODS"},{"name":"sample item2","unit_amount":{"currency_code":"USD","value":"39.00"},"quantity":"1","category":"PHYSICAL_GOODS"}];

  createOrder: function(data, actions) {
            return actions.order.create({
                purchase_units: [{
                    amount: paypalAmount,
                    items: paypalItems
                }],
                headers: {
                    'content-type': 'application/json'
                },
            });
        }

Solution

  • In "amount" you are passing a "breakdown" object, which takes a "shipping" parameter, as documented here: https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown