Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Smart Payments: changing the currency code

I'm trying to set up PayPal Smart Payments on a webpage. I'm using the example they give on here: https://developer.paypal.com/docs/checkout/integrate/

If I have currency_code set to USD it works fine, but if I change it to anything else, such as CAD or GBP the window won't load. What am I doing wrong?

<script src="https://www.paypal.com/sdk/js?client-id=sb"></script>
<script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      return actions.order.create({
        'purchase_units': [{
          'amount': {
            'currency_code': 'USD',
            'value': '5',
          },
        }]
      })
    }
  }).render('body')
</script>

For some reason this example won't run here on Stack Overflow, but it runs fine on JSFiddle, so I have made two examples with the currency_code set differently.

'currency_code': 'USD': https://jsfiddle.net/liquidmetalrob/8y3p52fh/

'currency_code': 'GBP': https://jsfiddle.net/liquidmetalrob/8y3p52fh/1

The first example will load the PayPal window, and you need a PayPal Sandbox account to log into it. So if you want to log in you can use the throwaway account that I just created. Username: [email protected] password: pRKCu9.> But the important question is why does the window not even load in the second example?

like image 710
Rob Kwasowski Avatar asked Jan 01 '23 07:01

Rob Kwasowski


1 Answers

I found the answer here: https://developer.paypal.com/docs/checkout/reference/customize-sdk/

You have to add the currency code to the script URL instead, and remove it from the JS.

<script
  src="https://www.paypal.com/sdk/js?client-id=sb&currency=GBP">
</script>
<script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      return actions.order.create({
        'purchase_units': [{
          'amount': {
            'value': '5',
          },
        }]
      })
    }
  }).render('body')
</script>

Note: The client-id can be set to sb for testing, but in production you use your own one.

like image 57
Rob Kwasowski Avatar answered Feb 12 '23 02:02

Rob Kwasowski