Redirect to third party payment gateway using POST authentication

Redirect to third party payment gateway using POST authentication

September 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Redirect to third party payment gateway using POST authentication

Redirecting to Third Party Payment Gateway using POST Authentication in Magento

Authentication is a crucial aspect when integrating external payment gateways into your e-commerce platform. In this post, we’ll guide you through the process of setting up POST authentication for redirection to a third-party payment gateway in Magento.

Understanding the Problem

You’ve implemented a custom payment extension following the excellent tutorial at Junaid Bhura’s blog. However, you’re facing challenges in implementing the POST values needed for authentication and ensuring the gateway receives the order in the correct format.

Step-by-Step Solution

1. Configure Payment Method Settings

First, ensure your payment method settings are correctly configured in Magento’s System > Configuration section under Sales > Payment Methods. Set up the required fields such as API Login, Secret Key (Encrypted), and any additional parameters the gateway requires.

2. Implement POST Authentication in PaymentController.php

Open your custom PaymentController.php file located at app/code/local/Myname/Mygateway/controllers/. You’ll see the three main actions: redirectAction(), responseAction(), and cancelAction().

In the responseAction() function, you need to implement the required authentication checks provided by the gateway. This usually involves validating a checksum or other security measures.

Here’s an example of how you might implement this using PHP and Mage_Core_Helper_Data for handling encrypted data:

public function responseAction()
{
    if ($this->getRequest()->isPost()) {
        $orderId = $this->getRequest()->getParam('orderid');
        $grandTotal = $this->getRequest()->getParam('grandtotal');

        // Decrypt the secret key provided by the gateway
        $secretKey = Mage::helper('core')->decrypt($this->_configSecretKey);

        // Validate the response using the gateway's authentication checks
        if (validateGatewayResponse($orderId, $grandTotal, $secretKey)) {
            //... Process successful order
        } else {
            //... Process failed order
        }
    } else {
        Mage_Core_Controller_Varien_Action::_redirect('');
    }
}

3. Ensure Correct Order Format and POST Values

In your redirect.phtml form, double-check that you’re passing the correct hidden values to the gateway’s URL:

<form name="mygatewayform" method="post"
action="http://www.gateway.com/the_url_they_gave_me">
    <input type="hidden" name="orderid" value="<?php echo $orderId; ?>">
    <input type="hidden" name="grandtotal" value="<?php echo $_order->getBaseGrandTotal(); ?>">
</form>

Ensure the gateway’s URL is correct and all required hidden fields are populated with the appropriate Magento data.

4. Test Order Submission

Run a test order to see if the gateway receives your order data correctly via IP logging or other debugging tools they provide. If issues persist, double-check your configuration settings, authentication checks in PaymentController.php, and hidden field values in redirect.phtml.

Best Practices for Payment Gateway Integration

  • Always validate the gateway’s response using their provided authentication methods to prevent unauthorized access.
  • Keep sensitive data such as API keys encrypted both in Magento’s configuration settings and when passing it around your codebase.
  • Regularly test order submissions, and monitor gateway logs for any errors or issues.
  • Stay updated with the latest Magento releases and security patches to ensure your e-commerce platform remains secure.

Conclusion

Integrating third-party payment gateways into Magento requires careful setup of authentication methods in your custom PaymentController.php file. Ensuring correct configuration settings, implementing proper validation checks, and passing all required data correctly is key to a successful integration.

Remember, always prioritize security when handling sensitive customer data such as credit card information. Regularly update your platform and monitor gateway logs for any issues.

We hope this guide helps resolve the challenges you’ve been facing with integrating external payment gateways into Magento. If further assistance is needed or if you’d like to explore how our services at Laravel Company can help with your e-commerce projects, please don’t hesitate to reach out!

API Extensions Configuration Orders

Our network