【问题标题】:Magento 2 Place order before sending to Payment Gateway?Magento 2 在发送到支付网关之前下订单?
【发布时间】:2017-08-16 18:35:48
【问题描述】:

我正在开发一个支付网关,通过将浏览器重定向到银行网站来完成支付,支付将在那里完成,成功后将被重定向回网站

我可以使用付款渲染器中的 JavaScript 代码成功重定向,但问题是订单将在重定向之前不会下达到银行

如何在将用户发送到银行之前下订单并获取Order_ID

以下是将用户重定向到处理重定向的特定控制器的 js 代码

        continueToMellat: function () {

                //update payment method information if additional data was changed

                $.mage.redirect(url.build('redirect/redirect'));
                this.selectPaymentMethod();
                setPaymentMethodAction(this.messageContainer);
                return false;

        }

谢谢

【问题讨论】:

  • 能否提供模块链接或源代码

标签: redirect payment magento2


【解决方案1】:

通过将代码更改为以下代码,我可以在重定向之前下订单,这将在发送到支付网关之前下订单 我现在正在尝试获取用户刚刚订购的订单 ID

continueToMellat: function () {


                if (this.validate() && additionalValidators.validate()) {
                this.isPlaceOrderActionAllowed(false);

                this.getPlaceOrderDeferredObject()
                    .fail(
                        function () {
                            self.isPlaceOrderActionAllowed(true);
                        }
                    ).done(
                        function () {
                            self.afterPlaceOrder();

                            if (self.redirectAfterPlaceOrder) {
                                redirectOnSuccessAction.execute();
                            }
                        }
                    );
            }
                //update payment method information if additional data was changed

                $.mage.redirect(url.build('redirect/redirect'));
                this.selectPaymentMethod();
                setPaymentMethodAction(this.messageContainer);
                return false;

        }

【讨论】:

    【解决方案2】:

    您可以使用购物车 ID:getQuoteId() 就像在

    中使用的一样
    //vendor/magento/module-checkout/view/frontend/web/js/action/get-payment-information.js
    
    
    define([
    'jquery',
    'Magento_Checkout/js/model/quote',
    ...
    ], function ($, quote, ...) {
    'use strict';
    
    return function (deferred, messageContainer) {
        var serviceUrl;
    
        deferred = deferred || $.Deferred();
    
        /**
         * Checkout for guest and registered customer.
         */
        if (!customer.isLoggedIn()) {
            serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/payment-information', {
                cartId: quote.getQuoteId()
            });
        }
    

    虽然订单增量 ID 可以在传递给客户端处理之前在服务器中保留:

    __construct(\Magento\Checkout\Model\Session $checkoutSession){
        $this->quote = $checkoutSession->getQuote();
    }
    
    ...
    
    $this->quote->reserveOrderId();
    $orderId = $this->quote->getReservedOrderId();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 2017-04-22
      • 2022-01-08
      • 2015-01-19
      • 2016-05-22
      • 2013-12-07
      相关资源
      最近更新 更多