Search code examples
javascriptpaypalpaypal-rest-sdk

Unable to set currency using PayPal JavaScript SDK


I am trying to set the currency for the PayPal API and I am unable to do so. When you click on the PayPal button, It shows the total amount in USD (next to the cart icon). Under pay with, it shows the amount converted to CAD which is not what I want. I want the amount set in createOrder to be in the currency I set.

<script src="https://www.paypal.com/sdk/js?currency=CAD&client-id="></script>

<script>
paypal.Buttons({
  createOrder: function(data, actions) {
    return actions.order.create({
      intent: "CAPTURE",
      purchase_units: [{
        amount: {
          value: "150"
        }
      }]
    });
  },
  onError: function (err) {
    alert(err);
  }
}).render('#paypal-button-container');
</script>

I have tried to put currency_code: "CAD" in amount but I get:

Error: Unexpected currency: CAD passed to order.create. Please ensure you are passing /sdk/js?currency=CAD in the PayPal script tag.

Solution

  • Not sure where you're going wrong, since your code would work if it were complete. The following is a working example:

    <script src="https://www.paypal.com/sdk/js?currency=CAD&client-id=sb"></script>
    
    <script>
    paypal.Buttons({
      createOrder: function(data, actions) {
        return actions.order.create({
          intent: "CAPTURE",
          purchase_units: [{
            amount: {
              value: "150",
              currency_code: "CAD"
            }
          }]
        });
      },
      onError: function (err) {
        alert(err);
      }
    }).render('body');
    </script>