Edit in GitHubLog an issue

Gateway Client

Gateway Client is a component of the Adobe Commerce 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:

Example

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

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

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:

Copied to your clipboard
public function create(array $request)
{
return $this->transferBuilder
->setBody($request)
->build();
}

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.

Copied to your clipboard
public function create(array $request)
{
return $this->transferBuilder
->setMethod(Curl::POST)
->setHeaders(['Content-Type' => 'application/json'])
->setBody(json_encode($request, JSON_UNESCAPED_SLASHES))
->setAuthUsername($this->getApiKey())
->setAuthPassword($this->getApiPassword())
->setUri($this->getUrl())
->build();
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.