Discussing APIs and development related to customers, discounts, and order management.
Hello, I'm using the Admin Rest API to get the orders of a store, and it is working well from several years.
The only problem I have is that I get an order transactions from /admin/api/2023-10/orders/{order_id}/transactions.json , I have the payments with the currency of the customer (USD). In some cases, the currency of the store is different (EUR). How could I get the payment with the currency of the store (EUR), or the exchange rate used during the transaction (as displayed on the store) ?
Currently I get following data from the API :
id (Integer) 6051360211152
order_id (Integer) 5104527769808
kind (String, 4 characters ) sale
gateway (String, 6 characters ) manual
status (String, 7 characters ) success
message (String, 37 characters ) Marked the manual payment as received
created_at (String, 25 characters ) 2024-01-25T09:06:12+01:00
test (Boolean) FALSE
authorization (NULL)
location_id (NULL)
user_id (NULL)
parent_id (NULL)
processed_at (String, 25 characters ) 2024-01-25T09:06:12+01:00
device_id (NULL)
error_code (NULL)
source_name (String, 12 characters ) checkout_one
receipt (Array, 0 elements)
amount (String, 7 characters ) 1112.00
currency (String, 3 characters ) USD
payment_id (String, 25 characters ) rRzbyPQLsgLBMH6YhPoxTgn1P
total_unsettled_set (Array, 2 elements)
admin_graphql_api_id (String, 44 characters ) gid://shopify/OrderTransaction/6051360211152
Thanks in advance,
Eric
Hi Eric,
The Shopify API doesn't directly provide the exchange rate used during the transaction. To work around this, you could:
Would this work for your use case?
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Create a product called something like "currency base" or "exchangeRate base".
Set it's price to 10,000,000,000 (10 billion)
Now, using the storefront api you can do something like:
query getStoreFrontExchangeRate @inContext(country: GB){
product (handle: "currency-base") {
priceRange{
maxVariantPrice {
amount
}
}
}
}
That will return the exchange rate for Great Britain.
Take the result, divide it by 10,000,000,000 and that will give you the exchange rate that shopify is using for calculating product pricing.
You can also query the admin api using:
{
productByHandle(handle: "currency-base") {
contextualPricing(context: {country: GB}) {
maxVariantPricing {
price {
amount
}
}
}
}
}