Expected currency from order api call
-
We’re getting “Expected currency from order api call to be USD, got EUR. Please ensure you are passing currency=EUR to the sdk url.”
Currency is set only at checkout using the billing country – it’s not set by geolocation. Our site currency is USD. I’m in Spain, selected US as the country. Selecting Spain or UK was OK.
Using Aelia Currency Converter, which doesn’t do a hard refresh for conversions.
-
Hi @henrybaum
This error occurs when the PayPal JS SDK is loaded with a certain currency, but then the currency passed in the API call to PayPal is different.
The PayPal plugin uses core WooCommerce functions for retrieving and use the currency. When loading the PayPal JS SDK,
get_woocommerce_currency()is used.When creating a PayPal order,
get_woocommerce_currency()andWC_Order::get_currency()are used.It would seem there is a disconnect between the currency provided when the JS script is loaded, and what’s being used server side when API requests are made. The JS SDK using
USDbut server side, theget_woocommerce_currency()function call is returningEUR. That sounds like an Aelia issue.Kind Regards
I’m the author of the Aelia plugin mentioned, I’ve been asked to look into this. Based on what we have seen on the site, that’s not an issue on our side. However, the root cause does seem to be the one described:
It would seem there is a disconnect between the currency provided when the JS script is loaded, and what’s being used server side when API requests are made
This is a slightly imprecise statement, but it’s in the right direction. In a multi-currency environment, the functions
get_woocommerce_currency()andWC_Order::get_currency()may or may not return the same value. The former returns the active currency at a given time, which may change depending on the context, whereasWC_Order::get_currency()always returns the currency in which an order is placed. The two are not the same thing, and can’t be used interchangeably.In the specific case reported by @henrybaum , the site is using multiple currencies, and it’s configured so that when a customer chooses a country at checkout, the currency in which the order is being placed changes as well. For example, a customers choosing US will see USD, a customer choosing UK will see GBP, and so on. Due to that, the following can happen:
- When the checkout page is loaded, the currency is USD. Calling
get_woocommerce_currency()returns USD. - The customer changes the country to France. WooCommerce triggers a “refresh order” event, which is a fetch/Ajax call (i.e. it doesn’t refresh the page). The call passes the newly selected country (Spain) and that changes the currency to EUR.
- The customer places the order. The order is placed in EUR, as it should be.
The “disconnect” between the currency on page load and the one after the checkout refresh is not due to an error, it’s due how the system works. Quite simply, at the time of a “page load” event it’s not possible to determine with certainty in which currency an order will be placed. Fetching the currency at that time could lead to a discrepancy when the checkout is actually started.
Suggested solution
To address the issue during the payment process, the currency to be used for payments should only be fetched from the order when it’s placed. That value never changes (our Currency Switcher doesn’t even take part into the payment process, and never alter existing orders). If you need to build a URL for the PayPal SDK, then the currency should be stored into a variable and added to the URL as the second to last step, just before calling the PayPal service.
For the sake of clarity, this behaviour is nothing new. The currency selection has been working this way for at least a decade. The fix I described is something we recommended to other developers, and it should be sufficient to prevent the error.
The customer changes the country to France. WooCommerce triggers a “refresh order” event, which is a fetch/Ajax call (i.e. it doesn’t refresh the page). The call passes the newly selected country (Spain) and that changes the currency to EUR.
Yes, you’re most likely referring to the
update_checkoutevent that WooCommerce triggers when checkout page inputs change. The PayPal plugin listens for theupdated_checkoutevent and re-loads the PayPal JS SDK if the currency value changes, so what you’re describing has been accounted for.then the currency should be stored into a variable and added to the URL as the second to last step, just before calling the PayPal service.
That’s not advisable and would cause a significant decreased in conversion rates if put into practice. Best practice is to setup the PayPal integration on page load, and reload the PayPal script as required.
I am wondering if this is an order that was attempted via a product or cart page, using PayPal as an express payment option. Does the currency plugin provide switching capability on other pages beyond the checkout page?
@henrybaum can you confirm if this was an order that originated from the checkout page or another page like the product or cart page?
@daigo75 can you reach out via our support page? It would be helpful to have a license to your plugin to perform additional testing.
The plugin does have a widget to change the currency before checkout, but we don’t use it. This order was made with an add to cart button on a standard page that goes straight to checkout, bypassing the cart. The only place to complete payment is at checkout.
@henrybaum can you share a link to a product page so your site can be reviewed?
The plugin isn’t live yet but this is our production site: https://www.selfpublishingreview.com/get-reviewed/ or https://www.independentreviewofbooks.com/submit-your-book-for-review/ (using a different payments plugin currently).
I’m not sure how adding a currency code to the settings of an integration could affect conversions, but that’s not the issue in this case.
To answer your question, there is a currency selector, which the client is not using. The selector reloads the whole page with the new currency, so that would not cause any issue. The only discrepancy can occur when there is one currency at page load, and another when the order is placed. That can happen most frequently in the scenario I already described, hence my suggestion.
I would be more than happy to provide you with a development licence. If you have an email address to which I could send it, I will do that as soon as possible.
If you have an email address to which I could send it, I will do that as soon as possible.
The WordPress forum rules prevent the sharing of an email address. I provided a link in my previous reply where you can create a support ticket. That’s the best way to contact us.
Kind Regards
- When the checkout page is loaded, the currency is USD. Calling
The topic ‘Expected currency from order api call’ is closed to new replies.