protected virtual async Task PrepareRecurringPaymentModel(RecurringPaymentModel model,
                                                                  RecurringPayment recurringPayment)
        {
            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 = await _customerService.GetCustomerById(recurringPayment.InitialOrder.CustomerId);

            model.CustomerId                = customer.Id;
            model.CustomerEmail             = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
            model.PaymentType               = _paymentService.GetRecurringPaymentType(recurringPayment.InitialOrder.PaymentMethodSystemName).GetLocalizedEnum(_localizationService, _workContext);
            model.CanCancelRecurringPayment = await _orderRecurringPayment.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment);
        }
Beispiel #2
0
        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"));
            }
        }
Beispiel #3
0
        private async Task PrepareRecurringPayments(CustomerOrderListModel model, GetCustomerOrderList request)
        {
            var recurringPayments = await _orderService.SearchRecurringPayments(request.Store.Id,
                                                                                request.Customer.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, request.Language.Id)),
                    NextPayment     = recurringPayment.NextPaymentDate.HasValue ? _dateTimeHelper.ConvertToUserTime(recurringPayment.NextPaymentDate.Value, DateTimeKind.Utc).ToString() : "",
                    TotalCycles     = recurringPayment.TotalCycles,
                    CyclesRemaining = recurringPayment.CyclesRemaining,
                    InitialOrderId  = recurringPayment.InitialOrder.Id,
                    CanCancel       = await _orderRecurringPayment.CanCancelRecurringPayment(request.Customer, recurringPayment),
                };

                model.RecurringOrders.Add(recurringPaymentModel);
            }
        }