graemeleftsockcouk
graemeleftsockcouk

Reputation: 31

How to ammend paypal smart button to include vat (tax)

I have a Paypal generated smart button that I want to amend so that vat is broken down correctly on the paypal receipt.

I've read the paypal pages that say it cant be done in the paypal interface but have to be called through on the api.

The code I current have is...

<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=xxxzzz&currency=GBP" data-sdk-integration-source="button-factory"></script>
<script>
  paypal.Buttons({
      style: {
          shape: 'rect',
          color: 'gold',
          layout: 'vertical',
          label: 'paypal',
          
      },
      createOrder: function(data, actions) {
          return actions.order.create({
              purchase_units: [{
                  description: "my amazing rocketpack",
                  amount: {
                      value: '2.99'
                  }
              }]
          });
      },      onApprove: function(data, actions) {
          return actions.order.capture().then(function(details) {
              alert('Shop transaction completed by ' + details.payer.name.given_name + '!');
          });
      }
  }).render('#paypal-button-container');
</script>

Looking at the paypal docs for purchase units it suggests I need to turn on amount.breakdown and specify item_total and tax_total.

But I cant seem to get it right (it either breaks the button so it doesn't display at all or the receipt is still just gross amount) and can find no examples of the code

Upvotes: 1

Views: 570

Answers (1)

graemeleftsockcouk
graemeleftsockcouk

Reputation: 31

Solved, in case anyone else wants to know, the below is how you initiate amount.breakdown (there is no dot)

              purchase_units: [{
                  description: "my item",
                  amount: {
                      value: '29.99',
                      currency_code: 'GBP',
                        breakdown: {
                            item_total: {
                                currency_code: 'GBP',
                                value: '24.99'
                            },
                tax_total: {
                                currency_code: 'GBP',
              value: '5.00'
                },
            }
                  }
              }]

Upvotes: 2

Related Questions