Try to change my currency, but when I use currency_code: 'EUR' I'm getting this error:
Error: Unexpected currency: EUR passed to order.create. Please ensure you are passing /sdk/js?currency=EUR in the paypal script tag.
When I go only with the currency: 'EUR' from the initialOptions and remove it from the PayPalButtons then it is using the Amount in USD and change it to EUR. But not everything is in Euro.
const initialOptions = {
'client-id': 'test',
currency: 'EUR',
intent: 'capture',
};
<PayPalScriptProvider options={initialOptions}>
<PayPalButtons
createOrder={(data, actions) => {
return actions.order.create({
purchase_units: [{
description:
'Rechnung '
dayjs(date, 'MM/YYYY').format('MMMM YYYY'),
amount: {
currency_code: 'EUR',
value: 2
}]
/>
</PayPalScriptProvider>
CodePudding user response:
In the current JS SDK design, rendering buttons for different currencies requires separate SDK loads.
When loading the SDK yourself, the data-namespace
attribute can be added at script load time. I don't see support for this in the react-paypal-js documentation.
<h3>USD buttons...</h3>
<div id="paypal-button-container-1" />
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD" data-namespace="paypalUSD"></script>
<script>
paypalUSD.Buttons({
//...
}).render('#paypal-button-container-1');
</script>
<hr />
<h3>EUR buttons...</h3>
<div id="paypal-button-container-2" />
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=EUR" data-namespace="paypalEUR"></script>
<script>
paypalEUR.Buttons({
//...
}).render('#paypal-button-container-2');
</script>
I don't see mention of this in the documentation of react-paypal-js , but looking at the package's code it does seem it may be supported. You'll need separate PayPalScriptProviders, each with their own currency and data-namespace
value (default is paypal
)