/// <summary>
        /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
        /// </summary>
        /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            Order order = postProcessPaymentRequest.Order;

            // Make sure order is not already paid or authorized
            if (order.PaymentStatus == PaymentStatus.Paid || order.PaymentStatus == PaymentStatus.Authorized)
            {
                return;
            }

            string currencyCode =
                _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            string description = string.Format("{0} - Order", _storeContext.CurrentStore.Name);
            string userAgent;

            if (_httpContextAccessor.HttpContext.Request != null)
            {
                userAgent = _httpContextAccessor.HttpContext.Request.Headers["User-Agent"].ToString();
            }
            else
            {
                userAgent = null;
            }

            string returnUrl = _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayEx/Complete";
            string cancelUrl = _webHelper.GetStoreLocation(false) + "Plugins/PaymentPayEx/CancelOrder?id=" + order.Id;

            PayexInterface payex = GetPayexInterface();

            string agreementRef = null;

            // If the customer wishes to save his payment details, we make an agreement.
            // This should be saved later in the complete operation, if it occurs.
            agreementRef = TryGetAgreementRef(_paymentService.DeserializeCustomValues(order));
            if (agreementRef == "new")
            {
                CreateAgreementRequest agreementRequest = new CreateAgreementRequest
                {
                    PurchaseOperation = GetPurchaseOperation(),
                    MerchantRef       = order.OrderGuid.ToString(),
                    MaxAmount         = _payExPaymentSettings.AgreementMaxAmount,
                    Description       = description,
                };
                CreateAgreementResult agreementResult =
                    payex.CreateAgreement(agreementRequest).GetAwaiter().GetResult();
                if (agreementResult.IsRequestSuccessful)
                {
                    agreementRef = agreementResult.AgreementRef;
                }
                else
                {
                    _logger.Error(
                        string.Format("PayEx: CreateAgreement (for AutoPay) failed for order {0}.", order.Id),
                        new NopException(agreementResult.GetErrorDescription()), order.Customer);
                }
            }

            // Initialize the purchase and get the redirect URL
            InitializeRequest request = new InitializeRequest
            {
                PurchaseOperation = GetPurchaseOperation(),
                Amount            = order.OrderTotal,
                CurrencyCode      = currencyCode,
                OrderID           = order.OrderGuid.ToString(),
                ProductNumber     = "ncOrder",
                Description       = description,
                AgreementRef      = agreementRef,
                //VatPercent = 100M * order.OrderTax / order.OrderTotal,
                ClientIPAddress = order.CustomerIp,
                UserAgent       = userAgent,
                ReturnURL       = returnUrl,
                CancelUrl       = cancelUrl,
                View            = PaymentView,
                ClientLanguage  = _workContext.WorkingLanguage?.LanguageCulture,
            };

            BeforeInitialize(postProcessPaymentRequest, request);

            InitializeResult result = payex.Initialize(request).GetAwaiter().GetResult();

            if (result.IsRequestSuccessful)
            {
                // Save OrderRef in case TransactionCallback fails or is implemented externally.
                order.AuthorizationTransactionCode = result.OrderRef;
                _orderService.UpdateOrder(order);
                if (_payExPaymentSettings.PassProductNamesAndTotals)
                {
                    AddOrderLines(payex, result.OrderRef, order);
                }
                // Redirect to PayEx
                _httpContextAccessor.HttpContext.Response.Redirect(result.RedirectUrl);
            }
            else
            {
                throw new NopException(result.GetErrorDescription());
            }
        }