4

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.
James
  • 1,138
  • 8
  • 20

1 Answers1

7

You get the related transactions for an order with

order.transactions

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.

Luke Holder
  • 6,827
  • 14
  • 27