private void ProcessCheckout()
        {
            Address BillingAddress = new Address();

            BillingAddress.LoadByCustomer(ThisCustomer.CustomerID, ThisCustomer.PrimaryBillingAddressID, AddressTypes.Billing);

            int OrderNumber = 0;
            // ----------------------------------------------------------------
            // Process The Order:
            // ----------------------------------------------------------------
            ErrorMessage err;

            if (PaymentMethod.Length == 0 || PM != AppLogic.CleanPaymentMethod(BillingAddress.PaymentMethodLastUsed))
            {
                err = new ErrorMessage(Server.HtmlEncode(AppLogic.GetString("checkoutpayment.aspx.20", ThisCustomer.SkinID, ThisCustomer.LocaleSetting)));
                Response.Redirect("checkoutpayment.aspx?errormsg=" + err.MessageId);
            }
            if (PM == AppLogic.ro_PMCreditCard)
            {
                bool CardinalAllowed = AppLogic.ProductIsMLExpress() == false &&
                                       AppLogic.AppConfigBool("CardinalCommerce.Centinel.Enabled") && !(cart.Total(true) == System.Decimal.Zero && AppLogic.AppConfigBool("SkipPaymentEntryOnZeroDollarCheckout"));
                if (CardinalAllowed && (BillingAddress.CardType.Trim().Equals("VISA", StringComparison.InvariantCultureIgnoreCase) ||
                                        BillingAddress.CardType.Trim().Equals("MASTERCARD", StringComparison.InvariantCultureIgnoreCase) ||
                                        BillingAddress.CardType.Trim().Equals("JCB", StringComparison.InvariantCultureIgnoreCase)))
                {
                    // use cardinal pre-auth fraud screening:
                    String ACSUrl               = String.Empty;
                    String Payload              = String.Empty;
                    String TransactionID        = String.Empty;
                    String CardinalLookupResult = String.Empty;
                    OrderNumber = AppLogic.GetNextOrderNumber();
                    if (Cardinal.PreChargeLookup(BillingAddress.CardNumber, Localization.ParseUSInt(BillingAddress.CardExpirationYear), Localization.ParseUSInt(BillingAddress.CardExpirationMonth), OrderNumber, cart.Total(true), "", out ACSUrl, out Payload, out TransactionID, out CardinalLookupResult))
                    {
                        // redirect to intermediary page which gets card password from user:
                        ThisCustomer.ThisCustomerSession["Cardinal.LookupResult"]  = CardinalLookupResult;
                        ThisCustomer.ThisCustomerSession["Cardinal.ACSUrl"]        = ACSUrl;
                        ThisCustomer.ThisCustomerSession["Cardinal.Payload"]       = Payload;
                        ThisCustomer.ThisCustomerSession["Cardinal.TransactionID"] = TransactionID;
                        ThisCustomer.ThisCustomerSession["Cardinal.OrderNumber"]   = OrderNumber.ToString();

                        if (AppLogic.ProductIsMLExpress() == false)
                        {
                            Response.Redirect("cardinalform.aspx"); // this will eventually come "back" to us in cardinal_process.aspx after going through banking system pages
                        }
                    }
                    else
                    {
                        ThisCustomer.ThisCustomerSession["Cardinal.LookupResult"] = CardinalLookupResult;
                        // user not enrolled or cardinal gateway returned error, so process card normally, using already created order #:

                        // set the ECIFlag for an 'N' Enrollment response, so the merchant receives Liability Shift Protection
                        string ECIFlag;
                        if (BillingAddress.CardType.Trim().Equals("VISA", StringComparison.InvariantCultureIgnoreCase))
                        {
                            ECIFlag = "06";  // Visa Card Issuer Liability
                        }
                        else if (BillingAddress.CardType.Trim().Equals("JCB", StringComparison.InvariantCultureIgnoreCase))
                        {
                            ECIFlag = "07";  // Indicates Merchant Liability
                        }
                        else
                        {
                            ECIFlag = "01";  // MasterCard Merchant Liability for non-enrolled card (rules differ between MC and Visa in the regard)
                        }

                        String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, ECIFlag, String.Empty, String.Empty);
                        if (status != AppLogic.ro_OK)
                        {
                            err = new ErrorMessage(Server.HtmlEncode(status));
                            Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                        }
                        DB.ExecuteSQL("update orders set CardinalLookupResult=" + DB.SQuote(ThisCustomer.ThisCustomerSession["Cardinal.LookupResult"]) + " where OrderNumber=" + OrderNumber.ToString());
                    }
                }
                else
                {
                    decimal CartTotal = cart.Total(true);
                    decimal NetTotal  = CartTotal - CommonLogic.IIF(cart.Coupon.CouponType == CouponTypeEnum.GiftCard, CommonLogic.IIF(CartTotal < cart.Coupon.DiscountAmount, CartTotal, cart.Coupon.DiscountAmount), 0);
                    // this is  specific for nexaxept gateway
                    if (AppLogic.ActivePaymentGatewayCleaned() == Gateway.ro_GWNETAXEPT &&
                        NetTotal > System.Decimal.Zero)
                    {
                        int  ordnum;
                        bool result = int.TryParse(ThisCustomer.ThisCustomerSession["Nextaxept_OrderNumber"], out ordnum);

                        if (result)
                        {
                            OrderNumber = ordnum;
                        }
                    }
                    else
                    {
                        // try create the order record, check for status of TX though:
                        OrderNumber = AppLogic.GetNextOrderNumber();
                    }
                    String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                    if (status == AppLogic.ro_3DSecure)
                    { // If credit card is enrolled in a 3D Secure service (Verified by Visa, etc.)
                        Response.Redirect("secureform.aspx");
                    }
                    if (status != AppLogic.ro_OK)
                    {
                        err = new ErrorMessage(Server.HtmlEncode(status));
                        Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                    }
                }
            }
            else if (PM.ToLower() == GatewayCheckoutByAmazon.CheckoutByAmazon.CBA_Gateway_Identifier.ToLower())
            {
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("shoppingcart.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMPurchaseOrder)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMCODMoneyOrder)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMCODCompanyCheck)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMCODNet30)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMPayPal)
            {
            }
            else if (PM == AppLogic.ro_PMPayPalExpress || PM == AppLogic.ro_PMPayPalExpressMark)
            {
                String PayPalToken = Security.UnmungeString(ThisCustomer.ThisCustomerSession["PayPalExpressToken"]);
                String PayerID     = Security.UnmungeString(ThisCustomer.ThisCustomerSession["PayPalExpressPayerID"]);
                if (PayPalToken.Length > 0)
                {
                    OrderNumber = AppLogic.GetNextOrderNumber();

                    Address UseBillingAddress = new Address();
                    UseBillingAddress.LoadByCustomer(ThisCustomer.CustomerID, ThisCustomer.PrimaryBillingAddressID, AddressTypes.Billing);
                    UseBillingAddress.PaymentMethodLastUsed = PM;
                    UseBillingAddress.CardNumber            = String.Empty;
                    UseBillingAddress.CardType            = String.Empty;
                    UseBillingAddress.CardExpirationMonth = String.Empty;
                    UseBillingAddress.CardExpirationYear  = String.Empty;
                    UseBillingAddress.CardName            = String.Empty;
                    UseBillingAddress.CardStartDate       = String.Empty;
                    UseBillingAddress.CardIssueNumber     = String.Empty;
                    UseBillingAddress.UpdateDB();

                    String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, PayPalToken, PayerID, String.Empty, String.Empty);
                    if (status != AppLogic.ro_OK)
                    {
                        err = new ErrorMessage(Server.HtmlEncode(status));
                        Response.Redirect("checkoutpayment.aspx?errormsg=" + err.MessageId);
                    }
                    else
                    {
                        ThisCustomer.ThisCustomerSession["PayPalExpressToken"]   = "";
                        ThisCustomer.ThisCustomerSession["PayPalExpressPayerID"] = "";
                    }
                }
                else
                {
                    err = new ErrorMessage("The PaypalExpress checkout token has expired, please re-login to your PayPal account or checkout using a different method of payment.");
                    Response.Redirect("shoppingcart.aspx?errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMRequestQuote)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMCheckByMail)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMCOD)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMECheck)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMMicropay)
            {
                // try create the order record, check for status of TX though:
                OrderNumber = AppLogic.GetNextOrderNumber();
                String status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            else if (PM == AppLogic.ro_PMSecureNetVault)
            {
                OrderNumber = AppLogic.GetNextOrderNumber();
                SecureNetVault vault  = new SecureNetVault(ThisCustomer);
                String         status = Gateway.MakeOrder(String.Empty, AppLogic.TransactionMode(), cart, OrderNumber, String.Empty, String.Empty, String.Empty, String.Empty);
                //String status = vault.ProcessVaultTransaction();
                if (status != AppLogic.ro_OK)
                {
                    err = new ErrorMessage(Server.HtmlEncode(status));
                    Response.Redirect("checkoutpayment.aspx?TryToShowPM=" + PM + "&errormsg=" + err.MessageId);
                }
            }
            Response.Redirect("orderconfirmation.aspx?ordernumber=" + OrderNumber.ToString() + "&paymentmethod=" + Server.UrlEncode(PaymentMethod));
        }