protected void Page_Load(object sender, EventArgs e)
        {
            string Locale = CultureInfo.CurrentCulture.Name;

            _country = Locale.Substring(3, 2);

            MembershipUser <DistributorProfileModel> member = null;

            var    memberDefault = Membership.GetUser();
            string DistributorID = string.Empty;

            try
            {
                member        = (MembershipUser <DistributorProfileModel>)memberDefault;
                DistributorID = (member != null && member.Value != null) ? member.Value.Id : string.Empty;
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("PaymentGatewayManager Null member cast failed : {0} ", ex.Message));
            }

            if (!string.IsNullOrEmpty(DistributorID))
            {
                _sessionInfo = SessionInfo.GetSessionInfo(DistributorID, Locale);
            }

            if (!IsPostBack)
            {
                ProductsBase.RemoveDupCheckCookie();
                (Master as OrderingMaster).SetPageHeader(GetLocalResourceObject("PageResource1.Title") as string);
                PaymentGatewayResponse gatewayResponse = null;
                try
                {
                    gatewayResponse = PaymentGatewayResponse.Create();
                    if (null != gatewayResponse)
                    {
                        LoggerHelper.Warn(string.Format("PaymentGatewayRequest Splunk Log : Request {0}", LogFormData(Request.Form)));
                    }
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(string.Format("PaymentGatewayManager failed to create a Response: {0}", ex.Message));
                }

                if (gatewayResponse == null)
                {
                    MyHLShoppingCart ShoppingCart = (null != this._sessionInfo && null != this._sessionInfo.ShoppingCart) ? this._sessionInfo.ShoppingCart : ShoppingCartProvider.GetShoppingCart(DistributorID, Locale);
                    if (ShoppingCart != null)
                    {
                        try
                        {
                            PaymentGatewayInvoker invoker = PaymentGatewayInvoker.Create(HLConfigManager.Configurations.PaymentsConfiguration.PaymentGatewayPaymentMethods, (ShoppingCart.Totals as OrderTotals_V01).AmountDue);
                            invoker.Submit();
                        }
                        catch (ThreadAbortException)
                        {
                            //this just seems to come along with the redirect request. We don't want this in the logs
                        }
                        catch (Exception ex)
                        {
                            PaymentGatewayInvoker.LogBlindError(string.Format("Error occurred Invoking Payment Gateway {0}. The error is: {1}", HLConfigManager.Configurations.PaymentsConfiguration.PaymentGatewayInvoker, ex.Message));
                            if (HLConfigManager.Configurations.DOConfiguration.IsChina && _sessionInfo.StandAloneDonationError == standAloneDonation)
                            {
                                _sessionInfo.StandAloneDonationError = standAloneDonationerror;
                                Response.Redirect("~/Ordering/Donation.aspx");
                            }
                            else
                            {
                                Response.Redirect("~/Ordering/Checkout.aspx");
                            }
                        }
                    }
                }
                else
                {
                    if (gatewayResponse is PGHPaymentGatewayResponse && _sessionInfo != null)
                    {
                        Session[PaymentGatewayResponse.PGH_FPX_PaymentStatus] =
                            ((PGHPaymentGatewayResponse)gatewayResponse).PhgPaymentStatus;
                    }

                    if (gatewayResponse.IsReturning)
                    {
                        bool pending   = gatewayResponse.IsPendingTransaction;
                        bool cancelled = gatewayResponse.IsCancelled;
                        PaymentGatewayRecordStatusType gatewayResponseStatus = gatewayResponse.Status;
                        if (gatewayResponse.IsApproved)
                        {
                            if (!gatewayResponse.CanSubmitIfApproved && _sessionInfo != null)
                            {
                                _sessionInfo.OrderStatus = SubmitOrderStatus.OrderSubmitted;
                                _sessionInfo.OrderNumber = gatewayResponse.OrderNumber;
                                if (_sessionInfo.ShoppingCart != null)
                                {
                                    ShoppingCartProvider.UpdateShoppingCart(_sessionInfo.ShoppingCart,
                                                                            string.Empty,
                                                                            gatewayResponse.OrderNumber, DateTime.Now);
                                }
                                return;
                            }
                        }

                        if (gatewayResponseStatus == PaymentGatewayRecordStatusType.OrderSubmitted && _sessionInfo != null)
                        {
                            _sessionInfo.OrderStatus = SubmitOrderStatus.OrderSubmitted;
                            _sessionInfo.OrderNumber = gatewayResponse.OrderNumber;
                            ShoppingCartProvider.UpdateShoppingCart(_sessionInfo.ShoppingCart,
                                                                    string.Empty,
                                                                    gatewayResponse.OrderNumber, DateTime.Now);
                            return;
                        }
                        else if (pending && _sessionInfo != null)
                        {
                            _sessionInfo.OrderStatus = SubmitOrderStatus.Unknown;
                            if (_sessionInfo.ShoppingCart != null)
                            {
                                _sessionInfo.ShoppingCart.CloseCart();
                            }
                            Response.Redirect("~/Ordering/Catalog.aspx?ETO=FALSE");
                            return;
                        }
                        else if (cancelled && _sessionInfo != null)
                        {
                            _sessionInfo.OrderStatus = SubmitOrderStatus.Unknown;
                            Response.Redirect("~/Ordering/Checkout.aspx");
                            return;
                        }
                        else if (gatewayResponse.IsApproved)
                        {
                            //Let it fall through the natural flow...
                        }
                        else if (gatewayResponseStatus == PaymentGatewayRecordStatusType.Declined)
                        {
                            Session[PaymentGatewayResponse.PaymentGateWateSessionKey] = gatewayResponse;
                            if (HLConfigManager.Configurations.DOConfiguration.IsChina && _sessionInfo.StandAloneDonationError == standAloneDonation)
                            {
                                _sessionInfo.StandAloneDonationError = standAloneDonationerror;
                                Response.Redirect("~/Ordering/Donation.aspx");
                            }
                            else
                            {
                                if (_sessionInfo != null)
                                {
                                    _sessionInfo.OrderStatus = SubmitOrderStatus.OrderSubmitFailed;
                                    _sessionInfo.OrderNumber = gatewayResponse.OrderNumber;
                                }
                                Response.Redirect("~/Ordering/Checkout.aspx");
                            }

                            return;
                        }
                        else
                        {
                            if (_sessionInfo != null)
                            {
                                _sessionInfo.OrderStatus = SubmitOrderStatus.OrderSubmitFailed;
                                return;
                            }
                        }
                    }

                    //For PGH-Submitted orders
                    if (gatewayResponse is PGHPaymentGatewayResponse)
                    {
                        if (gatewayResponse.Status == PaymentGatewayRecordStatusType.OrderSubmitted && _sessionInfo != null)
                        {
                            // Timer1.Enabled = false;
                            _sessionInfo.OrderStatus = SubmitOrderStatus.OrderSubmitted;
                            _sessionInfo.OrderNumber = gatewayResponse.OrderNumber;
                            return;
                        }
                    }

                    if (member == null || member.Value == null) //Being posted to by a gateway
                    {
                        offLinePost     = true;
                        Timer1.Enabled  = false;
                        _customResponse = gatewayResponse.SpecialResponse;
                        bool approved = gatewayResponse.IsApproved;
                        if (approved)
                        {
                            if (gatewayResponse.CanSubmitIfApproved)
                            {
                                SubmitOrder(gatewayResponse);
                            }

                            return;
                        }
                    }

                    string orderNumber = gatewayResponse.OrderNumber;
                    if (null != _sessionInfo)
                    {
                        if (_sessionInfo.OrderStatus == SubmitOrderStatus.OrderSubmitted && orderNumber != _sessionInfo.OrderNumber)
                        {
                            _sessionInfo.OrderStatus = SubmitOrderStatus.Unknown;
                        }
                        if (_sessionInfo.OrderStatus == SubmitOrderStatus.Unknown)
                        {
                            if (gatewayResponse.IsApproved && gatewayResponse.CanSubmitIfApproved)
                            {
                                _sessionInfo.OrderStatus = SubmitOrderStatus.OrderBeingSubmitted;
                                if (string.IsNullOrEmpty(_sessionInfo.OrderMonthShortString))
                                {
                                    var orderMonth = new OrderMonth(_country);
                                    //orderMonth.ResolveOrderMonth();
                                    _sessionInfo.OrderMonthShortString = orderMonth.OrderMonthShortString;
                                    _sessionInfo.OrderMonthString      = orderMonth.OrderMonthString;
                                }
                                if (null == _sessionInfo.ShoppingCart)
                                {
                                    _sessionInfo.ShoppingCart = ShoppingCartProvider.GetShoppingCart(DistributorID, Locale);
                                }

                                (new AsyncSubmitOrderProvider()).AsyncSubmitOrder(gatewayResponse, _country, _sessionInfo);
                            }
                            else
                            {
                                if (gatewayResponse.Status == PaymentGatewayRecordStatusType.ApprovalPending && HLConfigManager.Configurations.PaymentsConfiguration.CanSubmitPending)
                                {
                                    if (null != gatewayResponse as PGHPaymentGatewayResponse)
                                    {
                                        if ((gatewayResponse as PGHPaymentGatewayResponse).OrderStatus == HL.PGH.Api.OrderStatus.GatewayWillSubmit)
                                        {
                                            _sessionInfo.OrderStatus = SubmitOrderStatus.OrderSubmittedProcessing;
                                            Response.Redirect("~/Ordering/Confirm.aspx?OrderNumber=" + orderNumber);
                                            return;
                                        }
                                    }
                                    _sessionInfo.OrderStatus = SubmitOrderStatus.OrderBeingSubmitted;
                                    if (string.IsNullOrEmpty(_sessionInfo.OrderMonthShortString))
                                    {
                                        var orderMonth = new OrderMonth(_country);
                                        _sessionInfo.OrderMonthShortString = orderMonth.OrderMonthShortString;
                                        _sessionInfo.OrderMonthString      = orderMonth.OrderMonthString;
                                    }
                                    if (null == _sessionInfo.ShoppingCart)
                                    {
                                        _sessionInfo.ShoppingCart = ShoppingCartProvider.GetShoppingCart(DistributorID, Locale);
                                    }
                                    (new AsyncSubmitOrderProvider()).AsyncSubmitOrder(gatewayResponse, _country, _sessionInfo);
                                }
                                else
                                {
                                    Session[PaymentGatewayResponse.PaymentGateWateSessionKey] = gatewayResponse;
                                    if (HLConfigManager.Configurations.DOConfiguration.IsChina && _sessionInfo.StandAloneDonationError == standAloneDonation)
                                    {
                                        _sessionInfo.StandAloneDonationError = standAloneDonationerror;
                                        Response.Redirect("~/Ordering/Donation.aspx");
                                    }
                                    else
                                    {
                                        Response.Redirect("~/Ordering/Checkout.aspx");
                                    }
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        lbSubmitOrderStatus.Text = string.Format((string)GetLocalResourceObject("PaymentGatewayOrderSubmitFailed"), orderNumber);
                        if (gatewayResponse != null && !string.IsNullOrEmpty(orderNumber))
                        {
                            var status = OrderProvider.GetPaymentGatewayRecordStatus(orderNumber);
                            if (status == PaymentGatewayRecordStatusType.Approved || status == PaymentGatewayRecordStatusType.OrderSubmitted)
                            {
                                SettleCustomerOrderPayment(orderNumber);
                                Response.Redirect("~/Ordering/Confirm.aspx?OrderNumber=" + orderNumber);
                            }
                        }
                        lbSubmitOrderStatus.Style.Add(HtmlTextWriterStyle.Color, "Red");
                        Timer1.Enabled = false;
                    }
                }
            }
        }