Refund notification in Commerce

Is there a notification I can listen to, that fires when an order is (partially) refunded in Umbraco Commerce?

Hmm, doesn’t look like we do unfortunately so the best you can do right now is use an order save handler and see if the transaction array has changed (I believe we should give you access to the order before and after the changes being made)

Thanks, I’ll check that :+1:

How do I get the order before the changes? I only see an Order in the notification object.

Doh! Actually, I was wrong we don’t send the before/after order, but I was also wrong about there being no event. I think OrderTransactionUpdatedNotification should actually do the trick.

Something like

public class SendRefundNotificationHandler(IEmailService emailService)
    : NotificationEventHandlerBase<OrderTransactionUpdatedNotification>
{
    public override async Task HandleAsync(
        OrderTransactionUpdatedNotification evt,
        CancellationToken cancellationToken)
    {
        // Only react to (partial) refunds
        if (evt.PaymentStatus.To is not (PaymentStatus.Refunded or PaymentStatus.PartiallyRefunded))
            return;

        var order     = evt.Order;                       // OrderReadOnly
        var isPartial = evt.PaymentStatus.To == PaymentStatus.PartiallyRefunded;

        // The notification doesn't carry the amount — read the latest refund activity
        var refund = order.TransactionInfo.TransactionActivities
            .OfType<RefundTransactionActivity>()
            .LastOrDefault();

        var thisRefundAmount  = refund?.Amount;                  // amount of THIS refund
        var totalRefunded     = order.TransactionInfo.RefundedAmount; // cumulative across all refunds
        var reason            = refund?.MetaData?.RefundReason;
        var refundedLines     = refund?.MetaData?.OrderLines;    // lines + quantities

        await emailService.SendRefundNotificationAsync(
            order, thisRefundAmount, reason, isPartial, cancellationToken);
    }
}

Yes I found that too :slight_smile: hoping it only fires when there is new transactions then :slight_smile: