Redirect to external user not working in method PostProcessPayment of Payment Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 Jahre weitere
Hi,
Version 4.3
Payment Plugin
For some reason redirect to external payment link isn't working in method PostProcessPayment.
All I am trying to do is create a link for payment processing and redirect user to Payment Gateway (WorldPay) similar to whats shown in PayPalStandard plugin that comes in default installation
//Redirect to WorldPay
_httpContextAccessor.HttpContext.Response.Redirect(url);

 public class WorldPayHostedPaymentProcessor : BasePlugin, IPaymentMethod
    {
        #region Fields
        private readonly CurrencySettings _currencySettings;
        private readonly IAddressService _addressService;
        private readonly ICheckoutAttributeParser _checkoutAttributeParser;
        private readonly ICountryService _countryService;
        private readonly ICurrencyService _currencyService;
        private readonly ICustomerService _customerService;
        private readonly IGenericAttributeService _genericAttributeService;
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ILocalizationService _localizationService;
        private readonly IOrderService _orderService;
        private readonly IPaymentService _paymentService;
        private readonly IProductService _productService;
        private readonly ISettingService _settingService;
        private readonly IStateProvinceService _stateProvinceService;
        private readonly ITaxService _taxService;
        private readonly IWebHelper _webHelper;

        private readonly WorldPayHostedPaymentSettings _worldPayHostedPaymentSettings;
        #endregion

        #region Ctor
        public WorldPayHostedPaymentProcessor(CurrencySettings currencySettings,
            IAddressService addressService,
            ICheckoutAttributeParser checkoutAttributeParser,
            ICountryService countryService,
            ICurrencyService currencyService,
            ICustomerService customerService,
            IGenericAttributeService genericAttributeService,
            IHttpContextAccessor httpContextAccessor,
            ILocalizationService localizationService,
            IOrderService orderService,
            IPaymentService paymentService,
            IProductService productService,
            ISettingService settingService,
            IStateProvinceService stateProvinceService,
            ITaxService taxService,
            IWebHelper webHelper,
            WorldPayHostedPaymentSettings worldPayHostedPaymentSettings)
        {
            _currencySettings = currencySettings;
            _addressService = addressService;
            _checkoutAttributeParser = checkoutAttributeParser;
            _countryService = countryService;
            _currencyService = currencyService;
            _customerService = customerService;
            _genericAttributeService = genericAttributeService;
            _httpContextAccessor = httpContextAccessor;
            _localizationService = localizationService;
            _orderService = orderService;
            _paymentService = paymentService;
            _productService = productService;
            _settingService = settingService;
            _stateProvinceService = stateProvinceService;
            _taxService = taxService;
            _webHelper = webHelper;
            _worldPayHostedPaymentSettings = worldPayHostedPaymentSettings;
        }
        #endregion


/// <summary>
        /// This method is invoked right after a customer places an order. Usually this method is used when you need to redirect a customer to a third-party site
        /// for completing a payment (for example, PayPal Standard)
        /// </summary>
        /// <param name="postProcessPaymentRequest"></param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            //Implementing Query URL process
            var baseUrl = _worldPayHostedPaymentSettings.UseSandbox ?
                _worldPayHostedPaymentSettings.SandboxUrl :
                _worldPayHostedPaymentSettings.LiveUrl;

            //create common query parameters for the request
            var queryParameters = CreateQueryParameters(postProcessPaymentRequest);

            //remove null values from parameters
            queryParameters = queryParameters.Where(parameter => !string.IsNullOrEmpty(parameter.Value))
                .ToDictionary(parameter => parameter.Key, parameter => parameter.Value);

            var url = QueryHelpers.AddQueryString(baseUrl, queryParameters);

            //Log formated URL if logging is ON
            if (!string.IsNullOrEmpty(_worldPayHostedPaymentSettings.LogFilePath))
            {
                WorldPayHostedHelper.HandleException(null, _worldPayHostedPaymentSettings.LogFilePath, url, null);
            }

            //Redirect to WorldPay
            _httpContextAccessor.HttpContext.Response.Redirect(url);

            //HttpResponse.Redirect(url);
            //RedirectPermanent
        }
2 Jahre weitere
Looks like it might work
Do you have the url correct  ?
What is the problem does it open a url or goto error
Any errors in the log ?
2 Jahre weitere
Hi Yidna,

Thanks for your response, on a closer inspection, I found that I was using PaymentMethodType as Standard.
I found a note under OpcConfirmOrder method
//Redirection will not work because it's AJAX request.
//That's why we don't process it here (we redirect a user to another page where he'll be redirected)


Once I changed PaymentMethodType to PaymentMethodType.Redirection it all started working.

Do you have the url correct? Yes the Url was correct, as I am able to access them directly through browser
What is the problem does it open a url or goto error? There were no errors and it was going to basket page (I believe via Checkout complete page)
Any errors in the log ? No error logs.

Kind regards
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.