Пример #1
0
 public ActionResult Items(int id = 0) {
     try {
         Cart order = new Cart();
         order = order.GetByPayment(id);
         Customer customer = new Customer{ ID = order.cust_id };
         customer.Get();
         ViewBag.customer = customer;
         ViewBag.order = order;
         ViewBag.statuses = new OrderStatus().GetAll();
     } catch (Exception) {
         return RedirectToAction("Index");
     }
     return View();
 }
        public ActionResult AddBillingAddress()
        {
            int ID = Convert.ToInt32(Request.Form["customerID"]);
            try {
                Customer customer = new Customer { ID = ID };
                customer.Get();
                Cart currentCart = customer.Carts.Where(x => x.payment_id == 0).First<Cart>();

                Address billing = new Address();
                // Build out our Billing object
                billing = new Address {
                    first = Request.Form["bfirst"],
                    last = Request.Form["blast"],
                    street1 = Request.Form["bstreet1"],
                    street2 = Request.Form["bstreet2"],
                    city = Request.Form["bcity"],
                    postal_code = Request.Form["bzip"],
                    residential = (Request.Form["bresidential"] == null) ? false : true,
                    active = true
                };
                try {
                    billing.state = Convert.ToInt32(Request.Form["bstate"]);
                } catch (Exception) {
                    throw new Exception("You must select a billing state/province.");
                }
                //shipping.GeoLocate();
                billing.Save(customer.ID);

                // Retrieve Customer from Sessions/Cookie
                currentCart.SetBilling(billing.ID);
            } catch (Exception e) {
                TempData["error"] = e.Message;
            }

            return RedirectToAction("Step4", new { id = ID });
        }
        public ActionResult Step5(int id = 0, int address = 0)
        {
            Customer c = new Customer { ID = id };
            c.Get();
            ViewBag.customer = c;

            Cart currentCart = c.Carts.Where(x => x.payment_id == 0).First<Cart>();
            if (address != 0) {
                currentCart.SetBilling(address);
            }
            currentCart.SetTax();
            ViewBag.cart = currentCart;

            ViewBag.showShipping = true;
            ViewBag.message = TempData["message"];

            List<int> months = new List<int>();
            for (int i = 1; i <= 12; i++) {
                months.Add(i);
            }
            List<int> yearlist = new List<int>();
            for (int i = DateTime.Now.Year; i <= (DateTime.Now.Year + 20); i++) {
                yearlist.Add(i);
            }
            ViewBag.months = months;
            ViewBag.yearlist = yearlist;

            return View("Add-Payment");
        }
        public ActionResult Step4(int id = 0, string shipping_type = "")
        {
            Customer c = new Customer {ID = id};
            c.Get();
            ViewBag.customer = c;

            string error = (TempData["message"] != null) ? (string)TempData["message"] : null;
            ViewBag.error = error;

            List<Address> addresses = c.GetAddresses();
            ViewBag.addresses = addresses;

            Cart currentCart = c.Carts.Where(x => x.payment_id == 0).First<Cart>();

            List<Country> countries = UDF.GetCountries();
            ViewBag.countries = countries;

            if (shipping_type != "") {
                decimal shipping_price = 0;
                string shiptype = "";
                string[] typesplit = shipping_type.Split('|');
                shiptype = typesplit[0];
                shipping_price = Convert.ToDecimal(typesplit[1]);
                currentCart.setShippingType(shiptype, shipping_price);
            }
            // We need to calculate the tax now that we know the shipping state
            ViewBag.cart = currentCart;

            return View("Add-Billing");
        }
        public ActionResult Step3(int id = 0)
        {
            Customer c = new Customer {
                ID = id
            };
            c.Get();
            ViewBag.customer = c;

            string error = (TempData["message"] != null) ? (string)TempData["message"] : null;
            ViewBag.error = error;

            List<Address> addresses = c.GetAddresses();
            ViewBag.addresses = addresses;

            Cart currentCart = c.Carts.Where(x => x.payment_id == 0).First<Cart>();
            ViewBag.cart = currentCart;

            List<Country> countries = UDF.GetCountries();
            ViewBag.countries = countries;

            ShippingResponse shippingresponse = new ShippingResponse();
            shippingresponse = currentCart.getShipping();
            ViewBag.shippingresponse = shippingresponse;
            return View("Add-Shipping");
        }
 public ActionResult Step2(int id = 0)
 {
     Customer c = new Customer {
         ID = id
     };
     c.Get();
     Cart currentCart = new Cart();
     try {
         currentCart = c.Carts.Where(x => x.payment_id == 0).First<Cart>();
     } catch {
         Cart cart = new Cart();
         currentCart = cart.Save(c.ID);
     }
     ViewBag.customer = c;
     ViewBag.cart = currentCart;
     return View("Add-Items");
 }
 public ActionResult ChooseShipping(int id, int address)
 {
     Customer customer = new Customer { ID = id };
     customer.Get();
     Cart currentCart = customer.Carts.Where(x => x.payment_id == 0).First<Cart>();
     currentCart.SetShipping(address);
     return RedirectToAction("Step3", new { id = id });
 }
        public ActionResult Authorize(int id = 0)
        {
            Customer c = new Customer { ID = id };
            c.Get();
            Cart currentCart = c.Carts.Where(x => x.payment_id == 0).First<Cart>();
            Settings settings = ViewBag.settings;

            decimal amount = currentCart.getTotal();
            string cardnum = Request.Form["cardnumber"];
            string month = Request.Form["expiremonth"];
            string year = Request.Form["expireyear"];
            string cvv = Request.Form["cvv"];
            string first = Request.Form["first"];
            string last = Request.Form["last"];

            //step 1 - create the request
            IGatewayRequest request = new AuthorizationRequest(cardnum, month + year, amount, "Transaction");

            //These are optional calls to the API
            request.AddCardCode(cvv);

            //Customer info - this is used for Fraud Detection
            request.AddCustomer(c.ID.ToString(), first, last, currentCart.Billing.street1 + ((currentCart.Billing.street2 != "") ? " " + currentCart.Billing.street2 : ""), currentCart.Billing.State1.abbr, currentCart.Billing.postal_code);

            //order number
            //request.AddInvoice("invoiceNumber");

            //Custom values that will be returned with the response
            //request.AddMerchantValue("merchantValue", "value");

            //Shipping Address
            request.AddShipping(c.ID.ToString(), currentCart.Shipping.first, currentCart.Shipping.last, currentCart.Shipping.street1 + ((currentCart.Shipping.street2 != "") ? " " + currentCart.Shipping.street2 : ""), currentCart.Shipping.State1.abbr, currentCart.Shipping.postal_code);

            //step 2 - create the gateway, sending in your credentials and setting the Mode to Test (boolean flag)
            //which is true by default
            //this login and key are the shared dev account - you should get your own if you
            //want to do more testing
            bool testmode = false;
            if (settings.Get("AuthorizeNetTestMode").Trim() == "true") {
                testmode = true;
            }

            Gateway gate = new Gateway(settings.Get("AuthorizeNetLoginKey"), settings.Get("AuthorizeNetTransactionKey"), testmode);

            //step 3 - make some money
            IGatewayResponse response = gate.Send(request);
            if (response.Approved) {
                currentCart.AddPayment("credit card", response.AuthorizationCode,"Complete");
                currentCart.SendConfirmation();
                int cartid = currentCart.ID;
                return RedirectToAction("Step6", new { id = cartid });
            } else {
                TempData["message"] = response.Message;
                return RedirectToAction("Step5", new { id = c.ID });
            }
        }