public ActionResult Details(UserAccountUpdateModel details) { User u = null; PaymentInfoSet ret = null; Tuple <bool, PaymentInfoSet> paymentInfo = null; if (details != null) { using (var repo = Resolver.Resolve <IUserRepository>()) { u = repo.Select(ApplicationContext.Current.User.Id); if (u != null) { u.Name = details.Name; u.Email = details.Email; u.CompanyName = details.CompanyName; u.CompanyAddress = details.CompanyAddress; if (u.Subscription == null) { u.Subscription = new UserSubscription(); } u.Subscription.RenewedTo = details.SubscriptionType; if (!string.IsNullOrEmpty(details.Password)) { if (u.Password == null) { u.Password = new UserPasswordDetails(); } u.Password.Hash = Crypto.GetHash(details.Password); u.Password.ResetToken = string.Empty; } paymentInfo = GetPaymentInformationInternal(u); // This won't allow the user to use the tool before he submits a payment. if (paymentInfo.Item1) { u.Subscription.Renewed = DateTime.UtcNow.AddYears(-2); } repo.Update(u); if (paymentInfo.Item1) { ret = paymentInfo.Item2; } // Updating subscription type for all user presentations. UpdatePresentationSubscriptionType(u.Id, u.Subscription.Type); } } } return(Json(ret)); }
/// <summary> /// Returns payment information. /// </summary> /// <param name="user">User.</param> /// <returns>Payment information.</returns> private Tuple <bool, PaymentInfoSet> GetPaymentInformationInternal(User user = null) { User u = null; int chargeAmount = 0; PaymentInfoSet set = null; bool requiresPayment = false; Payments.IPaymentProcessor processor = null; if (user != null) { u = user; } else { using (var repo = Resolver.Resolve <IUserRepository>()) u = repo.Select(ApplicationContext.Current.User.Id); } if (u != null) { processor = Resolver.Resolve <Payments.IPaymentProcessor>(); // Requires payment if switching from free to any paid (no payments) or if the current paid plan is expiring. requiresPayment = u.Subscription.RenewedTo != SubscriptionType.Basic && processor.IsEnabled() && (u.Subscription.IsExpiring || !processor.HasValidPayment(u.Id, new Ifly.Payments.PaymentOptions(u.Subscription))); if (requiresPayment) { set = new PaymentInfoSet(); foreach (var duration in Enum.GetValues(typeof(SubscriptionDuration))) { chargeAmount = processor.GetChargeAmount(new Ifly.Payments.PaymentOptions(u.Subscription) { Duration = (SubscriptionDuration)duration }); set.Info.Add(new PaymentInfo() { UserId = u.Id, Amount = chargeAmount, RequiresPayment = true, Duration = (SubscriptionDuration)duration, SubscriptionType = u.Subscription.RenewedTo, Description = GetChargeDescription(new Ifly.Payments.PaymentOptions(u.Subscription.RenewedTo, (SubscriptionDuration)duration), chargeAmount), }); } } } return(new Tuple <bool, PaymentInfoSet>(requiresPayment, set)); }