What’s the best way to check if an order has been refunded in a template?

For example, you may want to:

  • Add a message to the order/invoice template if a refund has been successful.
  • Determine the status of the refund; perhaps displaying a different message if the status is not yet success.
  • Show the time of refund.

You get the related transactions for an order with


So you can loop over the transactions like so:

{% for transaction in order.transactions %}
  {{ transaction.type|title }}
  {{ transaction.status|title }}
  {{ transaction.amount|currency(transaction.currency) }} ({{ transaction.currency }})
  {{ transaction.paymentMethod.name }}
  {{ transaction.dateUpdated|date }} // could also format to get the time
{% endfor %}

The transaction 'type' column can hold the following values:

authorize, capture, purchase, refund

The transaction 'status' column can hold the following values:

pending, direct, success, failed

Some of those transaction types have a 'parent' transaction, for example, if you authorized a credit card, you would have a authorize transaction. When you capture that authorization you get a capture transactions whose parent is the authorize transaction.

{{ transaction.type }} // could return 'refund'
{% set parent = transaction.parent %}
{{ parent.type }} // could return 'purchase' or 'capture'

Let me know if you have further questions and I will improve the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.