Jan/10
20
Magento Partial Refund Amount Correction for Authorize.net
The Problem:
You’ve enabled partial refunds in the Authorizenet Model, but it’s not refunding the proper amounts. This is due to, in my view, a bug in the core which I’ll show you how to patch!
The Solution:
What you need to do is overload the refund method in the Authorizenet model.
Create a new model that extends the original Authorizenet model. You’ll need to follow the general instructions for how to create a custom module if you don’t already know how to do so.
class Spinonesolutions_General_Model_Paygate_Authorizenet extends Mage_Paygate_Model_Authorizenet {
//Override Mage_Paygate_Model_Authorizenet
protected $_canRefund = true;
public function refund(Varien_Object $payment, $amount) {
$error = false;
if ($payment->getRefundTransactionId() && $amount>0) {
$payment->setAnetTransType(self::REQUEST_TYPE_CREDIT);
$request = $this->_buildRequest($payment, $amount);
$request->setXTransId($payment->getRefundTransactionId());
$result = $this->_postRequest($request);
if ($result->getResponseCode()==self::RESPONSE_CODE_APPROVED) {
$payment->setStatus(self::STATUS_SUCCESS);
} else {
$error = $result->getResponseReasonText();
}
} else {
$error = Mage::helper('paygate')->__('Error in refunding the payment');
}
if ($error !== false) {
Mage::throwException($error);
}
return $this;
}
}
Now all we need to do is let Magento know that we’ve got a custom model. In config.xml add
<?xml version="1.0"?>
<config>
<modules>
<Spinonesolutions_General>
<version>0.0.1</version>
</Spinonesolutions_General>
</modules>
<global>
<models>
...
<paygate>
<rewrite>
<authorizenet>Imagistic_General_Model_Paygate_Authorizenet</authorizenet>
</rewrite>
</paygate>
...
</models>
</global>
</config>
That should do it! Questions and comments welcome.
1 Comment for Magento Partial Refund Amount Correction for Authorize.net
Chris | June 16, 2010 at 4:21 pm


You F#’er wever been looking for this issue for the last 16 hours – ive wasted my life catching up to you in magento. :-p
Thanks for being an author i trust, and providing an answer i can use.