Domanda

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.

È stato utile?

Soluzione

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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top