Home » Magento » Magento Payment Gateway : Authorize.net of Duplicate orders issue

Magento Payment Gateway : Authorize.net of Duplicate orders issue

Authorize.net of Duplicate orders issue
Magento Payment Gateway : Authorize.net of Duplicate orders issue

When we place the order through Authorize.net(payment gateway) in Magento  then sometimes we get duplicate orders.
Here the flow of code is that on request to Authorize.net set a curl action starts.
Now Authorize.net will internally check with Credit card companies for authentication of these credit card details.Credit card companies reply back to Authorize.net which in turn replies to website. As this involves too many sites if for some reason internet is slow( congestion) or some of the servers have a heavier load then the reply might reach after the curl timer has expired.
Client on the side was notified that payment was not complete resulting in Him repaying.This in turn results in duplicate orders.
To avoid this scenario, we can increase the curl timeout from following code file
Path: app/code/core/Mage/Paygate/Model/Authorizenet.php

protected function _postRequest(Varien_Object $request)
{
$result = Mage::getModel(‘paygate/authorizenet_result’);
$client = new Varien_Http_Client();
$uri = $this->getConfigData(‘cgi_url’);
$client->setUri($uri ? $uri : self::CGI_URL);
$client->setConfig(array(
maxredirects’=>0,
‘timeout’=>30,
//’ssltransport’ => ‘tcp’,
));
$client->setParameterPost($request->getData());
$client->setMethod(Zend_Http_Client::POST);
if ($this->getConfigData(‘debug’)) {
$requestDebug = clone $request;
foreach ($this->_debugReplacePrivateDataKeys as $key) {
if ($requestDebug->hasData($key)) {
$requestDebug->setData($key, ‘***’);
}
}
foreach( $requestDebug->getData() as $key => $value ) {
$requestData

[] = strtoupper($key) . ‘=’ . $value;
}
$requestData = join(‘&’, $requestData);
$debug = Mage::getModel(‘paygate/authorizenet_debug’)
->setRequestBody($requestData)
->setRequestSerialized(serialize($requestDebug->getData()))
->setRequestDump(print_r($requestDebug->getData(),1))
->save();
}
try {
$response = $client->request();
} catch (Exception $e) {
$result->setResponseCode(-1)
->setResponseReasonCode($e->getCode())
->setResponseReasonText($e->getMessage());
if (!empty($debug)) {
$debug
->setResultSerialized(serialize($result->getData()))
->setResultDump(print_r($result->getData(),1))
->save();
}
Mage::throwException($this->_wrapGatewayError($e->getMessage())
);
}
$responseBody = $response->getBody();
$r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
if ($r) {
$result->setResponseCode((int)str_replace(‘”‘,”,$r[0]))
->setResponseSubcode((int)str_replace(‘”‘,”,$r[1]))
->setResponseReasonCode((int)str_replace(‘”‘,”,$r[2]))
->setResponseReasonText($r[3])
->setApprovalCode($r[4])
->setAvsResultCode($r[5])
->setTransactionId($r[6])
->setInvoiceNumber($r[7])
->setDescription($r[8])
->setAmount($r[9])
->setMethod($r[10])
->setTransactionType($r[11])
->setCustomerId($r[12])
->setMd5Hash($r[37])
->setCardCodeResponseCode($r[38])
->setCAVVResponseCode( (isset($r[39])) ? $r[39] : null);
} else {
Mage::throwException(
Mage::helper(‘paygate’)->__(‘Error in payment gateway’)
);
}
if (!empty($debug)) {
$debug
->setResponseBody($responseBody)
->setResultSerialized(serialize($result->getData()))
->setResultDump(print_r($result->getData(),1))
->save();
}
return $result;
}
We can increase the curl timeout from following array list:
$client->setConfig(array(
‘maxredirects’=>0,
‘timeout’=>30,
//’ssltransport’ => ‘tcp’,
));

This solved our problem of duplicate orders.