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>
1 REPLY 1

Re: How complete my payment gateway - redirect user to external website

Hello @deanvg90003cdf 

 

To redirect a user to an external website for payment in Magento 2, you will need to create a payment method module and configure it to redirect the user to the external website. Here are the general steps you can follow:

  • Create a new payment method module in Magento 2. You can refer to the official Magento 2 documentation on creating a payment method module for detailed instructions.
  • In the module's config.xml file, specify the URL of the external payment gateway as the redirect_url.
  • In the module's controller, write the logic to redirect the user to the external payment gateway. You can use the Magento\Framework\Controller\Result\Redirect class to create a redirect response.
  • In the module's view/frontend/templates/payment/form.phtml file, add a form with a button that triggers the redirect to the external payment gateway.
  • Enable the payment method in the Magento 2 admin panel and configure any other settings required by the payment gateway.

Once you have completed these steps, when a customer selects the payment method you created, they will be redirected to the external payment gateway to complete the payment process. After the payment is completed, the customer will be redirected back to your Magento 2 store.

 

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9