コード例 #1
0
        public virtual ActionResult CancelRecurringPayment(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.CancelRecurringPayment(payment);
                var model  = new RecurringPaymentModel();
                PrepareRecurringPaymentModel(model, payment);
                if (errors.Any())
                {
                    foreach (var error in errors)
                    {
                        ErrorNotification(error, false);
                    }
                }
                else
                {
                    SuccessNotification(_localizationService.GetResource("Admin.RecurringPayments.Cancelled"), 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));
            }
        }
コード例 #2
0
        public virtual ActionResult CancelRecurringPayment(FormCollection form)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new HttpUnauthorizedResult());
            }

            //get recurring payment identifier
            int recurringPaymentId = 0;

            foreach (var formValue in form.AllKeys)
            {
                if (formValue.StartsWith("cancelRecurringPayment", StringComparison.InvariantCultureIgnoreCase))
                {
                    recurringPaymentId = Convert.ToInt32(formValue.Substring("cancelRecurringPayment".Length));
                }
            }

            var recurringPayment = _subscriptionService.GetRecurringPaymentById(recurringPaymentId);

            if (recurringPayment == null)
            {
                return(RedirectToRoute("CustomerSubscriptions"));
            }

            if (_subscriptionProcessingService.CanCancelRecurringPayment(_workContext.CurrentCustomer, recurringPayment))
            {
                var errors = _subscriptionProcessingService.CancelRecurringPayment(recurringPayment);

                var model = _subscriptionModelFactory.PrepareCustomerSubscriptionListModel();
                model.RecurringPaymentErrors = errors;

                return(View(model));
            }
            else
            {
                return(RedirectToRoute("CustomerSubscriptions"));
            }
        }