How do I export the total paid amount from a Shopify order?

You may want to export the total amount paid by the customer so far for a partially paid order or the actual amount paid if the order is refunded/partially refunded.

The Shopify API doesn't have a field a field for this.  However, we can calculate this by looking at the transaction data and using this formula in EZ Exporter via the Calculated Fields feature:

(get_total(to_list(search_attributes({{ transactions.successful_transactions }}, "sale", search_key="kind", result_key="amount", return_all_results=True))) + get_total(to_list(search_attributes({{ transactions.successful_transactions }}, "capture", search_key="kind", result_key="amount", return_all_results=True)))) - ({{ refunds.transactions.total_amount }} or 0)

The formula is a bit complex as we have to filter only successful transactions and specific types of transactions.  Depending on the payment gateway, the transaction may get authorized and captured at the same time which will set its "kind" attribute to "sale".  If the authorization and capture are separate, then they will show up as separate transactions.

The formula above accounts for both and then also subtracts refund tranactions.  The result would be the total amount that was actually paid by the customer.

More info here about Shopify transactions: https://shopify.dev/docs/admin-api/rest/reference/orders/transaction


App: EZ Exporter

Tags: transactions, shopify order