20
Magento Partial Refund Amount Correction for Authorize.net
5 Comments | Posted by Will Wright in Magento, PHP
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.
5 Comments for Magento Partial Refund Amount Correction for Authorize.net
Chris | June 16, 2010 at 4:21 pm
Harry Pierson | January 17, 2011 at 2:09 pm
Hi,
I’m disappointed to see that Magento apparently does not allow partial invoicing with authorize.net (i.e. if we make multiple shipments on a single order, we can’t submit several invoices to cover the shipments individually)
Is this something you’ve dealt with? Would you be able to modify our system to be able to make multiple Authorize.net captures against a single Authorize.net authorization?
Thanks,
Harry
Scott | May 11, 2011 at 1:47 pm
Does this method still apply? It’s been about a year and a half since this was posted.
Will Wright | May 16, 2011 at 8:59 am
Not sure Scott. The principles of overwriting a module certainly still apply, but I haven’t opened up the Authorize.net module in the new version so I don’t know if the specifics are the same.
Shawn | May 26, 2011 at 3:18 pm
Let me know if this works for magento ver 1.3.2.4
and Im a newbie Im confused with the naming and implementation of generated module. Could you provide the step by step information of Creating this custom module and implementing it with out just saying use the Custom Module Creator


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.