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#131
):
(The code sample is from Magento Open Source v2.1. 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.