Gateway Client

Gateway Client is a component of the Magento payment gateway that transfers the payload to the payment provider and gets the response.

Basic interface

The basic interface for a gateway client is Magento\Payment\Gateway\Http\ClientInterface.

A gateway client receives a called Transfer object. The client may be configured with response converter using dependency injection.

Default implementations

The following gateway client implementations can be used out-of-the-box:


Following is the illustration of how a Zend client can be added in di.xml:

<virtualType name="HtmlConverterZendClient" type="Magento\Payment\Gateway\Http\Client\Zend">
        <argument name="converter" xsi:type="object">Magento\Payment\Gateway\Http\Converter\HtmlFormConverter</argument>
        <argument name="logger" xsi:type="object">CustomLogger</argument>

Transfer Factory

Transfer Factory allows to create transfer object with all data from request builders. This object is then used by Gateway Client to process requests to payment processor.

Transfer Factory uses Transfer Builder to set required request parameters.

The basic Transfer Factory interface is Magento\Payment\Gateway\Http\TransferFactoryInterface.

The similar example of factory might looks like this:

 public function create(array $request)
    return $this->transferBuilder

In this example transfer factory simply sets request data using Transfer Builder and returns the created object.

Following is an example of a more complicated behavior. Here transfer factory sets all required data to process requests using API credentials and all data is sent in JSON format.

public function create(array $request)
    return $this->transferBuilder
        ->setHeaders(['Content-Type' => 'application/json'])
        ->setBody(json_encode($request, JSON_UNESCAPED_SLASHES))