Problem with creating an order with tax

vibralogix
Contributor
Contributor

I am attempting to create an order with items that have tax but the following code is causing an exception. I can't see any useful error messages so can anyone spot what I am doing wrong. There seem to be very few examples out there apart from simplistic ones.

 

<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [
{
reference_id: "ref",
custom_id: "123456",
amount: {
currency_code: "EUR",
value: "2.40",
},
amount_breakdown: {
item_total: {
currency_code: 'EUR',
value: '2.00'
},
tax_total: {
currency_code: 'EUR',
value: '0.40'
},
},
items: [
{
name: "Item 1",
description: "Description of item 1",
sku: "id1",
unit_amount: {
currency_code: "EUR",
value: "1.00"
},
tax: {
currency_code: "EUR",
value: "0.20"
},
quantity: "1"
},
{
name: "Item 2",
description: "Description of item 2",
sku: "id2",
unit_amount: {
currency_code: "EUR",
value: "1.00"
},
tax: {
currency_code: "EUR",
value: "0.20"
},
quantity: "1"
}
],
}
],
});
},
onApprove: function(data, actions) {
// Capture the funds from the transaction
return actions.order.capture().then(function(details) {
// Show a success message to your buyer
alert('Transaction completed by ' + details.payer.name.given_name);
});
},
onError: function (err) {
alert(err);
}
}).render('#paypal-button-container');
</script>

Login to Me Too
1 REPLY 1

vibralogix
Contributor
Contributor

In case anyone else needs this I found the solution.

 

paypal.Buttons({
    createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [
                {
                    reference_id: "ref",
                    custom_id: "123456",
                    amount: {
                        currency_code: "EUR",
                        value: "2.40",
                        breakdown: {
                            item_total: {
                              currency_code: 'EUR',
                              value: '2.00'
                            },
                            tax_total: {
                              currency_code: 'EUR',
                              value: '0.40'
                            },
                        }
                    },
                    items: [
                        {
                            name: "Item 1",
                            description: "Description of item 1",
                            sku: "id1",
                            unit_amount: {
                                currency_code: "EUR",
                                value: "1.00"
                            },
                            tax: {
                                currency_code: "EUR",
                                value: "0.20"
                            },
                            quantity: "1"
                        },
                        {
                            name: "Item 2",
                            description: "Description of item 2",
                            sku: "id2",
                            unit_amount: {
                                currency_code: "EUR",
                                value: "1.00"
                            },
                            tax: {
                                currency_code: "EUR",
                                value: "0.20"
                            },
                            quantity: "1"
                        }
                    ],
                }
            ],
        });
    },
    onApprove: function(data, actions) {
      // Capture the funds from the transaction
      return actions.order.capture().then(function(details) {
        // Show a success message to your buyer
        alert('Transaction completed by ' + details.payer.name.given_name);
      });
    },
    onError: function (err) {
      alert(err);
    }
}).render('#paypal-button-container');

 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.