[英]Nopcommerce - Custom Payment Method's PostProcessPayment not redirecting to Payment Gateway URL
I am developing a custom payment method plugin for a Nopcommerce site.我正在为 Nopcommerce 网站开发自定义支付方式插件。 This is the the payment processor class code:
这是支付处理器类代码:
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);
}
The breakpoint is coming at last line and url
is forming correctly.断点出现在最后一行并且
url
正确形成。 But the page is not redirecting to the url
when CONFIRM
button is clicked on Checkout page.但是当在结帐页面上单击
CONFIRM
按钮时,页面不会重定向到url
。 It just stays on the page or sometimes empties the cart.它只是停留在页面上或有时会清空购物车。 It means order is being created without going to payment gateway.
这意味着正在创建订单而无需转到支付网关。
The redirect is also not working in ConfirmOrder
action of CheckoutController
.重定向在
CheckoutController
的ConfirmOrder
操作中也不起作用。
if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
{
//redirection or POST has been done in PostProcessPayment
//return Content("Redirected");
return Redirect("http://localhost:15536/PaymentCODBooking/ProcessInternetPayment");
}
The redirect has to be an action result.重定向必须是操作结果。 For example in controller's action we write like this:
例如在控制器的动作中我们这样写:
return Redirect("http://www.google.com");
Without the return
keyword it would not redirect.如果没有
return
关键字,它就不会重定向。
To redirect from the controller of a plugin check out the similar implementation in the \Plugins\Nop.Plugin.Payments.PayPalStandard\Controllers\PaymentPayPalStandardController.cs class of the PayPalStandard plugin that comes out of the box要从插件的控制器重定向,请检查开箱即用的PayPalStandard插件的\Plugins\Nop.Plugin.Payments.PayPalStandard\Controllers\PaymentPayPalStandardController.cs类中的类似实现
If you are trying to develop a plugin, it's so much better to not change the nopCommerce source code.如果您正在尝试开发插件,最好不要更改 nopCommerce 源代码。 You can perform the redirection in the plugin itself, don't change the
ConfirmOrder
action of CheckoutController
.您可以在插件本身中执行重定向,不要更改
CheckoutController
的ConfirmOrder
操作。 Change your code to this:将您的代码更改为:
public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
{
// some code
string url = protocol + host + "/" + "PaymentCODBooking/ProcessInternetPayment";
_httpContextAccessor.HttpContext.Response.Redirect(url);
return;
}
you can find these lines in ConfirmOrder
action.您可以在
ConfirmOrder
操作中找到这些行。 The application will rich here after the PostProcessPayment
.在
PostProcessPayment
之后,应用程序将在这里丰富。 The redirection performs here:重定向在这里执行:
if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
{
//redirection or POST has been done in PostProcessPayment
return Content("Redirected");
}
Thank you everyone for help.谢谢大家的帮助。 Your answers gave me some hint and find the issue.
您的回答给了我一些提示并找到了问题所在。 The issue was that I forgot to set
public PaymentMethodType PaymentMethodType => PaymentMethodType.Redirection;
问题是我忘记设置
public PaymentMethodType PaymentMethodType => PaymentMethodType.Redirection;
. . It was set to
Standard
which caused the issue.它被设置为导致问题的
Standard
。
Changes PaymentMethodType to PaymentMethodType.Redirection It will work将 PaymentMethodType 更改为 PaymentMethodType.Redirection 它会起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.