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.
No observable events are fired during the Payment processing stage of Magento. Instead, you define a class for whatever gateway you're implementing, and then define methods that Magento will automatically call as an order makes it's way through the various payment methods.
Poke around the base abstract payment class to see the various methods that will be called during payment processing. Define the same methods in your class to hook into the payment process at whatever point you'd like.
I don't do a lot of Payment Gateway implementations, but I'm guessing that
refund
is the method you want for credit memos, andcapture
is the one for invoices. It looks like thecancel
method is something specific to Google Checkout. Define all five in your class with some logging functions and walk though some fake orders on your development system if you want to know for sure.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:
Magento has event hooks that might be helpful. A list of events (a bit outdated, I think) can be found here. And there is a useful article about how Magneto's events work here.
Also, looking at existing payment extensions could be useful. I would not be surprised if similar events are dispatched by Google Checkout for order cancellations. The Extension repository will have lots of payment methods to look at.
Good luck!