protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();

            string token = Request.QueryString["token"];

            AjaxTotalsToken totalsToken = AjaxTotalsHelper.DecryptToken(token);

            if (totalsToken != null && Request.UserHostAddress == totalsToken.userIP &&
                DateTime.Now.CompareTo(DateTime.Parse(totalsToken.expireDateTime)) <= 0)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string skuId    = Request.QueryString["PId"];
                string address1 = Request.Form["a1"];
                string address2 = Request.Form["a2"];
                string city     = Request.Form["city"];
                string state    = Request.Form["state"];
                string zip      = Request.Form["zip"];
                string quantity = Request.Form["quantity"];
                string promo    = Request.Form["promo"];

                if (!string.IsNullOrEmpty(skuId))
                {
                    CSBusiness.ShoppingManagement.Cart cartObject = new CSBusiness.ShoppingManagement.Cart();
                    cartObject.AddItem(Convert.ToInt32(skuId), Convert.ToInt32(quantity), true, false);

                    Address shippingAddress = new Address();
                    shippingAddress.Address1        = address1;
                    shippingAddress.Address2        = address2;
                    shippingAddress.City            = city;
                    shippingAddress.StateProvinceId = Convert.ToInt32(state);
                    shippingAddress.ZipPostalCode   = zip;

                    cartObject.ShippingAddress = shippingAddress;

                    cartObject.DiscountCode = promo;

                    cartObject.Compute();


                    AjaxTotalsResponse responseObj = new AjaxTotalsResponse()
                    {
                        total            = cartObject.Total,
                        shippingHandling = cartObject.ShippingCost,
                        subTotal         = cartObject.SubTotal,
                        tax      = cartObject.TaxCost,
                        discount = cartObject.DiscountAmount
                    };

                    Response.Write(serializer.Serialize(responseObj));
                }
                else
                {
                    Response.Write(serializer.Serialize(new AjaxTotalsResponse()
                    {
                        subTotal = 0, shippingHandling = 0, total = 0, tax = 0
                    }));
                }
            }

            Response.End();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["PId"] != null)
                {
                    skuId = Convert.ToInt32(Request.Params["PId"]);
                }

                if (Request.Params["CId"] != null)
                {
                    cId = Convert.ToInt32(Request.Params["CId"]);
                }

                if (Request.Params["DId"] != null)
                {
                    dId = Convert.ToInt32(Request.Params["DId"]);
                }

                if (Request.Params["QId"] != null)
                {
                    qId = Convert.ToInt32(Request.Params["QId"]);
                }

                if (skuId > 0)
                {
                    if (cId == (int)ShoppingCartType.SingleCheckout)
                    {
                        clientData = (ClientCartContext)Session["ClientOrderData"];
                        cartObject = new CSBusiness.ShoppingManagement.Cart();
                        cartObject.AddItem(skuId, qId, true, false);
                        if (dId > 0)
                        {
                            bool settingVal = Convert.ToBoolean(ConfigHelper.ReadAppSetting("DisCountCardDisplay", "false"));
                            cartObject.AddItem(dId, qId, settingVal, false);
                        }

                        cartObject.ShippingAddress = clientData.CustomerInfo.BillingAddress;
                        cartObject.Compute();
                        cartObject.ShowQuantity = false;
                        clientData.CartInfo     = cartObject;

                        //Sri Comment: OverrideSetting for Database configuration
                        if (CSFactory.OrderProcessCheck() == (int)OrderProcessTypeEnum.InstantOrderProcess)
                        {
                            int orderId = CSResolve.Resolve <IOrderService>().SaveOrder(clientData);
                            if (orderId > 0)
                            {
                                //remove Customer Data and Payment Data in session object
                                clientData.ResetData();
                                clientData.OrderId         = orderId;
                                Session["ClientOrderData"] = clientData;
                            }
                            if (OrderHelper.AuthorizeOrder(orderId) == true)
                            {
                                Response.Redirect("CheckoutThankYou.aspx?oId=" + orderId);
                            }
                            else
                            {
                                Response.Redirect("CardDecline.aspx?failedAuth=1&orderID=" + orderId);
                            }

                            Response.Redirect("PostSale.aspx");
                        }
                    }
                    else if (cId == (int)ShoppingCartType.ShippingCreditCheckout)
                    {
                        clientData = (ClientCartContext)Session["ClientOrderData"];
                        cartObject = new CSBusiness.ShoppingManagement.Cart();
                        cartObject.AddItem(skuId, qId, true, false);
                        if (dId > 0)
                        {
                            bool settingVal = Convert.ToBoolean(ConfigHelper.ReadAppSetting("DisCountCardDisplay", "false"));
                            cartObject.AddItem(dId, qId, settingVal, false);
                        }
                        cartObject.ShippingAddress = clientData.CustomerInfo.BillingAddress;
                        cartObject.Compute();
                        cartObject.ShowQuantity    = false;
                        clientData.CartInfo        = cartObject;
                        Session["ClientOrderData"] = clientData;
                        Response.Redirect("cart.aspx");
                    }

                    else
                    {
                        //we may set this object in index page to capture request information
                        if (Session["ClientOrderData"] == null)
                        {
                            clientData          = new ClientCartContext();
                            clientData.CartInfo = new CSBusiness.ShoppingManagement.Cart();
                        }
                        else
                        {
                            clientData = (ClientCartContext)Session["ClientOrderData"];
                            if (clientData.CartInfo == null)
                            {
                                clientData.CartInfo = new CSBusiness.ShoppingManagement.Cart();
                            }
                        }

                        clientData.CartInfo.AddItem(skuId, qId, true, false);
                        if (dId > 0)
                        {
                            bool settingVal = Convert.ToBoolean(ConfigHelper.ReadAppSetting("DisCountCardDisplay", "false"));
                            cartObject.AddItem(dId, qId, settingVal, false);
                        }
                        clientData.CartInfo.Compute();
                        clientData.CartInfo.ShowQuantity = false;

                        Session["ClientOrderData"] = clientData;
                        Response.Redirect("cart.aspx");
                    }
                }
            }
        }