Magento – Authorize.net Direct Post hash validation failed

authorize.netee-1.13enterprise-1.13paymentpayment-gateway

I have Authorize.net Direct Post enabled on Magento 1.13 with the following settings:

Payment Action: Authorize Only
Test Mode: No
Gateway URL: https://test.authorize.net/gateway/transact.dll

During checkout, after entering test credit card information and clicking "Place Order"

I get a pop up alert saying:

"Response hash validation failed. Transaction declined."

What is causing this and how do I fix it?

Best Answer

As defined in app/code/core/Mage/Authorizenet/Model/Directpost.php, this exception is thrown if any portion of the below evaluates as false:

if (!$this->getConfigData('trans_md5') || !$this->getConfigData('login') ||
    !$response->isValidHash($this->getConfigData('trans_md5'), $this->getConfigData('login'))
) {
    Mage::throwException(
        Mage::helper('authorizenet')->__('Response hash validation failed. Transaction declined.')
    );
}

So, it's one of three things:

  • You have no trans_md5 defined in the config tree payment/authorizenet_directpost/trans_md5

  • There is no login defined in payment/authorizenet_directpost/login

  • The method isValidHash is returning false

The method isValidHash returns false because there is an issue with either the generated hash (e.g. your API Login/Key are wrong, generate a new one and re-enter) or the amount of the transaction somehow differs between Authorize and your system.

The latter is less likely, but because generateHash in Mage_Authorizenet_Model_Directpost_Response uses the transaction amount as part of the hash, it's a potential factor here.

Related Topic