I am developing a custom payment method plugin for a Nopcommerce site. 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. But the page is not redirecting to the url
when CONFIRM
button is clicked on Checkout page. 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
.
if (_webHelper.IsRequestBeingRedirected || _webHelper.IsPostBeingDone)
{
//redirection or POST has been done in PostProcessPayment
//return Content("Redirected");
return Redirect("http://localhost:15536/PaymentCODBooking/ProcessInternetPayment");
}
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;
. It was set to Standard
which caused the issue.