/// <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);
        }
        public IViewComponentResult Invoke()
        {
            var cart = _payPalExpressCheckoutService.GetCart();

            if (cart.Count == 0)
            {
                return(Content(string.Empty));
            }

            var minOrderSubtotalAmountOk = _orderProcessingService.ValidateMinOrderSubtotalAmount(cart);

            if (!minOrderSubtotalAmountOk)
            {
                return(Content(string.Empty));
            }

            var filterByCountryId = 0;

            if (_addressSettings.CountryEnabled && _workContext.CurrentCustomer.BillingAddress?.Country != null)
            {
                filterByCountryId = _workContext.CurrentCustomer.BillingAddress.Country.Id;
            }

            var plugin = _paymentPluginManager.LoadPluginBySystemName("Payments.PayPalExpressCheckout");

            if (plugin == null || _paymentPluginManager.GetRestrictedCountryIds(plugin).Contains(filterByCountryId))
            {
                return(Content(string.Empty));
            }

            var model = new PaymentInfoModel
            {
                ButtonImageLocation = "https://paypalobjects.com/en_GB/i/btn/btn_xpressCheckout.gif"
            };

            return(View("~/Plugins/Payments.PayPalExpressCheckout/Views/PaymentInfo.cshtml", model));
        }
Ejemplo n.º 3
0
        public IViewComponentResult Invoke()
        {
            var cart = _payPalExpressCheckoutService.GetCart();

            if (cart.Count == 0)
            {
                return(Content(string.Empty));
            }

            if (!_orderProcessingService.ValidateMinOrderSubtotalAmount(cart))
            {
                return(Content(string.Empty));
            }

            var filterByCountryId = 0;
            var billingAddress    = _addressService.GetAddressById(_workContext.CurrentCustomer.BillingAddressId ?? 0);

            if (_addressSettings.CountryEnabled && billingAddress?.CountryId != null)
            {
                filterByCountryId = billingAddress.CountryId.Value;
            }

            var plugin = _paymentPluginManager.LoadPluginBySystemName("Payments.PayPalExpressCheckout");

            if (plugin == null || _paymentPluginManager.GetRestrictedCountryIds(plugin).Contains(filterByCountryId))
            {
                return(Content(string.Empty));
            }

            var model = new PaymentInfoModel
            {
                ButtonImageLocation = Defaults.CheckoutButtonImageUrl
            };

            return(View("~/Plugins/Payments.PayPalExpressCheckout/Views/PaymentInfo.cshtml", model));
        }