Ejemplo n.º 1
0
        public ActionResult Membership(RegisterMembershipViewModel model)
        {
            var customer = (Customer)Session["Customer"];

            if (customer.MembershipStatus != 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            else if (ModelState.IsValid)
            {
                var paymentParam = new PaypalPaymentService.PaypalPaymentParam()
                {
                    Session     = Session,
                    CallbackUrl = Request.Url.Scheme + "://" + Request.Url.Authority + "/Customer/PaymentCallback",
                    Items       = new List <Item>()
                    {
                        new Item()
                        {
                            name     = (model.MembershipType == CommonConstants.MONTHLY) ? "Monthly membership" : "Annual membership",
                            currency = "USD",
                            price    = ((model.MembershipType == CommonConstants.MONTHLY) ? CommonConstants.MONTLY_TOTAL : CommonConstants.ANNUAL_TOTAL).ToString(),
                            quantity = "1",
                        }
                    },
                    CreditCard = model.CreditCard,
                };

                if (model.PaymentMethod == "paypal")
                {
                    string url = PaymentService.SendPayment(paymentParam);
                    if (url == "NG")
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }

                    return(Redirect(url));
                }
                else
                {
                    var result = PaymentService.SendPaymentByCreditCard(paymentParam);

                    if (result != -1)
                    {
                        int customerId = ((Customer)Session["Customer"]).Id;
                        customer            = RegisterMembership(customerId, result);
                        Session["Customer"] = customer;
                        // notify.....

                        return(RedirectToAction("Membership"));
                    }
                }
            }
            customer = db.Customers.Find(customer.Id);

            return(View(customer));
        }
Ejemplo n.º 2
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));
        }