public async Task <IActionResult> CancelRecurringPayment(string id) { var payment = await _orderService.GetRecurringPaymentById(id); if (payment == null) { //No recurring payment found with the specified id return(RedirectToAction("List")); } try { var errors = await _orderRecurringPayment.CancelRecurringPayment(payment); var model = new RecurringPaymentModel(); await PrepareRecurringPaymentModel(model, payment); if (errors.Count > 0) { foreach (var error in errors) { ErrorNotification(error, false); } } else { SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Cancelled"), false); } //selected tab await SaveSelectedTabIndex(persistForTheNextRequest : false); return(View(model)); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); await PrepareRecurringPaymentModel(model, payment); ErrorNotification(exc, false); //selected tab await SaveSelectedTabIndex(persistForTheNextRequest : false); return(View(model)); } }
public virtual async Task <IActionResult> CancelRecurringPayment(IFormCollection form, [FromServices] IOrderRecurringPayment orderRecurringPayment) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } //get recurring payment identifier string recurringPaymentId = ""; foreach (var formValue in form.Keys) { if (formValue.StartsWith("cancelRecurringPayment", StringComparison.OrdinalIgnoreCase)) { recurringPaymentId = formValue.Substring("cancelRecurringPayment".Length); } } var recurringPayment = await _orderService.GetRecurringPaymentById(recurringPaymentId); if (recurringPayment == null) { return(RedirectToRoute("CustomerOrders")); } if (await orderRecurringPayment.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment)) { var errors = await orderRecurringPayment.CancelRecurringPayment(recurringPayment); var model = await _mediator.Send(new GetCustomerOrderList() { Customer = _workContext.CurrentCustomer, Language = _workContext.WorkingLanguage, Store = _storeContext.CurrentStore }); model.CancelRecurringPaymentErrors = errors; return(View(model)); } else { return(RedirectToRoute("CustomerOrders")); } }