public ViewResult Checkout(Cart cart, Order order) { if (cart.Lines.Count() == 0) ModelState.AddModelError("", CartStrings.Your_cart_is_empty); if (ModelState.IsValid) { orderProcessor.ProcessOrder(cart, order); cart.Clear(); return View("Completed"); } else { ViewBag.Shippers = repository.Shippers; return View(order); } }
public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails) { if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Sorry your cat is empty"); } if (ModelState.IsValid) { orderProcessor.ProcessorOrder(cart, shippingDetails); cart.Clear(); return View("Completed"); } else { return View(shippingDetails); } }
public ViewResult Checkout(Cart cart, Order order) { if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Извините, ваша корзина пуста!"); } if (ModelState.IsValid) { orderProcessor.ProcessOrder(cart, order); cart.Clear(); return View("Completed"); } else { return View(order); } }
public ActionResult PaymentWithPaypal(Cart cart) { ShippingDetails shippingDetails = (ShippingDetails)TempData["shipping_details"]; //getting the apiContext as earlier APIContext apiContext = PaypalConfiguration.GetAPIContext(); try { string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { //this section will be executed first because PayerID doesn't exist //it is returned by the create function call of the payment class // Creating a payment // baseURL is the url on which paypal sendsback the data. // So we have provided URL of this controller only string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/PaymentWithPayPal?"; //guid we are generating for storing the paymentID received in session //after calling the create function and it is used in the payment execution var guid = Convert.ToString((new Random()).Next(100000)); var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = baseURI + "guid=" + guid, return_url = baseURI + "guid=" + guid }; List<Transaction> transactions = GenerateteTransactions(cart); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment payment = new Payment() { intent = "sale", payer = payer, transactions = transactions, redirect_urls = redirUrls }; var createdPayment = payment.Create(apiContext); //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { //saving the payapalredirect URL to which user will be redirected for payment paypalRedirectUrl = lnk.href; } } // saving the paymentID in the key guid Session.Add(guid, createdPayment.id); return Redirect(paypalRedirectUrl); } else { // This section is executed when we have received all the payments parameters // from the previous call to the function Create // Executing a payment var guid = Request.Params["guid"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); if (executedPayment.state.ToLower() != "approved") { return View("Failure"); } } } catch (Exception ex) { Log.Error(ex); return View("Failure"); } orderProcessor.ProcessOrder(cart, shippingDetails); cart.Clear(); return View("Success"); }