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)); }
public virtual ActionResult ProcessNextPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments)) { return(AccessDeniedView()); } var payment = _subscriptionService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } try { var errors = _subscriptionProcessingService.ProcessNextRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); if (errors.Any()) { errors.ToList().ForEach(error => ErrorNotification(error, false)); } else { SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.NextPaymentProcessed"), false); } //selected tab SaveSelectedTabName(persistForTheNextRequest: false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment); ErrorNotification(exc, false); //selected tab SaveSelectedTabName(persistForTheNextRequest: false); return(View(model)); } }