public async Task <IActionResult> MethodRestrictions()
        {
            var model          = new PaymentMethodRestrictionModel();
            var paymentMethods = _paymentService.LoadAllPaymentMethods();
            var countries      = await _countryService.GetAllCountries(showHidden : true);

            var shippings = await _shippingMethodService.GetAllShippingMethods();

            foreach (var pm in paymentMethods)
            {
                model.AvailablePaymentMethods.Add(await pm.ToModel());
            }
            foreach (var c in countries)
            {
                model.AvailableCountries.Add(c.ToModel());
            }
            foreach (var s in shippings)
            {
                model.AvailableShippingMethods.Add(new Models.Shipping.ShippingMethodModel()
                {
                    Id   = s.Id,
                    Name = s.Name
                });
            }

            foreach (var pm in paymentMethods)
            {
                var restictedCountries = _paymentService.GetRestrictedCountryIds(pm);
                foreach (var c in countries)
                {
                    bool resticted = restictedCountries.Contains(c.Id);
                    if (!model.Resticted.ContainsKey(pm.SystemName))
                    {
                        model.Resticted[pm.SystemName] = new Dictionary <string, bool>();
                    }
                    model.Resticted[pm.SystemName][c.Id] = resticted;
                }

                var restictedShipping = _paymentService.GetRestrictedShippingIds(pm);
                foreach (var s in shippings)
                {
                    bool resticted = restictedShipping.Contains(s.Name);
                    if (!model.RestictedShipping.ContainsKey(pm.SystemName))
                    {
                        model.RestictedShipping[pm.SystemName] = new Dictionary <string, bool>();
                    }
                    model.RestictedShipping[pm.SystemName][s.Name] = resticted;
                }
            }

            return(View(model));
        }
Example #2
0
        public ActionResult MethodRestrictions()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            var model = new PaymentMethodRestrictionModel();

            var paymentMethods = _paymentService.LoadAllPaymentMethods();
            var countries      = _countryService.GetAllCountries(true);

            foreach (var pm in paymentMethods)
            {
                model.AvailablePaymentMethods.Add(pm.ToModel());
            }
            foreach (var c in countries)
            {
                model.AvailableCountries.Add(c.ToModel());
            }
            foreach (var pm in paymentMethods)
            {
                var restictedCountries = _paymentService.GetRestictedCountryIds(pm);
                foreach (var c in countries)
                {
                    bool resticted = restictedCountries.Contains(c.Id);
                    if (!model.Resticted.ContainsKey(pm.PluginDescriptor.SystemName))
                    {
                        model.Resticted[pm.PluginDescriptor.SystemName] = new Dictionary <int, bool>();
                    }
                    model.Resticted[pm.PluginDescriptor.SystemName][c.Id] = resticted;
                }
            }

            return(View(model));
        }
Example #3
0
        /// <summary>
        /// Prepare payment method restriction model
        /// </summary>
        /// <param name="model">Payment method restriction model</param>
        /// <returns>Payment method restriction model</returns>
        public virtual PaymentMethodRestrictionModel PreparePaymentMethodRestrictionModel(PaymentMethodRestrictionModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var countries = _countryService.GetAllCountries(showHidden: true);

            model.AvailableCountries = countries.Select(country => country.ToModel <CountryModel>()).ToList();

            foreach (var method in _paymentService.LoadAllPaymentMethods())
            {
                model.AvailablePaymentMethods.Add(method.ToPluginModel <PaymentMethodModel>());

                var restrictedCountries = _paymentService.GetRestictedCountryIds(method);
                foreach (var country in countries)
                {
                    if (!model.Resticted.ContainsKey(method.PluginDescriptor.SystemName))
                    {
                        model.Resticted[method.PluginDescriptor.SystemName] = new Dictionary <int, bool>();
                    }

                    model.Resticted[method.PluginDescriptor.SystemName][country.Id] = restrictedCountries.Contains(country.Id);
                }
            }

            return(model);
        }
        /// <summary>
        /// Prepare payment method restriction model
        /// </summary>
        /// <param name="model">Payment method restriction model</param>
        /// <returns>Payment method restriction model</returns>
        public virtual PaymentMethodRestrictionModel PreparePaymentMethodRestrictionModel(PaymentMethodRestrictionModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var countries = _countryService.GetAllCountries(showHidden: true);

            model.AvailableCountries = countries.Select(country =>
            {
                var countryModel            = country.ToModel <CountryModel>();
                countryModel.NumberOfStates = country.StateProvinces?.Count ?? 0;

                return(countryModel);
            }).ToList();

            foreach (var method in _paymentPluginManager.LoadAllPlugins())
            {
                var paymentMethodModel = method.ToPluginModel <PaymentMethodModel>();
                paymentMethodModel.RecurringPaymentType = _localizationService.GetLocalizedEnum(method.RecurringPaymentType);

                model.AvailablePaymentMethods.Add(paymentMethodModel);

                var restrictedCountries = _paymentPluginManager.GetRestrictedCountryIds(method);
                foreach (var country in countries)
                {
                    if (!model.Restricted.ContainsKey(method.PluginDescriptor.SystemName))
                    {
                        model.Restricted[method.PluginDescriptor.SystemName] = new Dictionary <int, bool>();
                    }

                    model.Restricted[method.PluginDescriptor.SystemName][country.Id] = restrictedCountries.Contains(country.Id);
                }
            }

            return(model);
        }
Example #5
0
        public ActionResult MethodRestrictions()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            var model = new PaymentMethodRestrictionModel();

            var paymentMethods = _paymentService.LoadAllPaymentMethods();
            var countries      = _countryService.GetAllCountries(showHidden: true);
            var customerroles  = _customerService.GetAllCustomerRoles(showHidden: true);
            var shippings      = _shippingService.GetAllShippingMethods();

            foreach (var pm in paymentMethods)
            {
                model.AvailablePaymentMethods.Add(pm.ToModel());
            }
            foreach (var c in countries)
            {
                model.AvailableCountries.Add(c.ToModel());
            }
            foreach (var r in customerroles)
            {
                model.AvailableCustomerRoles.Add(r.ToModel());
            }
            foreach (var s in shippings)
            {
                model.AvailableShippingMethods.Add(new Models.Shipping.ShippingMethodModel()
                {
                    Id   = s.Id,
                    Name = s.Name
                });
            }

            foreach (var pm in paymentMethods)
            {
                var restictedCountries = _paymentService.GetRestictedCountryIds(pm);
                foreach (var c in countries)
                {
                    bool resticted = restictedCountries.Contains(c.Id);
                    if (!model.Resticted.ContainsKey(pm.PluginDescriptor.SystemName))
                    {
                        model.Resticted[pm.PluginDescriptor.SystemName] = new Dictionary <string, bool>();
                    }
                    model.Resticted[pm.PluginDescriptor.SystemName][c.Id] = resticted;
                }

                var restictedRoles = _paymentService.GetRestictedRoleIds(pm);
                foreach (var r in customerroles)
                {
                    bool resticted = restictedRoles.Contains(r.Id);
                    if (!model.RestictedRole.ContainsKey(pm.PluginDescriptor.SystemName))
                    {
                        model.RestictedRole[pm.PluginDescriptor.SystemName] = new Dictionary <string, bool>();
                    }
                    model.RestictedRole[pm.PluginDescriptor.SystemName][r.Id] = resticted;
                }

                var restictedShipping = _paymentService.GetRestictedShippingIds(pm);
                foreach (var s in shippings)
                {
                    bool resticted = restictedShipping.Contains(s.Name);
                    if (!model.RestictedShipping.ContainsKey(pm.PluginDescriptor.SystemName))
                    {
                        model.RestictedShipping[pm.PluginDescriptor.SystemName] = new Dictionary <string, bool>();
                    }
                    model.RestictedShipping[pm.PluginDescriptor.SystemName][s.Name] = resticted;
                }
            }

            return(View(model));
        }
Example #6
0
        /// <summary>
        /// Prepare payment method restriction model
        /// </summary>
        /// <param name="model">Payment method restriction model</param>
        /// <returns>Payment method restriction model</returns>
        protected virtual async Task <PaymentMethodRestrictionModel> PreparePaymentMethodRestrictionModelAsync(PaymentMethodRestrictionModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var countries = await _countryService.GetAllCountriesAsync(showHidden : true);

            model.AvailableCountries = await countries.SelectAwait(async country =>
            {
                var countryModel            = country.ToModel <CountryModel>();
                countryModel.NumberOfStates = (await _stateProvinceService.GetStateProvincesByCountryIdAsync(country.Id))?.Count ?? 0;

                return(countryModel);
            }).ToListAsync();

            foreach (var method in await _paymentPluginManager.LoadAllPluginsAsync())
            {
                var paymentMethodModel = method.ToPluginModel <PaymentMethodModel>();
                paymentMethodModel.RecurringPaymentType = await _localizationService.GetLocalizedEnumAsync(method.RecurringPaymentType);

                model.AvailablePaymentMethods.Add(paymentMethodModel);

                var restrictedCountries = await _paymentPluginManager.GetRestrictedCountryIdsAsync(method);

                foreach (var country in countries)
                {
                    if (!model.Restricted.ContainsKey(method.PluginDescriptor.SystemName))
                    {
                        model.Restricted[method.PluginDescriptor.SystemName] = new Dictionary <int, bool>();
                    }

                    model.Restricted[method.PluginDescriptor.SystemName][country.Id] = restrictedCountries.Contains(country.Id);
                }
            }

            return(model);
        }