Magento 2.1.18 is the final 2.1.x release. After June 2019, Magento 2.1.x will no longer receive security patches, quality fixes, or documentation updates.
To maintain your site's performance, security, and PCI compliance, upgrade to the latest version of Magento.

Add a payment action

For each payment action available for the payment method, you must implement the following:

Configure the command

The gateway command for the payment action must be configured in the di.xml file of your module. Conventionally, its location must be <your_module_dir>/etc/di.xml

Configure the command as described in Gateway Command.

Example: authorize payment action for Braintree

Configuring the gateway command and adding it to command pool (app/code/Magento/Braintree/etc/di.xml):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<virtualType name="BraintreeCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
    <arguments>
        <argument name="commands" xsi:type="array">
            <item name="authorize" xsi:type="string">BraintreeAuthorizeCommand</item>
        </argument>
    </arguments>
</virtualType>

<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>
    </arguments>
</virtualType>

In the command configuration we see that BraintreeAuthorizeRequest is specified as requestBuilder, that is a Let’s look closer on the requestBuilder arguments. This argument value is a list of builders, builder composite.

The BraintreeAuthorizeRequest builder contains the following builders (app/code/Magento/Braintree/etc/di.xml):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<virtualType name="BraintreeAuthorizeRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
        <arguments>
            <argument name="builders" xsi:type="array">
                <item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
                <item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
                <item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
                <item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
                <item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
                <item name="3dsecure" xsi:type="string">Magento\Braintree\Gateway\Request\ThreeDSecureDataBuilder</item>
                <item name="device_data" xsi:type="string">Magento\Braintree\Gateway\Request\KountPaymentDataBuilder</item>
                <item name="dynamic_descriptor" xsi:type="string">Magento\Braintree\Gateway\Request\DescriptorDataBuilder</item>
                <item name="store" xsi:type="string">Magento\Braintree\Gateway\Request\StoreConfigBuilder</item>
            </argument>
        </arguments>
    </virtualType>

The most important builder in this pool is Magento\Braintree\Gateway\Request\PaymentDataBuilder, the payment builder. It is responsible for the payment information part of the request.

Please see the Get payment information from frontend to backend for details about how payment information can be handled.