Пример #1
0
        public ActionResult Checkout(CheckoutViewModel model)
        {
            CartViewModel cart = GetCartWithTruePrice();

            if (cart.HasInvalidQuantity())
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                List <Item> items = new List <Item>();
                foreach (var item in cart.ListItem)
                {
                    items.Add(new Item()
                    {
                        name     = item.Name,
                        currency = "USD",
                        price    = item.GetPriceAfterDiscount().ToString(),
                        quantity =
                            item.Quantity.ToString(),
                    });
                }

                var paymentParam = new PaypalPaymentService.PaypalPaymentParam()
                {
                    Session     = Session,
                    CallbackUrl = Request.Url.Scheme + "://" + Request.Url.Authority + "/Cart/PaymentCallback",
                    Items       = items
                };
                string url = PaymentService.SendPayment(paymentParam);
                if (url == "NG")
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                // Credit card here
                Session["Cart"] = cart;
                Session["CheckoutViewModel"] = model;

                return(Redirect(url));
            }
            ViewBag.cart = cart;

            return(View(model));
        }