首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重定向支付网关magento2

重定向支付网关magento2
EN

Stack Overflow用户
提问于 2016-10-23 00:30:04
回答 2查看 3.5K关注 0票数 3

我是Magento的新手,我正在实现magento2.1中的自定义支付方法,但我完全迷失了方向。所需的信息流动情况如下:

  1. 客户去结帐,输入所有的信息,并进入付款方法,他将选择我的定制方法,并按‘地点订购’按钮。
  2. 按下按钮后,我必须捕获订单、产品、数量、发货地址的信息,并添加其他信息,如“签名”(用于验证的散列)、“urlResponse”和“urlConfirmation”以及其他一些信息),然后我需要在Post请求中将这些参数发送到网关提供者URL。我不需要做任何形式的验证,只需获取数据,添加更多,并发送它。

在阅读了Max Pronko的教程之后

https://www.maxpronko.com/blog/magento-2-payment-gateway-api

(由于缺乏点数,我无法复制另一个链接,但在这个链接的末尾有另一个链接的引用)。

我试着去实现它,但我没有运气。据我所知,按下“Place”按钮后,请求将发送到一个捕获方法,在该方法中,我可以执行必要的逻辑,然后创建一个TransferObject,然后发送它(如何发送?)。

这就是我的结构:

自定义支付文件结构

在Vendor/PayU/etc/前端/di.xml中,我有:

代码语言:javascript
复制
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Payment\Gateway\Command\CommandPoolInterface" type="Magento\Payment\Gateway\Command\CommandPool" />

    <virtualType name="Vendor\PayU\Model\Payment\Command\CaptureGateway" type="Magento\Payment\Gateway\Command\GatewayCommand">
        <arguments>
            <argument name="requestBuilder" xsi:type="object">Vendor\PayU\Model\Payment\Request\Capture</argument>
        </arguments>
    </virtualType>

    <virtualType name="Vendor\PayU\Gateway\Command\CommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="capture" xsi:type="string">Vendor\PayU\Model\Payment\Command\CaptureGateway</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUPaymentMethodAdapter" type="Magento\Payment\Model\Method\Adapter">
        <arguments>
            <argument name="code" xsi:type="const">Vendor\PayU\Model\Payment::METHOD_CODE</argument>
            <argument name="valueHandlerPool" xsi:type="object">PayUValueHandlerPool</argument>
            <argument name="validatorPool" xsi:type="object">PayUValidatorPool</argument>
            <argument name="commandPool" xsi:type="object">PayUCommandPool</argument>
            <argument name="formBlockType" xsi:type="object">Magento\Payment\Block\Form\Cc</argument>
            <argument name="infoBlockType" xsi:type="object">Magento\Payment\Block\Info\Cc</argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="const">Vendor\PayU\Model\Payment::METHOD_CODE</argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">PayUConfig</argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">PayUConfigValueHandler</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="CountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
        <arguments>
            <argument name="config" xsi:type="object">PayUConfig</argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUGlobalValidator" type="Magento\Payment\Gateway\Validator\ValidatorComposite">
        <arguments>
            <argument name="validators" xsi:type="array">
                <item name="country" xsi:type="string">CountryValidator</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
        <arguments>
            <argument name="validators" xsi:type="array">
                <item name="global" xsi:type="string">PayUGlobalValidator</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUCaptureGatewayCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
        <arguments>
            <argument name="requestBuilder" xsi:type="object">Vendor\PayU\Model\Payment\Request\Capture</argument>
            <argument name="handler" xsi:type="object">Vendor\PayU\Model\Payment\Response\Capture</argument>
            <argument name="transferFactory" xsi:type="object">Vendor\PayU\Gateway\Http\TransferFactory</argument>
        </arguments>
    </virtualType>

    <virtualType name="PayUCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="capture" xsi:type="string">PayUCaptureGatewayCommand</item>
            </argument>
        </arguments>
    </virtualType>

    <type name="Vendor\PayU\Model\Payment">
        <arguments>
            <argument name="commandPool" xsi:type="object">Vendor\PayU\Gateway\Command\CommandPool</argument>
        </arguments>
    </type>
</config>

在Vendor/PayU/Model/Payment.php中,我有:

代码语言:javascript
复制
<?php

namespace Vendor\PayU\Model;

use Magento\Payment\Model\InfoInterface;
use Magento\Payment\Gateway\Command\CommandPoolInterface;
use Magento\Payment\Gateway\CommandInterface;

class Payment implements MethodInterface, PaymentMethodInterface
{
    /**
     * @var \Magento\Payment\Gateway\Command\CommandPoolInterface
    */
    protected $commandPool;

    /**
     * @var CommandPoolInterface
    */
    public function __construct(CommandPoolInterface $commandPool) {
        $this->commandPool = $commandPool;
    }

    /**
     * @param InfoInterface $payment
     * @param float $amount
     * @return $this
     * @api
    */
    public function capture(InfoInterface $payment, $amount)
    {
        /** @var CommandInterface $captureGatewayCommand */
        $captureGatewayCommand = $this->commandPool->get('capture');

        $captureGatewayCommand->execute([
            'payment' => $payment,
            'amount' => $amount
        ]);
    }     
}

我是否实现了正确的类?我还需要什么文件?如果有人能给我指明正确的方向,我将不胜感激。

EN

回答 2

Stack Overflow用户

发布于 2016-10-24 09:38:02

首先,看看magento两个正式的模块样本。https://github.com/magento/magento2-samples/tree/2.1/sample-module-payment-gateway,我知道你不应该有真正的支付模式。您刚刚在di.xml中创建了支付模型。按代码:

代码语言:javascript
复制
<virtualType name="PayUPaymentMethodAdapter" type="Magento\Payment\Model\Method\Adapter">
    <arguments>
        <argument name="code" xsi:type="const">Vendor\PayU\Model\Payment::METHOD_CODE</argument>
        <argument name="valueHandlerPool" xsi:type="object">PayUValueHandlerPool</argument>
        <argument name="validatorPool" xsi:type="object">PayUValidatorPool</argument>
        <argument name="commandPool" xsi:type="object">PayUCommandPool</argument>
        <argument name="formBlockType" xsi:type="object">Magento\Payment\Block\Form\Cc</argument>
        <argument name="infoBlockType" xsi:type="object">Magento\Payment\Block\Info\Cc</argument>
    </arguments>
</virtualType>

PayUPaymentMethodAdapter是您的支付模式,它包含所有需要的数据,您应该只需放置所有需要的东西(命令、验证器等),Magento将自动调用。因此Magento\ payment \Model\Adapter只是包含所有支付模块功能的Facade。Magento 2团队使用命令设计模式来进行所有的支付操作,比如(无效、捕获、授权)。您应该确定适当的命令,Magento\Payment\Model\Adapter将自动调用它们。请检查一下magento样品的付款方法。

票数 0
EN

Stack Overflow用户

发布于 2017-09-18 11:20:23

在我的17次付款延期 for Magento 2中,我以以下方式实现了从Magento支付页面到支付服务提供商或Magento结帐成功页面的重定向:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40198418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档