7

I'm working on custom payment system in which I am using Magento2 default vault functionality. Everything is working fine when if I replace below code in file Magento\Vault\Model\Method\Vault into authorize() or capture() methods.

$commandExecutor = $this->commandManagerPool->get(
        $this->getVaultProvider()->getCode()
    );

to

$commandExecutor = $this->commandManagerPool->get(
        "method_code"
    );

My question is how can I assign vaultprovider? so I can get method code directly form vaultprovider object.

Note: I'm not placing an order in Magento, I just authorize or capture amount from third party payment gateway system(paypal pro) in my custom module.

1
8

After some R&D I got the solution myself.

First I created a class in my module:

namespace VendorName\ModuleName\Model\Payment;
class Payflowpro 
{
 public function __construct(
    \Magento\Vault\Model\VaultPaymentInterface $vault
) {
   $this->vault = $vault

}
  public function mymethod($payment,$amount)
  {
    $this->vault->authorize($payment,$amount);
  }
}

Here I passed an object of Vault Class.

In second step 1 created di.xml in my module and write below code:

<type name="VendorName\ModuleName\Model\Payment\Payflowpro">
    <arguments>
        <argument name="vault" xsi:type="object">PayflowProCreditCardVaultFacade</argument>
    </arguments>
 </type>  

here type is used for assigning object value which I passed in my module class

Now last steps I creates VirtualType in my di.xml for assigning provider to Vault Class.

 <virtualType name="PayflowProCreditCardVaultFacade" type="Magento\Vault\Model\Method\Vault">
    <arguments>
        <argument name="config" xsi:type="object">PayflowProVaultPaymentConfig</argument>
        <argument name="valueHandlerPool" xsi:type="object">PayflowProVaultPaymentValueHandlerPool</argument>
        <argument name="vaultProvider" xsi:type="object">Magento\Paypal\Model\Payflow\Transparent</argument>
        <argument name="code" xsi:type="const">Magento\Paypal\Model\Payflow\Transparent::CC_VAULT_CODE</argument>
    </arguments>
</virtualType>
6
  • Nice solutions. May 31 '17 at 9:39
  • Good catch @Yogesh :) +1 from me
    – Keyur Shah
    Jun 1 '17 at 13:22
  • @yogesh, Can you provide info, how can I use vault for my custom payment method?
    – Charlie
    Jan 22 '18 at 5:44
  • @Keyur I am trying to add Vault to the payfort module by following the official doc devdocs.magento.com/guides/v2.1/payments-integrations/vault/…, but i cannot get the dependency injection correct. I tried to copy the di.xml from the braintree module but it is also very confusing. the code inside the VaultDetailsHandler which is used as handler is not getting executed. What is your opinion about using sales_order_payment_save_after or checkout_onepage_controller_success_action event observers to add token to vault. Is there any good example available ? Feb 5 '19 at 12:47
  • @Yogesh : Does the Magento_Vault functionalty work with custom payment method? or there is limitation like braintree & paypal. Jan 31 '20 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.