public async Task<ActionResult> Index(string message = "") { HttpContext ctx = System.Web.HttpContext.Current; Customer customer = new Customer(); ViewBag.timezone = UDF.GetTimeZone(ctx); var pcats = CURTAPI.GetParentCategoriesAsync(); await Task.WhenAll(new Task[] { pcats }); ViewBag.parent_cats = await pcats; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (!customer.Cart.Validate()) { return RedirectToAction("Index", "Cart"); } if (customer.Cart.payment_id > 0) { UDF.ExpireCart(ctx, customer.ID); return RedirectToAction("Index", "Cart"); } // Create Cart object from customer customer.BindAddresses(); Cart cart = customer.Cart; // Get the parts from this Cart cart.GetParts(); ViewBag.showTotal = true; ViewBag.cart = cart; ViewBag.message = 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(); }
public ActionResult Authorize() { HttpContext ctx = System.Web.HttpContext.Current; Customer customer = new Customer(); Settings settings = ViewBag.settings; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); if (!customer.Cart.Validate()) { return RedirectToAction("Index", "Cart"); } if (customer.Cart.GetPaymentID() > 0) { UDF.ExpireCart(ctx, customer.ID); return RedirectToAction("Index", "Cart"); } customer.BindAddresses(); decimal amount = customer.Cart.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(customer.ID.ToString(), first, last, customer.Cart.Billing.street1 + ((customer.Cart.Billing.street2 != "") ? " " + customer.Cart.Billing.street2 : ""), customer.Cart.Billing.State1.abbr, customer.Cart.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(customer.ID.ToString(), customer.Cart.Shipping.first, customer.Cart.Shipping.last, customer.Cart.Shipping.street1 + ((customer.Cart.Shipping.street2 != "") ? " " + customer.Cart.Shipping.street2 : ""), customer.Cart.Shipping.State1.abbr, customer.Cart.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); customer.Cart.SetStatus((int)OrderStatuses.PaymentPending); //step 3 - make some money IGatewayResponse response = gate.Send(request); if (response.Approved) { customer.Cart.AddPayment("credit card", response.AuthorizationCode, "Complete"); customer.Cart.SetStatus((int)OrderStatuses.PaymentComplete); customer.Cart.SendConfirmation(ctx); customer.Cart.SendInternalOrderEmail(ctx); int cartid = customer.Cart.ID; Cart new_cart = new Cart().Save(); new_cart.UpdateCart(ctx, customer.ID); DateTime cookexp = Request.Cookies["hdcart"].Expires; HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString()); cook.Expires = cookexp; Response.Cookies.Add(cook); customer.Cart = new_cart; customer.Cart.BindAddresses(); return RedirectToAction("Complete", new { id = cartid }); } else { customer.Cart.SetStatus((int)OrderStatuses.PaymentDeclined); return RedirectToAction("Index", new { message = response.Message }); } }
public async Task<ActionResult> Complete(int id = 0) { HttpContext ctx = System.Web.HttpContext.Current; Customer customer = new Customer(); ViewBag.timezone = UDF.GetTimeZone(ctx); var pcats = CURTAPI.GetParentCategoriesAsync(); await Task.WhenAll(new Task[] { pcats }); ViewBag.parent_cats = await pcats; // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(ctx); Cart order = new Cart().Get(id); order.BindAddresses(); Payment payment = order.getPayment(); ViewBag.order = order; ViewBag.payment = payment; return View(); }
public ActionResult Index(string message = "") { Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); if (!customer.LoggedIn()) { return RedirectToAction("Index", "Authenticate", new { referrer = "https://" + Request.Url.Host + "/Cart/Checkout" }); } if (customer.Cart.payment_id > 0) { UDF.ExpireCart(customer.ID); return RedirectToAction("Index", "Cart"); } // Create Cart object from customer customer.BindAddresses(); Cart cart = customer.Cart; // Get the parts from this Cart cart.GetParts(); ViewBag.showShipping = true; ViewBag.cart = cart; ViewBag.message = 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(); }
public ActionResult Complete(int id = 0) { Customer customer = new Customer(); // Retrieve Customer from Sessions/Cookie customer.GetFromStorage(); Cart order = new Cart().Get(id); if (!customer.LoggedIn() || order.cust_id != customer.ID) { return RedirectToAction("Index", "Authenticate"); } order.BindAddresses(); Payment payment = order.getPayment(); ViewBag.order = order; ViewBag.payment = payment; return View(); }