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
}