Nopcommerce - 自定义付款方式的PostProcessPayment不会重定向到付款网关URL

问题描述 投票:0回答:3

我正在为Nopcommerce网站开发自定义付款方式插件。这是支付处理器类代码:

public class CODBookingPaymentProcessor : BasePlugin, IPaymentMethod
{
    private IShoppingCartService _shoppingCartService;
    private IOrderService _orderService;
    private IHttpContextAccessor _httpContextAccessor;

    #region Ctor
    public CODBookingPaymentProcessor(IShoppingCartService shoppingCartService,
        IOrderService orderService, IHttpContextAccessor httpContextAccessor)
    {
        this._shoppingCartService = shoppingCartService;
        this._orderService = orderService;
        this._httpContextAccessor = httpContextAccessor;
    }
    #endregion

    ~~~~~~~~~~~~~~~~ SOME CODE ~~~~~~~~~~~~~~~~~~~~~
public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
    {
          // some code
          string url = protocol + host + "/" + "PaymentCODBooking/ProcessInternetPayment";

        _httpContextAccessor.HttpContext.Response.Redirect(url);
    }

断点即将到来,url正在形成。但是当在Checkout页面上点击url按钮时,页面不会重定向到CONFIRM。它只是留在页面上或有时清空推车。这意味着无需前往支付网关即可创建订单。

UPDATE

重定向也不适用于ConfirmOrderCheckoutController行动。

if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
{
    //redirection or POST has been done in PostProcessPayment
    //return Content("Redirected");

    return Redirect("http://localhost:15536/PaymentCODBooking/ProcessInternetPayment");
}
c# asp.net .net asp.net-mvc nopcommerce
3个回答
1
投票

重定向必须是动作结果。例如在控制器的动作中,我们这样写:

return Redirect("http://www.google.com");

没有return关键字,它不会重定向。

要从插件的控制器重定向,请查看开箱即用的PayPalStandard插件的\ Plugins \ Nop.Plugin.Payments.PayPalStandard \ Controllers \ PaymentPayPalStandardController.cs类中的类似实现。


1
投票

如果您正在尝试开发插件,那么不要更改nopCommerce源代码会好得多。您可以在插件中执行重定向,不要更改ConfirmOrderCheckoutController动作。将您的代码更改为:

public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
{
      // some code
      string url = protocol + host + "/" + "PaymentCODBooking/ProcessInternetPayment";

    _httpContextAccessor.HttpContext.Response.Redirect(url);
    return;
}

你可以在ConfirmOrder动作中找到这些线。在PostProcessPayment之后,应用程序将在这里丰富。重定向在这里执行:

if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
{
    //redirection or POST has been done in PostProcessPayment
    return Content("Redirected");
}

0
投票

谢谢大家的帮助。你的答案给了我一些提示并找到了问题。问题是我忘了设置public PaymentMethodType PaymentMethodType => PaymentMethodType.Redirection;。它被设置为Standard导致了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.