cancel
Showing results for 
Search instead for 
Did you mean: 

How to define new command for Paymeny Gatway Command Pool?

How to define new command for Paymeny Gatway Command Pool?

We ware using go cardles payment module, which is using one payment gateway pool command "initialize". Payment work fine, but we need to extend this payment and register Vault.

Registration of new Vault was not a problem. In config.xml and di.xml we defined new Facade and we can purchase using it.

config.xml

            <gocardless_cc_vault>
                <active>1</active>
                <model>GoCardlessAccountVaultFacade</model>
                <title>Stored Token GoCardless</title>
            </gocardless_cc_vault>

di.xml
    <virtualType name="GoCardlessAccountVaultFacade" type="Magento\Vault\Model\Method\Vault">
        <arguments>
            <argument name="config" xsi:type="object">GoCardlessVaultPaymentConfig</argument>
            <argument name="valueHandlerPool" xsi:type="object">GoCardlessVaultPaymentValueHandlerPool</argument>
            <argument name="vaultProvider" xsi:type="object">GoCardlessFacade</argument>
            <argument name="code" xsi:type="const">Ecomnova\GoCardlessVault\Model\Ui\ConfigProvider::CC_VAULT_CODE</argument>
        </arguments>
    </virtualType>

For vaultProvider I use orginal GoCardlessFacade object  on same way as Braintree module did.
see orginal Go Cardless Facade object

    <virtualType name="GoCardlessFacade" type="Magento\Payment\Model\Method\Adapter">
        <arguments>
            <argument name="code" xsi:type="const">Laurent35240\GoCardless\Model\Ui\ConfigProvider::CODE</argument>
            <argument name="formBlockType" xsi:type="string">Laurent35240\GoCardless\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">Laurent35240\GoCardless\Block\Info</argument>
            <argument name="valueHandlerPool" xsi:type="object">GoCardlessValueHandlerPool</argument>
            <argument name="validatorPool" xsi:type="object">GoCardlessValidatorPool</argument>
            <argument name="commandPool" xsi:type="object">GoCardlessCommandPool</argument>
        </arguments>
    </virtualType>

and command pool looks like

    <virtualType name="GoCardlessCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="initialize" xsi:type="string">Laurent35240\GoCardless\Gateway\Command\InitializeCommand</item>
            </argument>
        </arguments>
    </virtualType>  

The object is using only initialize command. What I want is to register more commands in gateway command pool and customize responses in handler like Braintree does.

So I tried like this:

<pre>
    <virtualType name="GoCardlessCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="initialize" xsi:type="string">Laurent35240\GoCardless\Gateway\Command\InitializeCommand</item>
                <item name="vault_authorize" xsi:type="string">GoCardlessVaultAuthorizeCommand</item>
            </argument>
        </arguments>
    </virtualType>
    

    <virtualType name="GoCardlessVaultAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
        <arguments>
            <argument name="handler" xsi:type="object">GoCardlessAuthorizationHandler</argument>
          </arguments>
    </virtualType>
    
    <virtualType name="GoCardlessAuthorizationHandler" type="Magento\Payment\Gateway\Response\HandlerChain">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="card_details" xsi:type="string">Ecomnova\GoCardlessVault\Gateway\Response\TokenDetailsHandler</item>
            </argument>
        </arguments>
    </virtualType>
    
</pre>

but the class and config that I created  is never called, no errors present in logs. And I not see what I missing here.
I followed intruction how to add new valut method from here:
https://devdocs.magento.com/guides/v2.2/payments-integrations/vault/vault-di.html