Refund online button in magento custom payment method

images

In your custom payment module if you need to build any custom api to make refund from the magento backend. Make sure the following things added in your custom module.

In config.xml

    <default>
        <payment>
            <namespace_modulename>
                <model>namespace/modulename</model>
                <payment_action>authorize</payment_action> 
            <namespace_modulename>
        </payment>
    </default>

The authorize function is very important in your source model file. Because the order amount should be authorized in the payment gateway before making refund. And enable the active variables to make refund.

     <?php
class Namespace_Modulename_Model_Paymentname extends Mage_Payment_Model_Method_Abstract {
    protected $_canAuthorize = true;
    protected $_canCapture = true;
    protected $_canRefund = true; 

    public function authorize(Varien_Object $payment, $amount) {
        if (!$this->canAuthorize()){
            $payment->setTransactionId(time());
            $payment->setIsTransactionClosed(0);
         }
        return $this;
    }
    public function refund(Varien_Object $payment, $amount) {
      //your api code here for refund
    }
}

The refund function will call back when you click refund button in the credit memo page of order invoice. Enjoy your work!! 🙂

Leave a Reply

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