/// <summary>
        /// Returns the errors as <see cref="IList{string}"/> if plugin isn't configured; otherwise empty
        /// </summary>
        /// <param name="storeId">The store id, pass null to use id of the current store</param>
        /// <returns>The <see cref="Task"/> containing the errors as <see cref="IList{string}"/> if plugin isn't configured; otherwise empty</returns>
        public virtual async Task <(bool IsValid, IList <string> Errors)> ValidateAsync(int?storeId = null)
        {
            OpenPayPaymentSettings openPayPaymentSettings = null;

            if (!storeId.HasValue)
            {
                openPayPaymentSettings = _openPayPaymentSettings;
            }
            else
            {
                // load settings for specified store
                openPayPaymentSettings = await _settingService.LoadSettingAsync <OpenPayPaymentSettings>(storeId.Value);
            }

            var errors = new List <string>();

            // resolve validator here to exclude warnings after installation process
            var validator        = EngineContext.Current.Resolve <IValidator <ConfigurationModel> >();
            var validationResult = await validator.ValidateAsync(new ConfigurationModel
            {
                ApiToken = openPayPaymentSettings.ApiToken,
                RegionTwoLetterIsoCode = openPayPaymentSettings.RegionTwoLetterIsoCode,
                PlanTiers = openPayPaymentSettings.PlanTiers
            });

            if (!validationResult.IsValid)
            {
                errors.AddRange(validationResult.Errors.Select(error => error.ErrorMessage));
                return(false, errors);
            }

            // check the primary store currency is available
            var region = Defaults.OpenPay.AvailableRegions.FirstOrDefault(
                region => region.IsSandbox == openPayPaymentSettings.UseSandbox && region.TwoLetterIsoCode == openPayPaymentSettings.RegionTwoLetterIsoCode);

            var primaryStoreCurrency = await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId);

            if (primaryStoreCurrency.CurrencyCode != region.CurrencyCode)
            {
                var invalidCurrencyLocale = await _localizationService.GetResourceAsync("Plugins.Payments.OpenPay.InvalidCurrency");

                var invalidCurrencyMessage = string.Format(invalidCurrencyLocale, region.TwoLetterIsoCode, region.CurrencyCode);
                errors.Add(invalidCurrencyLocale);

                return(false, errors);
            }

            return(true, errors);
        }
        public BaseHttpClient(OpenPayPaymentSettings settings, HttpClient httpClient)
        {
            _httpClient = new Lazy <HttpClient>(() =>
            {
                // set default settings
                httpClient.Timeout = TimeSpan.FromSeconds(Defaults.OpenPay.Api.DefaultTimeout);
                httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, Defaults.OpenPay.Api.UserAgent);
                httpClient.DefaultRequestHeaders.Add(HeaderNames.Accept, "*/*");
                httpClient.DefaultRequestHeaders.Add(Defaults.OpenPay.Api.VersionHeaderName, Defaults.OpenPay.Api.Version);

                ConfigureClient(httpClient, settings);

                return(httpClient);
            });
        }
示例#3
0
 public WidgetViewComponent(
     OpenPayService openPayService,
     OpenPayPaymentSettings openPayPaymentSettings,
     ICurrencyService currencyService,
     IProductService productService,
     IOrderTotalCalculationService orderTotalCalculationService,
     IShoppingCartService shoppingCartService,
     IStoreContext storeContext,
     IWorkContext workContext)
 {
     _openPayService               = openPayService;
     _openPayPaymentSettings       = openPayPaymentSettings;
     _currencyService              = currencyService;
     _productService               = productService;
     _orderTotalCalculationService = orderTotalCalculationService;
     _shoppingCartService          = shoppingCartService;
     _storeContext = storeContext;
     _workContext  = workContext;
 }
 public OpenPayService(
     CustomerSettings customerSettings,
     CurrencySettings currencySettings,
     OpenPayApi openPayApi,
     OpenPayPaymentSettings openPayPaymentSettings,
     IAddressService addressService,
     IActionContextAccessor actionContextAccessor,
     ICustomerService customerService,
     ICurrencyService currencyService,
     IGenericAttributeService genericAttributeService,
     IOrderService orderService,
     IOrderTotalCalculationService orderTotalCalculationService,
     IProductService productService,
     IProductAttributeFormatter productAttributeFormatter,
     IStateProvinceService stateProvinceService,
     ISettingService settingService,
     IShoppingCartService shoppingCartService,
     ILocalizationService localizationService,
     IUrlHelperFactory urlHelperFactory,
     IWebHelper webHelper)
 {
     _customerSettings             = customerSettings;
     _currencySettings             = currencySettings;
     _openPayApi                   = openPayApi;
     _openPayPaymentSettings       = openPayPaymentSettings;
     _addressService               = addressService;
     _actionContextAccessor        = actionContextAccessor;
     _customerService              = customerService;
     _genericAttributeService      = genericAttributeService;
     _orderService                 = orderService;
     _orderTotalCalculationService = orderTotalCalculationService;
     _productService               = productService;
     _productAttributeFormatter    = productAttributeFormatter;
     _stateProvinceService         = stateProvinceService;
     _settingService               = settingService;
     _shoppingCartService          = shoppingCartService;
     _currencyService              = currencyService;
     _localizationService          = localizationService;
     _urlHelperFactory             = urlHelperFactory;
     _webHelper = webHelper;
 }
示例#5
0
 public OpenPayPaymentController(
     OpenPayApi openPayApi,
     OpenPayService openPayService,
     OpenPayPaymentSettings openPayPaymentSettings,
     IPaymentPluginManager paymentPluginManager,
     IOrderService orderService,
     IOrderProcessingService orderProcessingService,
     INotificationService notificationService,
     ILocalizationService localizationService,
     ILogger logger)
 {
     _openPayApi             = openPayApi;
     _openPayService         = openPayService;
     _openPayPaymentSettings = openPayPaymentSettings;
     _paymentPluginManager   = paymentPluginManager;
     _orderService           = orderService;
     _orderProcessingService = orderProcessingService;
     _notificationService    = notificationService;
     _localizationService    = localizationService;
     _logger = logger;
 }
 public virtual void ConfigureClient(OpenPayPaymentSettings settings)
 {
     ConfigureClient(HttpClient, settings);
 }
示例#7
0
 public OpenPayApi(OpenPayPaymentSettings settings, HttpClient httpClient)
     : base(settings, httpClient)
 {
 }