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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: How do I calculate total sales for an order including refunds?

Solved

How do I calculate total sales for an order including refunds?

guster-dev-123
Tourist
3 0 3

Our company integrates with the Shopify POS and we will calculate daily total sales for a customer as part of our dashboard. Customer has found discrepancies in what they see on their own Shopify dashboard and what we calculate - which seems typically be due to refunds. Can I get clarification what the proper way to calculate the total sales for an order when refunds are also involved?

Currently using the /admin/api/2022-10/orders.json endpoint. 

Order total found on total_price property.
For refunds:  if a refund exists, we take the transactions array and subtract amount (if kind = 'refund' ). If a refund exists, but transactions array is empty, the assumption is the refund = 0.

The total amount for the order is calculated as total_price - refunds. 

Can someone confirm this is the correct or incorrect way of calculating refund totals?
Can someone explain why this would be different from what a customer might see on their Shopify dashboard?

Accepted Solution (1)
Ignelis
Shopify Partner
125 15 24

This is an accepted solution.

Yes, taxes and shipping costs could be factors that are affecting the total sales amount for an order. Depending on how the customer has set up their Shopify store, taxes and shipping costs may be included in the order total, or they may be added on separately.

 

To account for taxes and shipping costs, you may need to look at the following properties on the order resource:

  • subtotal_price: This is the total price of the line items in the order, before taxes and shipping are added.
  • total_tax: This is the total amount of tax charged for the order.
  • total_shipping_price_set: This is an object that contains information about the shipping cost for the order, including the shop_money and presentment_money amounts.

 

To calculate the total sales amount for an order, you would need to add up the subtotal_price, total_tax, and total_shipping_price_set amounts, and then subtract any refunds using your current method of calculating refunds.

 

It's also possible that there may be other factors at play, such as discounts or promotions, that are affecting the total sales amount for an order. If the customer is still experiencing discrepancies, it may be worth reviewing the order details in more detail to identify any other factors that could be affecting the total sales amount.

Have a nice day ƪ(˘⌣˘)ʃ
Hire me!
WhatsApp: +37062284670

View solution in original post

Replies 5 (5)

Ignelis
Shopify Partner
125 15 24

Hi, @guster-dev-123 

 

Your current method of calculating refund totals seems correct. You are subtracting the refunded amount from the total order price, which should give you the net sales amount for the order.

 

The reason for discrepancies between your calculations and what the customer sees on their Shopify dashboard could be due to timing differences. When a refund is issued, it may take some time for it to be reflected in the Shopify dashboard. Additionally, refunds may be processed in batches, which can further delay the appearance of the refund in the dashboard.

 

It's also possible that there may be other factors at play, such as taxes or shipping costs, that are affecting the total sales amounts. However, without more information it's difficult to say for certain.

 

If you are still experiencing discrepancies between your calculations and the customer's Shopify dashboard, it may be worth reaching out to Shopify's support team for further assistance. They can help you identify any potential issues with your API integration and provide guidance on how to resolve them.

Have a nice day ƪ(˘⌣˘)ʃ
Hire me!
WhatsApp: +37062284670
guster-dev-123
Tourist
3 0 3

Thank you for taking time to address the issue. 

I do not think timing is an issue as the customer seems to come to us after some time has past (at least a week or so). 

Can you elaborate more on other factors at play (taxes, shipping costs)? Are there other properties on the order resource that should be accounted for when calculating the total sale ($) for an order outside of total_price and refund.transactions

Our calculations are relatively simple otherwise. It would be helpful to know if there are other properties involved in this calculation that I am missing.

Re: Shopify support team. I've actually emailed them previously about our problem and was told it was beyond the scope of support. 

Ignelis
Shopify Partner
125 15 24

This is an accepted solution.

Yes, taxes and shipping costs could be factors that are affecting the total sales amount for an order. Depending on how the customer has set up their Shopify store, taxes and shipping costs may be included in the order total, or they may be added on separately.

 

To account for taxes and shipping costs, you may need to look at the following properties on the order resource:

  • subtotal_price: This is the total price of the line items in the order, before taxes and shipping are added.
  • total_tax: This is the total amount of tax charged for the order.
  • total_shipping_price_set: This is an object that contains information about the shipping cost for the order, including the shop_money and presentment_money amounts.

 

To calculate the total sales amount for an order, you would need to add up the subtotal_price, total_tax, and total_shipping_price_set amounts, and then subtract any refunds using your current method of calculating refunds.

 

It's also possible that there may be other factors at play, such as discounts or promotions, that are affecting the total sales amount for an order. If the customer is still experiencing discrepancies, it may be worth reviewing the order details in more detail to identify any other factors that could be affecting the total sales amount.

Have a nice day ƪ(˘⌣˘)ʃ
Hire me!
WhatsApp: +37062284670
guster-dev-123
Tourist
3 0 3

This sounds like the total_price property cannot be reliably used to calculate the TOTAL calculations of an order (excluding refunds). What does it effectively represent then?  Are you suggesting that we use the following properties to calculate sales (total_tax, total_shipping_price_set, subtotal_price) and potentially others (if they exist)? 

 

I need a reliable formula to use to calculate the sales for an order, including all possible factors that might be at play. We cannot go through each order individually to use different formulas. If `total_price` cannot be relied upon, it would be useful to a list of all the properties that must be accounted for. Does that exist?

team_supercrew
Tourist
4 0 2

Hey @guster-dev-123,

Could you figure out a reliable formula to calculate "Total Sales"?

 

Also, curious why you didn't take "kind = void" into account while calculating the returns.