Anyone building a custom payment method for
Magento 2 pours most of their care into checkout, authorization, and capture, because that is where revenue is created. Refund handling is often treated as a minor afterthought and bolted on later as a simple API call, without really engaging with the command pattern that underpins Magento's payment gateway architecture. That neglect catches up eventually: misbooked credit memos, duplicate refunds, or partial refunds that do not line up with the right shipment are common in payment integrations that grew organically. This article shows how to structure refund handling correctly along the command pattern, including partial refunds and robust error handling.