My payment module is required to sent notifications to the payment service if an order is canceled or refunded. I assume that the “Cancel” button on the order page (in the administration backend) will cancel the order, and that the “Credit memo” button (after an invoice has been created) will refund the order.
How do I run my code on these events? I tried using the cancel() method in my payment method model, but the code did not run.
Seems like your payment method is not using transactions or does not create authorization transaction id. It is common beginner mistake in Payment gateways development.
To enable your payment gateway with online actions you need to implement something like this in your payment method: