I have created a payment module, following the devdocs approach by creating virtual types, request builder, transfer factory, the client (using Zend client - curl adapter) until validation handler for capture command.

The 3rd party payment gateway will redirect the customer to their own gateway page to do the debit process. Unfortunately, in the header, there is no location URL, since the 1st gateway page redirects to another page via javascript submit and adding some additional post data on the top of the post data send by the Zend client curl adapter.

After successful, the customer will be redirected back to Magento 2 store at specified URL (controller) with some response post data.

My current issues are since no location in the header, Zend client unable to do a redirect, thus I have to process the redirection to 3rd party gateway and halted the process in the middle from finishing the rest of client method placeRequest() up to response handler and validation. Now, since I have no choice but to receive the response data from the controller, I am not sure how to continue back from client up to validation and response handler.

From my gateway client, please check the comment section in the code:

namespace Afham\Fpx\Gateway\Http\Client;

use Magento\Framework\HTTP\ZendClientFactory;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\ConverterInterface;
use Magento\Payment\Gateway\Http\TransferInterface;

use Magento\Payment\Gateway\Http\ClientException;
use Psr\Log\LoggerInterface;

class TransactionSale implements ClientInterface
    protected $clientFactory;

    protected $converter;

    protected $logger;

public function __construct(
    ZendClientFactory $clientFactory,
    LoggerInterface $logger,
    ConverterInterface $converter = null
    $this->clientFactory = $clientFactory;
    $this->converter = $converter;
    $this->logger = $logger;

public function placeRequest(TransferInterface $transferObject)
    $log = [
        'request' => $transferObject->getBody(),
        'request_uri' => $transferObject->getUri()
    $result = [];
    /** @var ZendClient $client */
    $client = $this->clientFactory->create();


    switch($transferObject->getMethod()) {
        case \Zend_Http_Client::GET:
        case \Zend_Http_Client::POST:
            throw new \LogicException(
                    'Unsupported HTTP method %s',


    try {
        $response = $client->request();

        /** This is where it stops, I am planning to output the $response
            since curl returns us the html (checked from xdebug) with 
            automatic javascript redirect to another page at gateway side 
            and additional post data on the top of previous one.

            After customer done at gateway, the gateway will send back the 
            results post data to webstore (magento 2 controller). My plan is 
            to continue from here at the controller side, so that it will
            run response validation and response handler, which it will mark 
            the order to processing

        $result = $this->converter
            ? $this->converter->convert($response->getBody())
            : [$response->getBody()];
        $log['response'] = $result;
    } catch (\Zend_Http_Client_Exception $e) {
        throw new \Magento\Payment\Gateway\Http\ClientException(
    } catch (\Magento\Payment\Gateway\Http\ConverterException $e) {
        throw $e;
    } finally {

    return $result;

Please advise, I have been in a circle for days, less sleep and its catching the dateline..


UPDATE: Found the answer. I will post later when I am free. Its just me that I dont understand the command gateway flow

1 Answer 1


Generally if you are redirecting to the payment gateway page for transaction, then you need to pass two extra parameters success_url and failure_url in the form with order details like order_id, payment_ref_no, cust_name etc itself. This is the basic functionality that any payment gateway should support.

If it is not working with magento, then try the same with static html forms. If then also it is not working, then this is not an issue from your side. Check with the payment gateway about the integration document which they use to provide. They also have the sample html form pages to show a success demo from their side.

  • I actually managed to get the data response from the server and knew few ways of processing the response at the controller, doing the validation and mark the order as processed. However, I think since magento already supply us with the proper way how to do validation and response handler from the devdocs, its just that how to get back to continue from when we left the webstore (magento 2) to 3rd party gateway (right after curl_exec() at the Zend curl adapter or if from Zend Client, its $response = $client->request() ).
    – Afham
    Sep 7, 2017 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.