protected void GCheckoutButton1_Click(object sender, ImageClickEventArgs e)
 {
     CheckoutShoppingCartRequest Req = GCheckoutButton1.CreateRequest();
     Req.AddItem("Snickers", "Packed with peanuts.", 0.75m, 2);
     Req.AddItem("Gallon of Milk", "Milk goes great with candy bars!", 2.99m, 1);
     Req.AddStateTaxRule("CA", 0.0825, true);
     Req.AddStateTaxRule("IL", 0.0625, false);
     ShippingRestrictions Only48Lower = new ShippingRestrictions();
        // Only48Lower.AddAllowedCountryArea(GCheckout.AutoGen.USAreas.CONTINENTAL_48);
     Req.AddFlatRateShippingMethod("UPS Ground", 7.05m, Only48Lower);
     ShippingRestrictions OnlyCA_NV = new ShippingRestrictions();
     OnlyCA_NV.AddAllowedStateCode("CA");
     OnlyCA_NV.AddAllowedStateCode("NV");
     Req.AddFlatRateShippingMethod("California Express", 6.35m, OnlyCA_NV);
     Req.AddFlatRateShippingMethod("USPS", 3.08m);
     Req.AddPickupShippingMethod("Pick up in store", 0);
     Req.ContinueShoppingUrl = "http://www.example.com/continueshopping";
     Req.EditCartUrl = "http://www.example.com/editcart";
     GCheckoutResponse Resp = Req.Send();
     Response.Redirect(Resp.RedirectUrl, true);
 }
Beispiel #2
0
    //Google!!
    protected void GoogleCheckoutButton1_Click(object sender, ImageClickEventArgs e)
    {
        //Finding Button
        GCheckoutButton btn = (GCheckoutButton)LoginView1.FindControl("GCheckoutButton1");

        //Request
        CheckoutShoppingCartRequest req = btn.CreateRequest();

        req.EditCartUrl = BuildAbsolute("ViewCart.aspx");
        req.ContinueShoppingUrl = BuildAbsolute("Default.aspx");

        // adding to the request

        Cart c = (Cart)Session["ShoppingCart"];

        foreach (Prod p in c.Products)
        {
            req.AddItem(p.Name, "", p.Price, p.Quantity);
        }

        //Optional Requests-- not used.
        req.AddStateTaxRule("CA", 0.0825, true);
        req.AddStateTaxRule("UT", 0.0625, false);
        ShippingRestrictions Only48Lower = new ShippingRestrictions();
        Only48Lower.AddAllowedCountryArea(GCheckout.AutoGen.USAreas.CONTINENTAL_48);
        req.AddFlatRateShippingMethod("UPS Ground", 7.05m, Only48Lower);
        ShippingRestrictions OnlyCA_NV = new ShippingRestrictions();
        OnlyCA_NV.AddAllowedStateCode("CA");
        OnlyCA_NV.AddAllowedStateCode("NV");
        req.AddFlatRateShippingMethod("California Express", 6.35m, OnlyCA_NV);
        req.AddFlatRateShippingMethod("USPS", 3.08m);
        req.AddPickupShippingMethod("Pick up in store", 0);

        //Request send
        GCheckoutResponse resp = req.Send();

        //If the response reports success, use the CreateOrder method of the Cart object to write the cart contents to the database as an order.
        //Use the Google checkout serial number as the orderID
        if (resp.IsGood)
        {

            bool ordercreated = c.CreateOrder(resp.SerialNumber, User.Identity.Name);

            //Shopping cart reset and send to google. Or error.
            if (ordercreated)
            {
                Session["ShoppingCart"] = null;
                //Redirect
                Response.Redirect(resp.RedirectUrl, true);
            }
            else
            {
                lblStatus.Text = "OH NO! Something went horribly wrong! Just kidding, we've had a small error. Try again later.";
            }

        }
        else
        {
            lblStatus.Text = "OH NO! Something went horribly wrong! Just kidding, we've had a small error. Try again later.";
        }
    }