The Payment Provider Gateway documentation uses the Magento 2.3.x version of the Braintree module as a reference application. The Braintree module was removed in Magento 2.4.0. The concepts described in this guide are still applicable to Magento 2.4.0, but the code samples are not supported.
This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

Gateway Command

Gateway Command is a component of the Magento payment gateway that takes the payload required for a particular payment provider and sends, receives, and processes the provider’s response. For each operation (authorization, capture and so on) of a certain payment provider - a separate gateway command is added.

Interface

Basic interface for a gateway command is \Magento\Payment\Gateway\CommandInterface. It implements the Command design pattern.

Basic implementation

The \Magento\Payment\Gateway\Command\GatewayCommand class is the default CommandInterface implementation. It allows performing most of the operations implemented in the Magento sales management.

Adding gateway commands

For each particular integration with a payment provider, gateway commands are added using virtual types in dependency injection (DI) configuration.

In the following example the BraintreeAuthorizeCommand gateway command is added. The command implements the “authorize” operation for the Braintree payment provider (app/code/Magento/Braintree/etc/di.xml):

1
2
3
4
5
6
7
8
9
10
<virtualType name="BraintreeAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
    <arguments>
        <argument name="requestBuilder" xsi:type="object">BraintreeAuthorizeRequest</argument>
        <argument name="transferFactory" xsi:type="object">Magento\Braintree\Gateway\Http\TransferFactory</argument>
        <argument name="client" xsi:type="object">Magento\Braintree\Gateway\Http\Client\TransactionSale</argument>
        <argument name="handler" xsi:type="object">BraintreeAuthorizationHandler</argument>
        <argument name="validator" xsi:type="object">Magento\Braintree\Gateway\Validator\ResponseValidator</argument>
        <argument name="errorMessageMapper" xsi:type="object">Magento\Braintree\Gateway\ErrorMapper\VirtualErrorMessageMapper</argument>
    </arguments>
</virtualType>

(The code sample is from Magento Open Source v2.2. Although the payment provider gateway was added in v2.0, the particular default implementation using the gateway were added in v2.1.)

A gateway command must be configured with the following arguments:

  • requestBuilder: request builder, builds an array of provider-specific arguments using the order information.

  • transferFactory: transfer factory, creates transfer object from request data, which will be used by Gateway Client to process requests. For details see Gateway Client #Transfer Factory

  • client: gateway client, takes the provider-specific arguments and performs a low-level call to the provider.

Optional arguments :

  • handler: response handler, changes the order and payment status depending on the payment provider response.
  • validator: response validator, validates the provider response.