public virtual ActionResult ProcessPayPal(string token, string payerId)
        {
            var order = _context.Orders
                        .Where(x => x.PayPalToken == token && x.OrderedForId == CurrentUserId)
                        .FirstOrDefault();

            if (order == null || order.OrderStatus != DomainModel.Enums.OrderStatus.AwaitingPayment)
            {
                return(RedirectToAction(MVC.Home.Index()));
            }

            // Perform the payment
            string transactionId = ProcessPaypalTransaction(token, payerId, order.TotalPrice);

            order.PayPalTransactionId = transactionId;
            order.OrderStatus         = OrderStatus.Completed;
            _context.SaveChanges();

            var utils = new OrderUtils(_context, CurrentUserId);

            utils.ActivateOrderedLicenses(order);
            string license = utils.GetLicenseDescription(order.FillPerfectLicenses.First().LicenseType);

            return(RedirectToAction(MVC.Products.FillPerfect.LicenseActivated(
                                        (Guid)_context.Users.Find(order.OrderedForId).FillPerfectKey,
                                        order.FillPerfectLicenses.First().EffectiveDate,
                                        order.FillPerfectLicenses.First().ExpirationDate,
                                        license)));
        }
        public virtual ActionResult Confirm(OrderConfirmViewModel model)
        {
            var orderUtils = new OrderUtils(_context, CurrentUserId);

            if (!model.OrderConfirmed)
            {
                // Regenerate the model
                model = orderUtils.GetConfirmModel(model.ProductId);
                ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license");
                return View(model);
            }

            var createdOrder = orderUtils.CreateOrder(model.ProductId);
            if (createdOrder.OrderStatus == OrderStatus.AwaitingPayment)
                return RedirectToAction(MVC.Products.Pay.Index(createdOrder.Id));

            else if (createdOrder.OrderStatus != OrderStatus.Completed)
                throw new InvalidOperationException(
                    string.Format("Order status of {0} is not supported", createdOrder.OrderStatus.ToString()));

            // Order was completed as it was free
            orderUtils.ActivateOrderedLicenses(createdOrder);
            string LicenseType = orderUtils.GetLicenseDescription(createdOrder.FillPerfectLicenses.First().LicenseType);
           
            return RedirectToAction(
                MVC.Products.FillPerfect.LicenseActivated(
                    (Guid)_context.Users.Find(createdOrder.OrderedForId).FillPerfectKey,
                    createdOrder.FillPerfectLicenses.First().EffectiveDate,
                    createdOrder.FillPerfectLicenses.First().ExpirationDate,
                    LicenseType));
        }
Exemple #3
0
        public virtual ActionResult Confirm(OrderConfirmViewModel model)
        {
            var orderUtils = new OrderUtils(_context, CurrentUserId);

            if (!model.OrderConfirmed)
            {
                // Regenerate the model
                model = orderUtils.GetConfirmModel(model.ProductId);
                ModelState.AddModelError("OrderConfirmed", "You must check the confirmation box to activate this license");
                return(View(model));
            }

            var createdOrder = orderUtils.CreateOrder(model.ProductId);

            if (createdOrder.OrderStatus == OrderStatus.AwaitingPayment)
            {
                return(RedirectToAction(MVC.Products.Pay.Index(createdOrder.Id)));
            }

            else if (createdOrder.OrderStatus != OrderStatus.Completed)
            {
                throw new InvalidOperationException(
                          string.Format("Order status of {0} is not supported", createdOrder.OrderStatus.ToString()));
            }

            // Order was completed as it was free
            orderUtils.ActivateOrderedLicenses(createdOrder);
            string LicenseType = orderUtils.GetLicenseDescription(createdOrder.FillPerfectLicenses.First().LicenseType);

            return(RedirectToAction(
                       MVC.Products.FillPerfect.LicenseActivated(
                           (Guid)_context.Users.Find(createdOrder.OrderedForId).FillPerfectKey,
                           createdOrder.FillPerfectLicenses.First().EffectiveDate,
                           createdOrder.FillPerfectLicenses.First().ExpirationDate,
                           LicenseType)));
        }