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?
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¤cy=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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With