public virtual ActionResult RetryLastRecurringPayment(FormCollection form) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } //get recurring payment identifier var recurringPaymentId = 0; if (!form.AllKeys.Any(formValue => formValue.StartsWith("retryLastPayment", StringComparison.InvariantCultureIgnoreCase) && int.TryParse(formValue.Substring(formValue.IndexOf('_') + 1), out recurringPaymentId))) { return(RedirectToRoute("CustomerSubscriptions")); } var recurringPayment = _subscriptionService.GetRecurringPaymentById(recurringPaymentId); if (recurringPayment == null) { return(RedirectToRoute("CustomerSubscriptions")); } if (!_subscriptionProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment)) { return(RedirectToRoute("CustomerSubscriptions")); } var errors = _subscriptionProcessingService.ProcessNextRecurringPayment(recurringPayment); var model = _subscriptionModelFactory.PrepareCustomerSubscriptionListModel(); model.RecurringPaymentErrors = errors.ToList(); return(View(model)); }
/// <summary> /// Prepare the customer subscription list model /// </summary> /// <returns>Customer subscription list model</returns> public virtual CustomerSubscriptionListModel PrepareCustomerSubscriptionListModel() { var model = new CustomerSubscriptionListModel(); var subscriptions = _subscriptionService.SearchSubscriptions(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id); foreach (var subscription in subscriptions) { var subscriptionModel = new CustomerSubscriptionListModel.SubscriptionDetailsModel { Id = subscription.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(subscription.CreatedOnUtc, DateTimeKind.Utc), SubscriptionStatusEnum = subscription.SubscriptionStatus, SubscriptionStatus = subscription.SubscriptionStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = subscription.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), IsReturnRequestAllowed = _subscriptionProcessingService.IsReturnRequestAllowed(subscription), CustomSubscriptionNumber = subscription.CustomSubscriptionNumber }; var subscriptionTotalInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionTotal, subscription.CurrencyRate); subscriptionModel.SubscriptionTotal = _priceFormatter.FormatPrice(subscriptionTotalInCustomerCurrency, true, subscription.CustomerCurrencyCode, false, _workContext.WorkingLanguage); model.Subscriptions.Add(subscriptionModel); } var recurringPayments = _subscriptionService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerSubscriptionListModel.RecurringSubscriptionModel { Id = recurringPayment.Id, StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(), CycleInfo = string.Format("{0} {1}", recurringPayment.CycleLength, recurringPayment.CyclePeriod.GetLocalizedEnum(_localizationService, _workContext)), NextPayment = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : "", TotalCycles = recurringPayment.TotalCycles, CyclesRemaining = recurringPayment.CyclesRemaining, InitialSubscriptionId = recurringPayment.InitialSubscription.Id, InitialSubscriptionNumber = recurringPayment.InitialSubscription.CustomSubscriptionNumber, CanCancel = _subscriptionProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _subscriptionProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringSubscriptions.Add(recurringPaymentModel); } return(model); }