Order cancelled, refunded or Incomplete (for example an online payment for the rest of the order failed): the wallet part goes back to the customer's wallet automatically. If you later move that order back to a live status, the wallet amount is taken again.
Refund through the gateway only refunds what the customer paid by card or UPI. The wallet part is not sent to the bank; it is returned to the wallet as above.
Returns: if the customer chooses Store credit on their return request, approving and settling the return credits their wallet.
Point of sale: a counter return can also be refunded to the customer's wallet.