Magento Error Message at Checkout

Magento Error Message at Checkout

September 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Error Message at Checkout

Displaying Error Messages at Checkout in Magento

In your custom payment extension for Magento, you’re facing an issue where error messages are not displayed immediately when using the Mage::throwException method within the authorize function. This leads to a poor user experience because the customer is redirected without any feedback about what went wrong.

Understanding the Current Behavior

When you call Mage::throwException($return), it indeed prevents the next page from loading and interrupts the checkout process. However, Magento’s default error handling does not display this exception message at the current step of the checkout process. It only adds an error to the session, which is then displayed on the subsequent page.

The addError method works as expected in other validation functions like validate because it appends the error to the session and redirection is handled differently there. But the authorize function has a unique flow that requires manual intervention to display the message immediately.

Displaying Error Messages Immediately

To solve this issue, you can override the default behavior of Magento’s checkout process using an event observer. Here’s how:

  1. Create a custom module: If you don’t have one already, create a new module in your Magento installation. You can follow our guide on creating custom modules for a detailed walkthrough.

  2. Configure the observer: In your module’s etc folder, create an XML file named config.xml. Inside this file, define an event observer that listens to the checkout_onepage_controller_success_action event:

<events>
    <checkout_onepage_controller_success_action>
        <observers>
            <your_module_model_checkout_success>
                <type>singleton</type>
                <class>Your_Module_Model_Checkout_SuccessObserver</class>
                <method>processSuccess</method>
            </your_module_model_checkout_success>
        </observers>
    </checkout_onepage_controller_success_action>
</events>

Replace your_module with the actual name of your module.

  1. Create the observer class: In your module’s Model folder, create a new file named Checkout_SuccessObserver.php. Implement the processSuccess method as follows:
public function processSuccess($observer)
{
    $request = $observer->getControllerAction()->getRequest();
    if ($request->getParam('error')) {
        Mage::app()->getSession()->addError($request->getParam('error'));
    }
}

In this observer, we check if the request contains an error parameter. If it does, we add that error message to the session using Mage::app()->getSession()->addError($message);.

  1. Passing Error Parameters

To pass the error message from your custom payment extension to the checkout success page, you can set it as a request parameter in your authorize function:

public function authorize(Varien_Object $payment, $amount)
{
    //... (previous code)

    if(strlen($error) > 0)
    {
        Mage::app()->getRequest()->setParam('error', $error);
        Mage::throwException($error);
    }

    return $this;
}

Now, when an error occurs in the authorize function, it sets the error parameter in the request. Our observer then picks up this parameter and adds the message to the session.

Conclusion

Displaying error messages immediately at the checkout step requires overriding Magento’s default behavior using event observers. By setting the error message as a request parameter and processing it with an observer, you can provide real-time feedback to your customers without interrupting their shopping experience.

Remember to properly test this solution in your specific Magento version and module structure. If you encounter any issues or need further assistance, feel free to explore our other Magento tutorials for more advanced topics and troubleshooting guides.

Happy coding!

Checkout Extensions Configuration Customers

Our network