Пример #1
0
        protected void btConfirm_Click(object sender, EventArgs e)
        {
            lError.Text = "";

            string CountryCode = ddlCountry.SelectedValue;
            string State       = shipState.Text;

            if (CountryCode == "US")
            {
                State = ddlStates.SelectedValue;
            }

            if (string.IsNullOrEmpty(State))
            {
                lState.Text = "State is required";
                return;
            }

            if (!BasicUtils.IsValidEmail(shipEmail.Text))
            {
                lError.Text = "Email must be valid";
                return;
            }

            Guid cartKey = Guid.Parse(Request.Cookies["cartKey"].Value);

            List <SqlParameter> p = new List <SqlParameter>();

            p.Add(new SqlParameter("@CacheID", cartKey));
            p.Add(new SqlParameter("@ShipFirstName", shipFName.Text));
            p.Add(new SqlParameter("@ShipLastName", shipLName.Text));
            p.Add(new SqlParameter("@ShipAddress1", shipAddress1.Text));
            p.Add(new SqlParameter("@ShipAddress2", shipAddress2.Text));
            p.Add(new SqlParameter("@ShipCity", shipCity.Text));
            p.Add(new SqlParameter("@ShipState", State));
            p.Add(new SqlParameter("@ShipCountryCode", ddlCountry.SelectedValue));
            p.Add(new SqlParameter("@ShipZip", shipZip.Text));
            p.Add(new SqlParameter("@ShipEmail", shipEmail.Text));
            p.Add(new SqlParameter("@ShipPhone", shipPhone.Text));
            DB.Set("CartAddressUpdate", p.ToArray());

            decimal Shipping = ScalablePressUtils.GetShippingQuote(cartKey);

            string redirect_url = PayPalUtils.ConfirmSale(cartKey, Shipping);

            Response.Redirect(redirect_url, false);
        }
Пример #2
0
        protected void completeSale_Click(object sender, EventArgs e)
        {
            try
            {
                string PID = PayPalUtils.ExecuteSale(paymentid.Value, payerid.Value);

                Guid cartKey = Guid.Parse(Request.Cookies["cartKey"].Value);

                decimal ShippingTotal = ScalablePressUtils.GetShippingQuote(cartKey);

                List <SqlParameter> p = new List <SqlParameter>();
                p.Add(new SqlParameter("@CacheID", cartKey));
                p.Add(new SqlParameter("@ShippingPaid", ShippingTotal));
                p.Add(new SqlParameter("@PaymentID", PID));

                SqlParameter outOrderID = new SqlParameter("@OutOrderID", SqlDbType.Int);
                outOrderID.Direction = ParameterDirection.Output;
                p.Add(outOrderID);

FORCEREPEAT:
                try
                {
                    DB.Set("CartOrderedInsert", p.ToArray());
                }
                catch
                {
                    goto FORCEREPEAT;
                }

                string     OrderID    = outOrderID.Value.ToString();
                HttpCookie cartCookie = new HttpCookie("cartKey");
                cartCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(cartCookie);

                bool ordered  = false;
                int  retry    = 0;
                int  maxRetry = 3;

                while (!ordered)
                {
                    try
                    {
                        ordered = ScalablePressUtils.PlaceOrder(OrderID);
                    }
                    catch (Exception ex)
                    {
                        LoggingUtil.InsertError(ex);
                        if (retry > maxRetry)
                        {
                            return;
                        }
                        else
                        {
                            retry++;
                        }
                    }
                }

                BasicUtils.SendConfirmation(OrderID);
                Response.Redirect("~/Shop/Confirm.aspx", false);
            }
            catch (Exception ex)
            {
                LoggingUtil.InsertError(ex);
            }
        }