Refund Store Credit Automatically on Order Cancel

Well, the title says it all. This is for Enterprise_CustomerBalance module in Magento Enterprise, popularly known as Store Credit. Recently we had a requirement, if a person uses store credit to pay for an order either partially or fully, and if the order gets cancelled due to whatever reason, the store credit has to be refunded automatically to the customer. Well if yout think this feature is already there in Magento, you are wrong 😛

You can always issue a credit memo to refund the store credit, but what I am talking about is for orders which have not been invoiced yet and that can be canceled.

Logic is straight forward. Listen to the sales_order_payment_cancel event in an observer. Capture the store credit used in the order, refund the same to the customer. In codes, here you go!

To get store credit used in an order from order object

For updating store credit of a customer,

Here is the full module, use this if you are busy like me!

First create a module, I have created Hashid_Storecreditrefund ( I love my name 😛 ) . Add this in your config.xml

Create the observer now: Hashid/Storecreditrefund/Model/Observer.php and add the following:

That’s it, we are done! I have explained each step in comments. Do not forget to put your xml file in app/etc/modules folder.

To check the working

Create an order using customer’s store credit. And cancel it from admin. Order can be canceled only if invoice is not generated.

Do read my Extension Tutorials before doing this, if you are a beginner. Alright ciao!

The following two tabs change content below.
Hardcore programmer! Been playing with Magento for a while now!

One thought on “Refund Store Credit Automatically on Order Cancel

Leave a Reply

Your email address will not be published. Required fields are marked *