public virtual IActionResult RetryLastRecurringPayment(IFormCollection form) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } //get recurring payment identifier var recurringPaymentId = 0; if (!form.Keys.Any(formValue => formValue.StartsWith("retryLastPayment", StringComparison.InvariantCultureIgnoreCase) && int.TryParse(formValue.Substring(formValue.IndexOf('_') + 1), out recurringPaymentId))) { return(RedirectToRoute("CustomerOrders")); } var recurringPayment = _orderService.GetRecurringPaymentById(recurringPaymentId); if (recurringPayment == null) { return(RedirectToRoute("CustomerOrders")); } if (!_orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment)) { return(RedirectToRoute("CustomerOrders")); } var errors = _orderProcessingService.ProcessNextRecurringPayment(recurringPayment); var model = _orderModelFactory.PrepareCustomerOrderListModel(); model.RecurringPaymentErrors = errors.ToList(); return(View(model)); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel() { var model = new CustomerOrderListModel(); var orders = _orderService.SearchOrders(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext), IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), CustomOrderNumber = order.CustomOrderNumber, // ++ CanCancelOrderForCustomer CanCancelOrder = _orderProcessingService.CanCancelOrderForCustomer(order), }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); model.Orders.Add(orderModel); } var recurringPayments = _orderService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { Id = recurringPayment.Id, StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(), CycleInfo = $"{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, InitialOrderId = recurringPayment.InitialOrder.Id, InitialOrderNumber = recurringPayment.InitialOrder.CustomOrderNumber, CanCancel = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } return(model); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel(int?page) { var model = new CustomerOrderListModel(); var pageSize = 5; var orders = _orderService.SearchOrders(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id, pageIndex: --page ?? 0, pageSize: pageSize); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = _localizationService.GetLocalizedEnum(order.OrderStatus), PaymentStatus = _localizationService.GetLocalizedEnum(order.PaymentStatus), ShippingStatus = _localizationService.GetLocalizedEnum(order.ShippingStatus), IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), CustomOrderNumber = order.CustomOrderNumber }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); model.Orders.Add(orderModel); } model.PagerModel = new PagerModel { PageSize = orders.PageSize, TotalRecords = orders.TotalCount, PageIndex = orders.PageIndex, ShowTotalSummary = false, RouteActionName = "CustomerOrdersListPaged", UseRouteLinks = true, RouteValues = new OrdersListRouteValues { pageNumber = page ?? 0 } }; var recurringPayments = _orderService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { Id = recurringPayment.Id, StartDate = _dateTimeHelper.ConvertToUserTime(recurringPayment.StartDateUtc, DateTimeKind.Utc).ToString(), CycleInfo = $"{recurringPayment.CycleLength} {_localizationService.GetLocalizedEnum(recurringPayment.CyclePeriod)}", NextPayment = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : "", TotalCycles = recurringPayment.TotalCycles, CyclesRemaining = recurringPayment.CyclesRemaining, InitialOrderId = recurringPayment.InitialOrder.Id, InitialOrderNumber = recurringPayment.InitialOrder.CustomOrderNumber, CanCancel = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } return(model); }
/// <summary> /// Prepare the customer order list model /// </summary> /// <returns>Customer order list model</returns> public virtual CustomerOrderListModel PrepareCustomerOrderListModel(string status, int?page, int?pageSize) { if (page == 0) { page = null; } List <int> statusList = new List <int>(); if (!string.IsNullOrEmpty(status)) { if (status == ((int)OrderStatus.Cancelled).ToString()) { statusList.Add((int)OrderStatus.Cancelled); } if (status == ((int)OrderStatus.Pending).ToString()) { statusList.Add((int)OrderStatus.Pending); statusList.Add((int)OrderStatus.Processing); } } var model = new CustomerOrderListModel(); var orders = _orderService.SearchOrders(storeId: _storeContext.CurrentStore.Id, customerId: _workContext.CurrentCustomer.Id, osIds: statusList); //pageIndex: --page ?? 0, pageSize: 5, List <CustomerOrderListModel.OrderDetailsModel> allOrders = new List <CustomerOrderListModel.OrderDetailsModel>(); foreach (var order in orders) { var orderModel = new CustomerOrderListModel.OrderDetailsModel { Id = order.Id, CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc), OrderStatusEnum = order.OrderStatus, OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext), PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext), ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext), IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order), CustomOrderNumber = order.CustomOrderNumber }; var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); orderModel.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage); allOrders.Add(orderModel); } List <CustomerOrderListModel.OrderDetailsModel> legacyOrders = null; var miscPlugins = _pluginFinder.GetPlugins <MyOrderServicePlugin>(storeId: EngineContext.Current.Resolve <IStoreContext>().CurrentStore.Id).ToList(); if (miscPlugins.Count > 0 && _gbsOrderSettings.LegacyOrdersInOrderHistory) { legacyOrders = new Orders.OrderExtensions().getLegacyOrders(); if (!string.IsNullOrEmpty(status)) { legacyOrders = legacyOrders.Where(x => statusList.Contains((int)x.OrderStatusEnum)).ToList(); } if (legacyOrders != null && legacyOrders.Count() > 0) { allOrders.AddRange(legacyOrders); } allOrders.Sort((x, y) => y.CreatedOn.CompareTo(x.CreatedOn)); } var ordersPaging = new PagedList <CustomerOrderListModel.OrderDetailsModel>(allOrders, pageIndex: --page ?? 0, pageSize: pageSize ?? 5); model.Orders = ordersPaging.ToList(); // do paging on orders var recurringPayments = _orderService.SearchRecurringPayments(_storeContext.CurrentStore.Id, _workContext.CurrentCustomer.Id); foreach (var recurringPayment in recurringPayments) { var recurringPaymentModel = new CustomerOrderListModel.RecurringOrderModel { 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, InitialOrderId = recurringPayment.InitialOrder.Id, InitialOrderNumber = recurringPayment.InitialOrder.CustomOrderNumber, CanCancel = _orderProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment), CanRetryLastPayment = _orderProcessingService.CanRetryLastRecurringPayment(_workContext.CurrentCustomer, recurringPayment) }; model.RecurringOrders.Add(recurringPaymentModel); } model.CustomProperties["PagerModel"] = new PagerModel { PageSize = ordersPaging.PageSize, TotalRecords = ordersPaging.TotalCount, PageIndex = ordersPaging.PageIndex, ShowTotalSummary = true, RouteActionName = "CustomerOrders", UseRouteLinks = true, RouteValues = new OrderRouteValues { page = page ?? 0, status = status, pageSize = pageSize } }; if (model.Orders.Any()) { model.Orders.FirstOrDefault().CustomProperties["PagerModel"] = new PagerModel { PageSize = ordersPaging.PageSize, TotalRecords = ordersPaging.TotalCount, PageIndex = ordersPaging.PageIndex, ShowTotalSummary = true, RouteActionName = "CustomerOrders", UseRouteLinks = true, RouteValues = new OrderRouteValues { page = page ?? 0, status = status, pageSize = pageSize } }; } return(model); }
/// <summary> /// Gets a value indicating whether a customer can retry last failed recurring payment /// </summary> /// <param name="customer">Customer</param> /// <param name="recurringPayment">Recurring Payment</param> /// <returns>True if a customer can retry payment; otherwise false</returns> public bool CanRetryLastRecurringPayment(Customer customer, RecurringPayment recurringPayment) { return(_orderProcessingService.CanRetryLastRecurringPayment(customer, recurringPayment)); }