Redirect 重定向支付网关magento2
我是Magento的新手,我正在magento2.1中实现一种自定义付款方法,但我完全迷路了。所需的信息流如下:Redirect 重定向支付网关magento2,redirect,post,payment-gateway,magento2,payment-method,Redirect,Post,Payment Gateway,Magento2,Payment Method,我是Magento的新手,我正在magento2.1中实现一种自定义付款方法,但我完全迷路了。所需的信息流如下: 客户进入结帐并输入所有信息,然后进入付款方式,在那里他将选择我的自定义方式并按下“下订单”按钮 按下按钮后,我必须捕获订单、产品、金额、发货地址的信息,并添加其他信息,如(“签名”-用于验证的哈希、“urlResponse”和“urlConfirmation”等),然后我需要在Post请求中将这些参数发送到网关提供商URL。我不需要进行任何形式的验证,只需抓取数据,添加更多数据并发送
<?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>
供应商\PayU\Model\Payment\Request\Capture
供应商\PayU\Model\Payment\Command\CaptureGateway
供应商\PayU\Model\Payment::方法\u代码
PayUValueHandlerPool
PayUValidatorPool
PayUCommandPool
Magento\Payment\Block\Form\Cc
Magento\Payment\Block\Info\Cc
供应商\PayU\Model\Payment::方法\u代码
帕尤孔菲格
PayUConfigValueHandler
帕尤孔菲格
乡村验证器
PayUGlobalValidator
供应商\PayU\Model\Payment\Request\Capture
供应商\PayU\Model\Payment\Response\Capture
供应商\PayU\Gateway\Http\TransferFactory
PayUCaptureGatewayCommand
供应商\PayU\Gateway\Command\CommandPool
在Vendor/PayU/Model/Payment.php中,我有:
<?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
]);
}
}
首先,看看magento 2模块的官方示例。
我知道你不应该有真正的付款模式。您刚刚在di.xml中创建了支付模型。按代码:
<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>
供应商\PayU\Model\Payment::方法\u代码
PayUValueHandlerPool
PayUValidatorPool
PayUCommandPool
Magento\Payment\Block\Form\Cc
Magento\Payment\Block\Info\Cc
PayUPaymentMethodAdapter是您的支付模型,它包含所有需要的数据,您只需放置所有需要的内容(命令、验证程序等),Magento将自动调用。因此,Magento\Payment\Model\Method\Adapter就是包含所有支付模块功能的Facade。Magento 2团队将命令设计模式用于所有支付操作,如(作废、捕获、授权)。您应该识别适当的命令,Magento\Payment\Model\Method\Adapter将自动调用这些命令。请检查magento示例付款方式。在我的for magento 2中,我已通过以下方式将magento付款页面重定向到付款服务提供商或magento“checkout success”页面:
谢谢您的回复。我一直在看你推荐给我的例子,但我没能让它起作用。它在下一个链接中向我抛出错误:。我认为问题出在包含xsi:type=“const”的参数中,因为如果我对这些行(所有virtualType)进行注释,则页面加载不会出现问题(代码的url为:)。你知道有什么问题吗?谢谢。你能给我看一下这个类吗?我是说\Vender\PayUGateway\Model\ConfigProvider。你用固定支付方法代码创建了这个类吗?请同时验证命名空间。似乎magento找不到常数。请确保所有内容都正确。这是我的ConfigProvider.php:我已经检查了名称空间。您可能会看到,为了提问的目的,我在两个屏幕截图中都更改了供应商名称,但我在“工作”版本的两个文件中都正确写入了它们。我也面临着同样的问题。没有得到任何解决方案。你能帮我吗?你在做什么?你到底需要做什么?