I can’t figure out how to determine the right refund amount for two types of orders:
- Orders where the refunded amount has been “manually” overridden to a lower amount than the lineItems suggest, e.g.. if taking a return fee.
- Orders with exchanges.
I can get the amounts right in each case in isolation, but the fix makes the amount incorrect in the other scenario.
1: Orders with manual amounts
Let’s say you refund a line item worth 269,95 kr., but manually override the amount to 250,9 kr. because of a return fee. That gives you the following refund object where the totalRefundedSet is the right amount, not the sum of the refundLineItems.
The problem is if I just record the totalRefundedSet amount as the refunded amount, I get problems in the next scenario, orders with exchanges.
2: Orders with exchanges
If an order has an exchange, I get the following refund object because of the returned product:
Also, the subTotalPriceset gets updated because of the “new” product in the exchange.
The totalRefundedSet, in the refund object, is technically the correct refund amount as there’s only refunded 100 kr. to the customer.
But if I only subtract 100 kr. from the order’s subtotalPriceSet, which is higher than the original amount because of the exchange, the revenue isn’t correct. So here I have to record the sum of the refunded line items as the total refunded amount to get revenue, which is opposite of the fix in scenario 1.


