public ActionResult CancelRecurringPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) //No recurring payment found with the specified id return RedirectToAction("List"); try { var errors = _orderProcessingService.CancelRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); if (errors.Count > 0) { foreach (var error in errors) NotifyError(error, false); } else NotifySuccess(_localizationService.GetResource("Admin.RecurringPayments.Cancelled"), false); return View(model); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); NotifyError(exc, false); return View(model); } }
private void PrepareRecurringPaymentModel(RecurringPaymentModel model, RecurringPayment recurringPayment, bool includeHistory) { if (model == null) throw new ArgumentNullException("model"); if (recurringPayment == null) throw new ArgumentNullException("recurringPayment"); model.Id = recurringPayment.Id; model.CycleLength = recurringPayment.CycleLength; model.CyclePeriodId = recurringPayment.CyclePeriodId; model.CyclePeriodStr = recurringPayment.CyclePeriod.GetLocalizedEnum(_localizationService, _workContext); model.TotalCycles = recurringPayment.TotalCycles; model.StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(); model.IsActive = recurringPayment.IsActive; model.NextPaymentDate = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : ""; model.CyclesRemaining = recurringPayment.CyclesRemaining; model.InitialOrderId = recurringPayment.InitialOrder.Id; var customer = recurringPayment.InitialOrder.Customer; model.CustomerId = customer.Id; model.CustomerEmail = customer.IsGuest() ? _localizationService.GetResource("Admin.Customers.Guest") : customer.Email; model.PaymentType = _paymentService.GetRecurringPaymentType(recurringPayment.InitialOrder.PaymentMethodSystemName).GetLocalizedEnum(_localizationService, _workContext); model.CanCancelRecurringPayment = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment); if (includeHistory) foreach (var rph in recurringPayment.RecurringPaymentHistory.OrderBy(x => x.CreatedOnUtc)) { var rphModel = new RecurringPaymentModel.RecurringPaymentHistoryModel(); PrepareRecurringPaymentHistoryModel(rphModel, rph); model.History.Add(rphModel); } }
private void PrepareRecurringPaymentHistoryModel(RecurringPaymentModel.RecurringPaymentHistoryModel model, RecurringPaymentHistory history) { if (model == null) throw new ArgumentNullException("model"); if (history == null) throw new ArgumentNullException("history"); var order = _orderService.GetOrderById(history.OrderId); model.Id = history.Id; model.OrderId = history.OrderId; model.RecurringPaymentId = history.RecurringPaymentId; model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext); model.PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext); model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(history.CreatedOnUtc, DateTimeKind.Utc); }
public ActionResult List(GridCommand command) { var gridModel = new GridModel<RecurringPaymentModel>(); if (_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) { var payments = _orderService.SearchRecurringPayments(0, 0, 0, null, true); gridModel.Data = payments.PagedForCommand(command).Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x, false); return m; }); gridModel.Total = payments.Count; } else { gridModel.Data = Enumerable.Empty<RecurringPaymentModel>(); NotifyAccessDenied(); } return new JsonResult { Data = gridModel }; }
public ActionResult Edit(RecurringPaymentModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var payment = _orderService.GetRecurringPaymentById(model.Id); if (payment == null || payment.Deleted) //No recurring payment found with the specified id return RedirectToAction("List"); payment.CycleLength = model.CycleLength; payment.CyclePeriodId = model.CyclePeriodId; payment.TotalCycles = model.TotalCycles; payment.IsActive = model.IsActive; _orderService.UpdateRecurringPayment(payment); NotifySuccess(_localizationService.GetResource("Admin.RecurringPayments.Updated")); return continueEditing ? RedirectToAction("Edit", payment.Id) : RedirectToAction("List"); }
public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var payment = _orderService.GetRecurringPaymentById(id); if (payment == null || payment.Deleted) //No recurring payment found with the specified id return RedirectToAction("List"); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); return View(model); }
public ActionResult List(GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var payments = _orderService.SearchRecurringPayments(0, 0, 0, null, true); var gridModel = new GridModel<RecurringPaymentModel> { Data = payments.PagedForCommand(command).Select(x => { var m = new RecurringPaymentModel(); PrepareRecurringPaymentModel(m, x, false); return m; }), Total = payments.Count, }; return new JsonResult { Data = gridModel }; }
public ActionResult ProcessNextPayment(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders)) return AccessDeniedView(); var payment = _orderService.GetRecurringPaymentById(id); if (payment == null) //No recurring payment found with the specified id return RedirectToAction("List"); ViewData["selectedTab"] = "history"; try { _orderProcessingService.ProcessNextRecurringPayment(payment); var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); NotifySuccess(_localizationService.GetResource("Admin.RecurringPayments.NextPaymentProcessed"), false); return View(model); } catch (Exception exc) { //error var model = new RecurringPaymentModel(); PrepareRecurringPaymentModel(model, payment, true); NotifyError(exc, false); return View(model); } }