Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Get exchange rate for an order transaction with admin API

Get exchange rate for an order transaction with admin API

erpmathieu
Shopify Partner
4 0 1

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) ?

Screenshot 2024-01-25 at 11.22.45.png

 

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

Replies 3 (3)

Liam
Community Manager
3108 344 889

Hi Eric,

 

The Shopify API doesn't directly provide the exchange rate used during the transaction. To work around this, you could:

  • Use a third-party currency conversion API to get historical exchange rates. You would need the date of the transaction (which you already have) and then convert the amount from USD to EUR based on the historical exchange rate of that specific day.
  • Record exchange rates daily in your database and use these rates to convert historical transactions.

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

erpmathieu
Shopify Partner
4 0 1
Hi Liam, Thanks for your answer!

We are afraid of having discrepancies between the exchange rates so we will
probably load all the prices with the buyer currency to avoid this problem,
and use the sales order exchange rate (shop_money.amount /
presentment_money.amount) for our reports.

Cheers
Eric
Schmidtc63
Shopify Partner
101 14 29

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
        }
      }
    }
  }
}