cancel
Showing results for 
Search instead for 
Did you mean: 

How complete my payment gateway - redirect user to external website

How complete my payment gateway - redirect user to external website

I'm trying to make a payment gateway, this gateway is like all others with one exception.

in this gateway, after the user does the following:

  1. add items to cart

  2. got to cart

  3. start checkout

  4. select MyCustomPayment (can be selected)

  5. click pay (currently just directing to the success page)

after clicking pay, i would like to redirect the user to another url, of a payment gateway

I have Vodapay\Gateway\Command\Authorize.php

<?php

namespace Dischem\Vodapay\Gateway\Command;

use Magento\Payment\Gateway\CommandInterface;

class Authorize implements CommandInterface
{
    public function __construct()
    {
        // TODO: Implement contsturutor as needed.
    }

    public function execute(array $commandSubject)
    {
        // TODO: Get order here
        // TODO: generate redirection link here for example link could be https://example.com/orderid=1234
        // TODO: return redirection link to user
    }

}

and the following di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Dischem\Vodapay\Api\VodapayInterface" type="Dischem\Vodapay\Model\Api\Vodapay"/>
    <!-- Payment Gateway Facade -->
    <virtualType name="VodapayFacade" type="Magento\Payment\Model\Method\Adapter">
        <arguments>
            <argument name="code" xsi:type="const">Dischem\Vodapay\Model\Payment\Vodapay::METHOD_CODE</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">Magento\Payment\Block\Info</argument>
            <argument name="valueHandlerPool" xsi:type="object">VodapayValueHandlerPool</argument>
            <argument name="validatorPool" xsi:type="object">VodapayValidatorPool</argument>
            <argument name="commandPool" xsi:type="object">VodapayCommandPool</argument>
        </arguments>
    </virtualType>
    <!-- Value Handler Pool entries -->
    <virtualType name="VodapayValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">VodapayConfigValueHandler</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="VodapayConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">VodapayConfig</argument>
        </arguments>
    </virtualType>
    <!-- Validator Pool -->
    <virtualType name="VodapayValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
        <arguments>
            <argument name="validators" xsi:type="array">
                <item name="country" xsi:type="string">VodapayCountryValidator</item>
                <item name="availability" xsi:type="string">Dischem\Vodapay\Gateway\Validator\SessionValidator</item>
            </argument>
</virtualType>
<virtualType name="VodapayCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">VodapayConfig</argument>
</arguments>
</virtualType>
<!-- Command Pool entries -->
<virtualType name="VodapayCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="authorize" xsi:type="string">Dischem\Vodapay\Gateway\Command\Authorize</item>
</argument>
</arguments>
</virtualType>
<!-- Multiple use entries -->
<virtualType name="VodapayConfig" type="Magento\Payment\Gateway\Config\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Dischem\Vodapay\Model\Payment\Vodapay::METHOD_CODE</argument>
</arguments>
</virtualType>
</config>