The Payment Provider Gateway documentation uses the Magento 2.3 (now Adobe Commerce and Magento Open Source) of the Braintree module as a reference application. The Braintree module was removed in version 2.4.0. The concepts described in this guide are still applicable to version 2.4.x, but the code samples are not supported.
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 clipboardpublic 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 clipboardpublic 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();}