public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //save settings _payuPaymentSettings.MerchantId = model.MerchantId; _payuPaymentSettings.Key = model.Key; _payuPaymentSettings.MerchantParam = model.MerchantParam; _payuPaymentSettings.PayUri = model.PayUri; _payuPaymentSettings.AdditionalFee = model.AdditionalFee; _payuPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; await _settingService.SaveSettingAsync(_payuPaymentSettings); //return View("Nop.Plugin.Payments.Payu.Views.PaymentPayu.Configure", model); //return View("~/Plugins/Payments.Payu/Views/PaymentPayu/Configure.cshtml", model); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(SwiperSliderConfigurationModel model) { _swiperSliderSettings.ContainerCssSelector = model.ContainerCssSelector; _swiperSliderSettings.PaginationCssSelector = model.PaginationCssSelector; _swiperSliderSettings.NavigationNextCssSelector = model.NavigationNextCssSelector; _swiperSliderSettings.NavigationPrevCssSelector = model.NavigationPrevCssSelector; _swiperSliderSettings.ScrollBarCssSelector = model.ScrollBarCssSelector; _swiperSliderSettings.Direction = (Direction)Enum.Parse(typeof(Direction), model.DirectionId.ToString()); _swiperSliderSettings.InitialSlide = model.InitialSlide; _swiperSliderSettings.Speed = model.Speed; _swiperSliderSettings.Loop = model.Loop; _swiperSliderSettings.LoopFillGroupWithBlankEnabled = model.LoopFillGroupWithBlankEnabled; _swiperSliderSettings.PaginationEnabled = model.PaginationEnabled; _swiperSliderSettings.PaginationClickableEnabled = model.PaginationClickableEnabled; _swiperSliderSettings.NavigationEnabled = model.NavigationEnabled; _swiperSliderSettings.ScrollBarEnabled = model.ScrollBarEnabled; _swiperSliderSettings.AutoPlayEnabled = model.AutoPlayEnabled; _swiperSliderSettings.AutoPlayDelay = model.AutoPlayDelay; _swiperSliderSettings.AutoPlayDisableOnInteraction = model.AutoPlayDisableOnInteraction; _swiperSliderSettings.SlidesPerGroup = model.SlidesPerGroup; _swiperSliderSettings.SpaceBetween = model.SpaceBetween; _swiperSliderSettings.SlidesPerView = model.SlidesPerView; _swiperSliderSettings.FreeModeEnabled = model.FreeModeEnabled; _swiperSliderSettings.DynamicBulletsEnabled = model.DynamicBulletsEnabled; _swiperSliderSettings.CenteredSlidesEnabled = model.CenteredSlidesEnabled; _swiperSliderSettings.CustomCss = model.CustomCss; await _settingService.SaveSettingAsync(_swiperSliderSettings); await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var paySynchronyPaymentSettings = SynchronyPaymentSettings.FromModel(model); /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(paySynchronyPaymentSettings, x => x.MerchantId, model.MerchantId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(paySynchronyPaymentSettings, x => x.MerchantPassword, model.MerchantPassword_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(paySynchronyPaymentSettings, x => x.Integration, model.Integration_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(paySynchronyPaymentSettings, x => x.TokenNumber, model.TokenNumber_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(paySynchronyPaymentSettings, x => x.WhitelistDomain, model.WhitelistDomain_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(paySynchronyPaymentSettings, x => x.IsDebugMode, model.IsDebugMode_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } var storeId = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var settings = await _settingService.LoadSettingAsync <AccessiBeSettings>(storeId); settings.Script = model.Script; await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.Script, model.Script_OverrideForStore, storeId, false); await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var comingSoonPageSettings = await _settingService.LoadSettingAsync <ComingSoonPageSettings>(storeScope); comingSoonPageSettings.BackgroundId = model.BackgroundId; comingSoonPageSettings.OpeningDate = model.OpeningDate; comingSoonPageSettings.DisplayCountdown = model.DisplayCountdown; comingSoonPageSettings.DisplayNewsletterBox = model.DisplayNewsletterBox; comingSoonPageSettings.DisplayLoginButton = model.DisplayLoginButton; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(comingSoonPageSettings, x => x.BackgroundId, model.BackgroundId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(comingSoonPageSettings, x => x.OpeningDate, model.OpeningDate_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(comingSoonPageSettings, x => x.DisplayCountdown, model.DisplayCountdown_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(comingSoonPageSettings, x => x.DisplayNewsletterBox, model.DisplayNewsletterBox_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(comingSoonPageSettings, x => x.DisplayLoginButton, model.DisplayLoginButton_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var helloWorldSettings = await _settingService.LoadSettingAsync <HelloWorldSettings>(storeScope); helloWorldSettings.Text = model.Text; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(helloWorldSettings, x => x.Text, model.Text_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Settings() { var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var apiSettings = await _settingService.LoadSettingAsync <ApiSettings>(storeScope); var model = apiSettings.ToModel(); // Store Settings model.ActiveStoreScopeConfiguration = storeScope; if (model.EnableApi_OverrideForStore || storeScope == 0) { await _settingService.SaveSettingAsync(apiSettings, x => x.EnableApi, storeScope, false); } //now clear settings cache await _settingService.ClearCacheAsync(); return(View($"~/Plugins/Nop.Plugin.Api/Areas/Admin/Views/ApiAdmin/Settings.cshtml", model)); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var payGatePaymentSettings = await _settingService.LoadSettingAsync <PayGatePaymentSettings>(storeScope); //save settings payGatePaymentSettings.TestMode = model.TestMode; payGatePaymentSettings.PayGateID = model.PayGateID; payGatePaymentSettings.EncryptionKey = model.EncryptionKey; payGatePaymentSettings.EnableIpn = model.EnableIpn; payGatePaymentSettings.EnableRedirect = model.EnableRedirect; payGatePaymentSettings.UseSSL = model.UseSSL; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync (payGatePaymentSettings, x => x.TestMode, model.TestMode_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync (payGatePaymentSettings, x => x.PayGateID, model.PayGateID_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync (payGatePaymentSettings, x => x.EncryptionKey, model.EncryptionKey_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync (payGatePaymentSettings, x => x.EnableIpn, model.EnableIpn_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync (payGatePaymentSettings, x => x.EnableRedirect, model.EnableRedirect_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync (payGatePaymentSettings, x => x.UseSSL, model.UseSSL_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!ModelState.IsValid) { return(await Configure()); } var storeId = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var sendinblueSettings = await _settingService.LoadSettingAsync <SendinblueSettings>(storeId); //set API key sendinblueSettings.ApiKey = model.ApiKey; await _settingService.SaveSettingAsync(sendinblueSettings, settings => settings.ApiKey, clearCache : false); await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var zarinPalPaymentSettings = await _settingService.LoadSettingAsync <ZarinpalPaymentSettings>(storeScope); //save settings zarinPalPaymentSettings.Method = model.Method; zarinPalPaymentSettings.UseSandbox = model.UseSandbox; zarinPalPaymentSettings.MerchantID = model.MerchantID; zarinPalPaymentSettings.RialToToman = model.RialToToman; zarinPalPaymentSettings.UseZarinGate = model.UseZarinGate; zarinPalPaymentSettings.BlockOverseas = model.BlockOverseas; zarinPalPaymentSettings.ZarinGateType = model.ZarinGateType; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.Method, model.Method_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.UseSandbox, model.UseSandbox_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.MerchantID, model.MerchantID_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.RialToToman, model.RialToToman_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.BlockOverseas, model.MerchantID_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.UseZarinGate, model.UseZarinGate_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(zarinPalPaymentSettings, x => x.ZarinGateType, model.ZarinGateType_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var yuansferPaymentSettings = await _settingService.LoadSettingAsync <YuansferPaymentSettings>(storeScope); //save settings yuansferPaymentSettings.BaseApiUrl = model.BaseApiUrl; yuansferPaymentSettings.MerchantId = model.MerchantId; yuansferPaymentSettings.StoreId = model.StoreId; yuansferPaymentSettings.ApiToken = model.ApiToken; yuansferPaymentSettings.PaymentChannels = model.PaymentChannels.ToList(); yuansferPaymentSettings.AdditionalFee = model.AdditionalFee; yuansferPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.BaseApiUrl, model.BaseApiUrl_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.MerchantId, model.MerchantId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.StoreId, model.StoreId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.ApiToken, model.ApiToken_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.PaymentChannels, model.PaymentChannels_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.AdditionalFee, model.AdditionalFee_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(yuansferPaymentSettings, x => x.AdditionalFeePercentage, model.AdditionalFeePercentage_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
/// <returns>A task that represents the asynchronous operation</returns> public async Task <IActionResult> UpdateFixedShippingRate(FixedRateModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageShippingSettings)) { return(Content("Access denied")); } await _settingService.SetSettingAsync(string.Format(FixedByWeightByTotalDefaults.FixedRateSettingsKey, model.ShippingMethodId), model.Rate, 0, false); await _settingService.SetSettingAsync(string.Format(FixedByWeightByTotalDefaults.TransitDaysSettingsKey, model.ShippingMethodId), model.TransitDays, 0, false); await _settingService.ClearCacheAsync(); return(new NullJsonResult()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var checkMoneyOrderPaymentSettings = await _settingService.LoadSettingAsync <CheckMoneyOrderPaymentSettings>(storeScope); //save settings checkMoneyOrderPaymentSettings.DescriptionText = model.DescriptionText; checkMoneyOrderPaymentSettings.AdditionalFee = model.AdditionalFee; checkMoneyOrderPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; checkMoneyOrderPaymentSettings.ShippableProductRequired = model.ShippableProductRequired; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(checkMoneyOrderPaymentSettings, x => x.DescriptionText, model.DescriptionText_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(checkMoneyOrderPaymentSettings, x => x.AdditionalFee, model.AdditionalFee_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(checkMoneyOrderPaymentSettings, x => x.AdditionalFeePercentage, model.AdditionalFeePercentage_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(checkMoneyOrderPaymentSettings, x => x.ShippableProductRequired, model.ShippableProductRequired_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); //localization. no multi-store support for localization yet. foreach (var localized in model.Locales) { await _localizationService.SaveLocalizedSettingAsync(checkMoneyOrderPaymentSettings, x => x.DescriptionText, localized.LanguageId, localized.DescriptionText); } _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(CronTasksSettingsModel model) { if (!ModelState.IsValid) { return(await Configure()); } var settings = await _settingService.LoadSettingAsync <CronTasksSettings>(await _storeContext.GetActiveStoreScopeConfigurationAsync()); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var payPalStandardPaymentSettings = await _settingService.LoadSettingAsync <PayPalStandardPaymentSettings>(storeScope); //save settings payPalStandardPaymentSettings.UseSandbox = model.UseSandbox; payPalStandardPaymentSettings.BusinessEmail = model.BusinessEmail; payPalStandardPaymentSettings.PdtToken = model.PdtToken; payPalStandardPaymentSettings.PassProductNamesAndTotals = model.PassProductNamesAndTotals; payPalStandardPaymentSettings.AdditionalFee = model.AdditionalFee; payPalStandardPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(payPalStandardPaymentSettings, x => x.UseSandbox, model.UseSandbox_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(payPalStandardPaymentSettings, x => x.BusinessEmail, model.BusinessEmail_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(payPalStandardPaymentSettings, x => x.PdtToken, model.PdtToken_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(payPalStandardPaymentSettings, x => x.PassProductNamesAndTotals, model.PassProductNamesAndTotals_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(payPalStandardPaymentSettings, x => x.AdditionalFee, model.AdditionalFee_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(payPalStandardPaymentSettings, x => x.AdditionalFeePercentage, model.AdditionalFeePercentage_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ShipStationModel model) { if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var shipStationSettings = await _settingService.LoadSettingAsync <ShipStationSettings>(storeScope); //save settings shipStationSettings.ApiKey = model.ApiKey; shipStationSettings.ApiSecret = model.ApiSecret; shipStationSettings.PackingPackageVolume = model.PackingPackageVolume; shipStationSettings.PackingType = (PackingType)model.PackingType; shipStationSettings.PassDimensions = model.PassDimensions; shipStationSettings.Password = model.Password; shipStationSettings.UserName = model.UserName; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.ApiKey, model.ApiKey_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.ApiSecret, model.ApiSecret_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.PackingPackageVolume, model.PackingPackageVolume_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.PackingType, model.PackingType_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.PassDimensions, model.PassDimensions_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.Password, model.Password_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(shipStationSettings, x => x.UserName, model.UserName_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public static async Task SaveAsync <TSetttings>( this ISettingService service, TSetttings instance) where TSetttings : ISettings { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } var settingType = instance.GetType(); var typeName = settingType.Name; foreach (var prop in settingType.GetProperties()) { if (!prop.CanRead || !prop.CanWrite) { continue; } var key = (typeName + "." + prop.Name).ToLower(); if (!TypeDescriptor.GetConverter(prop.PropertyType).CanConvertFrom(typeof(string))) { continue; } object value = prop.GetValue(instance, null); if (value == null) { await service.AddOrUpdateAsync(key, ""); } else { string valueString = TypeDescriptor.GetConverter(prop.PropertyType).ConvertToInvariantString(value); await service.AddOrUpdateAsync(key, valueString); } } await service.ClearCacheAsync(); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var googleAnalyticsSettings = await _settingService.LoadSettingAsync <GoogleAnalyticsSettings>(storeScope); googleAnalyticsSettings.GoogleId = model.GoogleId; googleAnalyticsSettings.TrackingScript = model.TrackingScript; googleAnalyticsSettings.EnableEcommerce = model.EnableEcommerce; googleAnalyticsSettings.UseJsToSendEcommerceInfo = model.UseJsToSendEcommerceInfo; googleAnalyticsSettings.IncludingTax = model.IncludingTax; googleAnalyticsSettings.IncludeCustomerId = model.IncludeCustomerId; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(googleAnalyticsSettings, x => x.GoogleId, model.GoogleId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(googleAnalyticsSettings, x => x.TrackingScript, model.TrackingScript_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(googleAnalyticsSettings, x => x.EnableEcommerce, model.EnableEcommerce_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(googleAnalyticsSettings, x => x.UseJsToSendEcommerceInfo, model.UseJsToSendEcommerceInfo_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(googleAnalyticsSettings, x => x.IncludingTax, model.IncludingTax_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(googleAnalyticsSettings, x => x.IncludeCustomerId, model.IncludeCustomerId_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <ActionResult> Configure(ConfigurationModel model) { if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var luceneSettings = await _settingService.LoadSettingAsync <LuceneSettings>(storeScope); luceneSettings.Enabled = model.Enabled; luceneSettings.AutoCompleteSearchEnabled = model.AutoCompleteSearchEnabled; if (model.Enabled_OverrideForStore || storeScope == 0) { await _settingService.SaveSettingAsync(luceneSettings, x => x.Enabled, storeScope, false); } else if (storeScope > 0) { await _settingService.DeleteSettingAsync(luceneSettings, x => x.Enabled, storeScope); } if (model.AutoCompleteSearchEnabled_OverrideForStore || storeScope == 0) { await _settingService.SaveSettingAsync(luceneSettings, x => x.AutoCompleteSearchEnabled, storeScope, false); } else if (storeScope > 0) { await _settingService.DeleteSettingAsync(luceneSettings, x => x.AutoCompleteSearchEnabled, storeScope); } //now clear settings cache await _settingService.ClearCacheAsync(); return(await Configure()); }
/// <summary> /// Execute task /// </summary> /// <returns>The <see cref="Task"/></returns> public async Task ExecuteAsync() { var stores = await _storeService.GetAllStoresAsync(); foreach (var store in stores) { var validationResult = await _openPayService.ValidateAsync(store.Id); if (!validationResult.IsValid) { await _logger.ErrorAsync($"{Defaults.SystemName}: Cannot get the order limits for the store '{store.Name}' when background task was processed.{Environment.NewLine}{string.Join(Environment.NewLine, validationResult.Errors)}"); continue; } var openPayPaymentSettings = await _settingService.LoadSettingAsync <OpenPayPaymentSettings>(store.Id); _openPayApi.ConfigureClient(openPayPaymentSettings); try { var limits = await _openPayApi.GetOrderLimitsAsync(); openPayPaymentSettings.MinOrderTotal = limits.MinPrice / 100; openPayPaymentSettings.MaxOrderTotal = limits.MaxPrice / 100; await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.MinOrderTotal, stores.Count > 1, store.Id, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.MaxOrderTotal, stores.Count > 1, store.Id, false); await _settingService.ClearCacheAsync(); } catch (ApiException ex) { await _logger.ErrorAsync($"{Defaults.SystemName}: Cannot get the order limits for the store '{store.Name}' when background task was processed.", ex); } } }
/// <summary> /// Prepare credentials and onboarding model properties /// </summary> /// <param name="model">Comfiguration model</param> /// <param name="settings">Plugin settings</param> /// <param name="storeId">Store id</param> /// <returns>A task that represents the asynchronous operation</returns> private async Task PrepareCredentialsAsync(ConfigurationModel model, PayPalCommerceSettings settings, int storeId) { model.OnboardingModel.MerchantGuid = settings.MerchantGuid; model.OnboardingModel.SignUpUrl = settings.SignUpUrl; //no need to check credentials if the plugin is already configured or credentials were manually set if (settings.SetCredentialsManually || ServiceManager.IsConfigured(settings)) { return; } //no need to check credentials until the merchant has been onboarded and signed up if (string.IsNullOrEmpty(settings.MerchantGuid) || !string.IsNullOrEmpty(settings.SignUpUrl)) { return; } var(merchant, error) = await _serviceManager.GetMerchantAsync(settings.MerchantGuid); if (merchant is null || !string.IsNullOrEmpty(error)) { var locale = await _localizationService.GetResourceAsync("Plugins.Payments.PayPalCommerce.Configuration.Error"); var errorMessage = string.Format(locale, error, Url.Action("List", "Log")); _notificationService.ErrorNotification(errorMessage, false); return; } model.OnboardingModel.AccountCreated = !string.IsNullOrEmpty(merchant.MerchantId); model.OnboardingModel.EmailConfirmed = merchant.EmailConfirmed; model.OnboardingModel.PaymentsReceivable = merchant.PaymentsReceivable; model.OnboardingModel.PermissionGranted = merchant.PermissionGranted; model.OnboardingModel.DisplayStatus = true; if (!merchant.EmailConfirmed || !merchant.PaymentsReceivable || !merchant.PermissionGranted) { var onboardingNotCompleted = await _localizationService.GetResourceAsync("Plugins.Payments.PayPalCommerce.Onboarding.InProcess"); _notificationService.WarningNotification(onboardingNotCompleted); return; } if (string.IsNullOrEmpty(merchant.ClientId) || string.IsNullOrEmpty(merchant.ClientSecret)) { var onboardingError = await _localizationService.GetResourceAsync("Plugins.Payments.PayPalCommerce.Onboarding.Error"); _notificationService.ErrorNotification(onboardingError); return; } var onboardingCompleted = await _localizationService.GetResourceAsync("Plugins.Payments.PayPalCommerce.Onboarding.Completed"); _notificationService.SuccessNotification(onboardingCompleted); //first delete the unused webhook on a previous client, if changed if ((!merchant.ClientId?.Equals(settings.ClientId) ?? true) && !string.IsNullOrEmpty(settings.WebhookUrl) && !string.IsNullOrEmpty(settings.ClientId) && !string.IsNullOrEmpty(settings.SecretKey)) { await _serviceManager.DeleteWebhookAsync(settings); } //set new settings values settings.ClientId = merchant.ClientId; settings.SecretKey = merchant.ClientSecret; model.IsConfigured = ServiceManager.IsConfigured(settings); //ensure that webhook created, display warning in case of fail if (!string.IsNullOrEmpty(settings.ClientId) && !string.IsNullOrEmpty(settings.SecretKey)) { var(webhook, _) = await _serviceManager.CreateWebhookAsync(settings, storeId); settings.WebhookUrl = webhook?.Url; if (string.IsNullOrEmpty(settings.WebhookUrl)) { var url = Url.Action("List", "Log"); var warning = string.Format(await _localizationService.GetResourceAsync("Plugins.Payments.PayPalCommerce.WebhookWarning"), url); _notificationService.WarningNotification(warning, false); } } if (!string.IsNullOrEmpty(merchant.Email) && !merchant.Email.Equals(settings.Email, StringComparison.InvariantCultureIgnoreCase)) { settings.Email = merchant.Email; model.Email = merchant.Email; } var overrideSettings = storeId > 0; await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.Email, overrideSettings, storeId, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.WebhookUrl, overrideSettings, storeId, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.ClientId, overrideSettings, storeId, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.SecretKey, overrideSettings, storeId, false); await _settingService.ClearCacheAsync(); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } // primary store currency must match the currency of the selected country var selectedRegion = Defaults.OpenPay.AvailableRegions .FirstOrDefault(region => region.TwoLetterIsoCode == model.RegionTwoLetterIsoCode); var primaryStoreCurrency = await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId); if (primaryStoreCurrency.CurrencyCode != selectedRegion.CurrencyCode) { var invalidCurrencyLocale = await _localizationService.GetResourceAsync("Plugins.Payments.OpenPay.InvalidCurrency"); var invalidCurrencyMessage = string.Format(invalidCurrencyLocale, selectedRegion.TwoLetterIsoCode, selectedRegion.CurrencyCode); _notificationService.WarningNotification(invalidCurrencyMessage); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var openPayPaymentSettings = await _settingService.LoadSettingAsync <OpenPayPaymentSettings>(storeScope); //sort plan tiers var convertedPlanTiers = model.PlanTiers.Split(',').Select(x => int.Parse(x)).ToArray(); Array.Sort(convertedPlanTiers); //save settings openPayPaymentSettings.UseSandbox = model.UseSandbox; openPayPaymentSettings.ApiToken = model.ApiToken; openPayPaymentSettings.RegionTwoLetterIsoCode = model.RegionTwoLetterIsoCode; openPayPaymentSettings.AdditionalFee = model.AdditionalFee; openPayPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage; openPayPaymentSettings.DisplayProductListingWidget = model.DisplayProductListingWidget; openPayPaymentSettings.DisplayCartWidget = model.DisplayCartWidget; openPayPaymentSettings.CartWidgetLogo = model.CartWidgetLogo; openPayPaymentSettings.DisplayProductPageWidget = model.DisplayProductPageWidget; openPayPaymentSettings.DisplayInfoBeltWidget = model.DisplayInfoBeltWidget; openPayPaymentSettings.DisplayLandingPageWidget = model.DisplayLandingPageWidget; openPayPaymentSettings.PlanTiers = string.Join(",", convertedPlanTiers); openPayPaymentSettings.InfoBeltWidgetColor = model.InfoBeltWidgetColor; openPayPaymentSettings.ProductListingWidgetLogo = model.ProductListingWidgetLogo; openPayPaymentSettings.ProductListingHideLogo = model.ProductListingHideLogo; openPayPaymentSettings.ProductPageWidgetLogo = model.ProductPageWidgetLogo; openPayPaymentSettings.ProductPageWidgetLogoPosition = model.ProductPageWidgetLogoPosition; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.UseSandbox, model.UseSandbox_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.ApiToken, model.ApiToken_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.RegionTwoLetterIsoCode, model.RegionTwoLetterIsoCode_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.AdditionalFee, model.AdditionalFee_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.AdditionalFeePercentage, model.AdditionalFeePercentage_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.DisplayProductListingWidget, model.DisplayProductListingWidget_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.DisplayCartWidget, model.DisplayCartWidget_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.CartWidgetLogo, model.CartWidgetLogo_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.DisplayProductPageWidget, model.DisplayProductPageWidget_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.DisplayInfoBeltWidget, model.DisplayInfoBeltWidget_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.DisplayLandingPageWidget, model.DisplayLandingPageWidget_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.PlanTiers, model.PlanTiers_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.InfoBeltWidgetColor, model.InfoBeltWidgetColor_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.ProductListingWidgetLogo, model.ProductListingWidgetLogo_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.ProductListingHideLogo, model.ProductListingHideLogo_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.ProductPageWidgetLogo, model.ProductPageWidgetLogo_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(openPayPaymentSettings, x => x.ProductPageWidgetLogoPosition, model.ProductPageWidgetLogoPosition_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(RedirectToAction("Configure")); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageWidgets)) { return(AccessDeniedView()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var nivoSliderSettings = await _settingService.LoadSettingAsync <NivoSliderSettings>(storeScope); //get previous picture identifiers var previousPictureIds = new[] { nivoSliderSettings.Picture1Id, nivoSliderSettings.Picture2Id, nivoSliderSettings.Picture3Id, nivoSliderSettings.Picture4Id, nivoSliderSettings.Picture5Id }; nivoSliderSettings.Picture1Id = model.Picture1Id; nivoSliderSettings.Text1 = model.Text1; nivoSliderSettings.Link1 = model.Link1; nivoSliderSettings.AltText1 = model.AltText1; nivoSliderSettings.Picture2Id = model.Picture2Id; nivoSliderSettings.Text2 = model.Text2; nivoSliderSettings.Link2 = model.Link2; nivoSliderSettings.AltText2 = model.AltText2; nivoSliderSettings.Picture3Id = model.Picture3Id; nivoSliderSettings.Text3 = model.Text3; nivoSliderSettings.Link3 = model.Link3; nivoSliderSettings.AltText3 = model.AltText3; nivoSliderSettings.Picture4Id = model.Picture4Id; nivoSliderSettings.Text4 = model.Text4; nivoSliderSettings.Link4 = model.Link4; nivoSliderSettings.AltText4 = model.AltText4; nivoSliderSettings.Picture5Id = model.Picture5Id; nivoSliderSettings.Text5 = model.Text5; nivoSliderSettings.Link5 = model.Link5; nivoSliderSettings.AltText5 = model.AltText5; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Picture1Id, model.Picture1Id_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Text1, model.Text1_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Link1, model.Link1_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.AltText1, model.AltText1_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Picture2Id, model.Picture2Id_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Text2, model.Text2_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Link2, model.Link2_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.AltText2, model.AltText2_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Picture3Id, model.Picture3Id_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Text3, model.Text3_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Link3, model.Link3_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.AltText3, model.AltText3_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Picture4Id, model.Picture4Id_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Text4, model.Text4_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Link4, model.Link4_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.AltText4, model.AltText4_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Picture5Id, model.Picture5Id_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Text5, model.Text5_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.Link5, model.Link5_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(nivoSliderSettings, x => x.AltText5, model.AltText5_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); //get current picture identifiers var currentPictureIds = new[] { nivoSliderSettings.Picture1Id, nivoSliderSettings.Picture2Id, nivoSliderSettings.Picture3Id, nivoSliderSettings.Picture4Id, nivoSliderSettings.Picture5Id }; //delete an old picture (if deleted or updated) foreach (var pictureId in previousPictureIds.Except(currentPictureIds)) { var previousPicture = await _pictureService.GetPictureByIdAsync(pictureId); if (previousPicture != null) { await _pictureService.DeletePictureAsync(previousPicture); } } _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
/// <summary> /// Prepare SendinBlueModel /// </summary> /// <param name="model">Model</param> private async Task PrepareModelAsync(ConfigurationModel model) { //load settings for active store scope var storeId = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var sendinBlueSettings = await _settingService.LoadSettingAsync <SendinBlueSettings>(storeId); //whether plugin is configured if (string.IsNullOrEmpty(sendinBlueSettings.ApiKey)) { return; } //prepare common properties model.ActiveStoreScopeConfiguration = storeId; model.ApiKey = sendinBlueSettings.ApiKey; model.ListId = sendinBlueSettings.ListId; model.SmtpKey = sendinBlueSettings.SmtpKey; model.SenderId = sendinBlueSettings.SenderId; model.UseSmsNotifications = sendinBlueSettings.UseSmsNotifications; model.SmsSenderName = sendinBlueSettings.SmsSenderName; model.StoreOwnerPhoneNumber = sendinBlueSettings.StoreOwnerPhoneNumber; model.UseMarketingAutomation = sendinBlueSettings.UseMarketingAutomation; model.TrackingScript = sendinBlueSettings.TrackingScript; model.HideGeneralBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), SendinBlueDefaults.HideGeneralBlock); model.HideSynchronizationBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), SendinBlueDefaults.HideSynchronizationBlock); model.HideTransactionalBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), SendinBlueDefaults.HideTransactionalBlock); model.HideSmsBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), SendinBlueDefaults.HideSmsBlock); model.HideMarketingAutomationBlock = await _genericAttributeService.GetAttributeAsync <bool>(await _workContext.GetCurrentCustomerAsync(), SendinBlueDefaults.HideMarketingAutomationBlock); //prepare nested search models model.MessageTemplateSearchModel.SetGridPageSize(); model.SmsSearchModel.SetGridPageSize(); //prepare add SMS model model.AddSms.AvailablePhoneTypes.Add(new SelectListItem(await _localizationService.GetResourceAsync("Plugins.Misc.SendinBlue.MyPhone"), "0")); model.AddSms.AvailablePhoneTypes.Add(new SelectListItem(await _localizationService.GetResourceAsync("Plugins.Misc.SendinBlue.CustomerPhone"), "1")); model.AddSms.AvailablePhoneTypes.Add(new SelectListItem(await _localizationService.GetResourceAsync("Plugins.Misc.SendinBlue.BillingAddressPhone"), "2")); model.AddSms.DefaultSelectedPhoneTypeId = model.AddSms.AvailablePhoneTypes.First().Value; var stores = await _storeService.GetAllStoresAsync(); var messageTemplates = await _messageTemplateService.GetAllMessageTemplatesAsync(storeId); model.AddSms.AvailableMessages = await messageTemplates.SelectAwait(async messageTemplate => { var name = messageTemplate.Name; if (storeId == 0 && messageTemplate.LimitedToStores) { var storeIds = await _storeMappingService.GetStoresIdsWithAccessAsync(messageTemplate); var storeNames = stores.Where(store => storeIds.Contains(store.Id)).Select(store => store.Name); name = $"{name} ({string.Join(',', storeNames)})"; } return(new SelectListItem(name, messageTemplate.Id.ToString())); }).ToListAsync(); var defaultSelectedMessage = model.AddSms.AvailableMessages.FirstOrDefault(); model.AddSms.DefaultSelectedMessageId = defaultSelectedMessage?.Value ?? "0"; //check whether email account exists if (sendinBlueSettings.UseSmtp && await _emailAccountService.GetEmailAccountByIdAsync(sendinBlueSettings.EmailAccountId) != null) { model.UseSmtp = sendinBlueSettings.UseSmtp; } //get account info var(accountInfo, marketingAutomationEnabled, maKey, accountErrors) = await _sendinBlueEmailManager.GetAccountInfoAsync(); model.AccountInfo = accountInfo; model.MarketingAutomationKey = maKey; model.MarketingAutomationDisabled = !marketingAutomationEnabled; if (!string.IsNullOrEmpty(accountErrors)) { _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {accountErrors}"); } //prepare overridable settings if (storeId > 0) { model.ListId_OverrideForStore = await _settingService.SettingExistsAsync(sendinBlueSettings, settings => settings.ListId, storeId); model.UseSmtp_OverrideForStore = await _settingService.SettingExistsAsync(sendinBlueSettings, settings => settings.UseSmtp, storeId); model.SenderId_OverrideForStore = await _settingService.SettingExistsAsync(sendinBlueSettings, settings => settings.SenderId, storeId); model.UseSmsNotifications_OverrideForStore = await _settingService.SettingExistsAsync(sendinBlueSettings, settings => settings.UseSmsNotifications, storeId); model.SmsSenderName_OverrideForStore = await _settingService.SettingExistsAsync(sendinBlueSettings, settings => settings.SmsSenderName, storeId); model.UseMarketingAutomation_OverrideForStore = await _settingService.SettingExistsAsync(sendinBlueSettings, settings => settings.UseMarketingAutomation, storeId); } //check SMTP status var(smtpEnabled, smtpErrors) = await _sendinBlueEmailManager.SmtpIsEnabledAsync(); if (!string.IsNullOrEmpty(smtpErrors)) { _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {smtpErrors}"); } //get available contact lists to synchronize var(lists, listsErrors) = await _sendinBlueEmailManager.GetListsAsync(); model.AvailableLists = lists.Select(list => new SelectListItem(list.Name, list.Id)).ToList(); model.AvailableLists.Insert(0, new SelectListItem("Select list", "0")); if (!string.IsNullOrEmpty(listsErrors)) { _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {listsErrors}"); } //get available senders of emails from account var(senders, sendersErrors) = await _sendinBlueEmailManager.GetSendersAsync(); model.AvailableSenders = senders.Select(list => new SelectListItem(list.Name, list.Id)).ToList(); model.AvailableSenders.Insert(0, new SelectListItem("Select sender", "0")); if (!string.IsNullOrEmpty(sendersErrors)) { _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {sendersErrors}"); } //get allowed tokens model.AllowedTokens = string.Join(", ", await _messageTokenProvider.GetListOfAllowedTokensAsync()); //create attributes in account var attributesErrors = await _sendinBlueEmailManager.PrepareAttributesAsync(); if (!string.IsNullOrEmpty(attributesErrors)) { _notificationService.ErrorNotification($"{SendinBlueDefaults.NotificationMessage} {attributesErrors}"); } //try to set account partner if (!sendinBlueSettings.PartnerValueSet) { var partnerSet = await _sendinBlueEmailManager.SetPartnerAsync(); if (partnerSet) { sendinBlueSettings.PartnerValueSet = true; await _settingService.SaveSettingAsync(sendinBlueSettings, settings => settings.PartnerValueSet, clearCache : false); await _settingService.ClearCacheAsync(); } } }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var settings = await _settingService.LoadSettingAsync <PayPalSmartPaymentButtonsSettings>(storeScope); //first delete the unused webhook on a previous client, if changed if ((!model.ClientId?.Equals(settings.ClientId) ?? true) && !string.IsNullOrEmpty(settings.ClientId) && !string.IsNullOrEmpty(settings.SecretKey)) { await _serviceManager.DeleteWebhookAsync(settings); } //set new settings values settings.ClientId = model.ClientId; settings.SecretKey = model.SecretKey; settings.UseSandbox = model.UseSandbox; settings.PaymentType = (PaymentType)model.PaymentTypeId; settings.DisplayButtonsOnShoppingCart = model.DisplayButtonsOnShoppingCart; settings.DisplayButtonsOnProductDetails = model.DisplayButtonsOnProductDetails; settings.DisplayLogoInHeaderLinks = model.DisplayLogoInHeaderLinks; settings.LogoInHeaderLinks = model.LogoInHeaderLinks; settings.DisplayLogoInFooter = model.DisplayLogoInFooter; settings.LogoInFooter = model.LogoInFooter; //ensure that webhook created, display warning in case of fail if (!string.IsNullOrEmpty(settings.ClientId) && !string.IsNullOrEmpty(settings.SecretKey)) { var webhookUrl = Url.RouteUrl(Defaults.WebhookRouteName, null, _webHelper.GetCurrentRequestProtocol()); var(webhook, webhookError) = await _serviceManager.CreateWebHookAsync(settings, webhookUrl); settings.WebhookId = webhook?.Id; if (string.IsNullOrEmpty(settings.WebhookId)) { var url = Url.Action("List", "Log"); var warning = string.Format(await _localizationService.GetResourceAsync("Plugins.Payments.PayPalSmartPaymentButtons.WebhookWarning"), url); _notificationService.WarningNotification(warning, false); } } //save settings await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.WebhookId, true, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.ClientId, model.ClientId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.SecretKey, model.SecretKey_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.UseSandbox, model.UseSandbox_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.PaymentType, model.PaymentTypeId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.DisplayButtonsOnShoppingCart, model.DisplayButtonsOnShoppingCart_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.DisplayButtonsOnProductDetails, model.DisplayButtonsOnProductDetails_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.DisplayLogoInHeaderLinks, model.DisplayLogoInHeaderLinks_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.LogoInHeaderLinks, model.LogoInHeaderLinks_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.DisplayLogoInFooter, model.DisplayLogoInFooter_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(settings, setting => setting.LogoInFooter, model.LogoInFooter_OverrideForStore, storeScope, false); await _settingService.ClearCacheAsync(); //ensure credentials are valid if (!string.IsNullOrEmpty(settings.ClientId) && !string.IsNullOrEmpty(settings.SecretKey)) { var(_, errorMessage) = await _serviceManager.GetAccessTokenAsync(settings); if (!string.IsNullOrEmpty(errorMessage)) { var url = Url.Action("List", "Log"); var error = string.Format(await _localizationService.GetResourceAsync("Plugins.Payments.PayPalSmartPaymentButtons.Credentials.Invalid"), url); _notificationService.ErrorNotification(error, false); } else { _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Plugins.Payments.PayPalSmartPaymentButtons.Credentials.Valid")); } } _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }
public async Task <IActionResult> Configure(ConfigurationModel model) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(await Configure()); } //load settings for a chosen store scope var storeScope = await _storeContext.GetActiveStoreScopeConfigurationAsync(); var PaytmPaymentSettings = await _settingService.LoadSettingAsync <PaytmPaymentSettings>(storeScope); //save settings PaytmPaymentSettings.MerchantId = model.MerchantId; PaytmPaymentSettings.MerchantKey = model.MerchantKey; PaytmPaymentSettings.PdtToken = model.PdtToken; PaytmPaymentSettings.env = model.env; PaytmPaymentSettings.IndustryTypeId = model.IndustryTypeId; PaytmPaymentSettings.Website = model.Website; if (model.env == "Stage") { PaytmPaymentSettings.PaymentUrl = "https://securegw-stage.paytm.in/order/process"; PaytmPaymentSettings.TxnStatusUrl = "https://securegw-stage.paytm.in/order/status"; } if (model.env == "Prod") { PaytmPaymentSettings.PaymentUrl = "https://securegw.paytm.in/order/process"; PaytmPaymentSettings.TxnStatusUrl = "https://securegw.paytm.in/order/status"; } PaytmPaymentSettings.PaymentUrl = model.PaymentUrl; PaytmPaymentSettings.CallBackUrl = model.CallBackUrl; PaytmPaymentSettings.TxnStatusUrl = model.TxnStatusUrl; PaytmPaymentSettings.UseDefaultCallBack = model.UseDefaultCallBack; /* We do not clear cache after each setting update. * This behavior can increase performance because cached settings will not be cleared * and loaded from database after each update */ await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.MerchantId, model.MerchantId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.MerchantKey, model.MerchantKey_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.PdtToken, model.PdtToken_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.PaymentUrl, model.PaymentUrl_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.TxnStatusUrl, model.TxnStatusUrl_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.UseDefaultCallBack, model.UseDefaultCallBack_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.Website, model.Website_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.IndustryTypeId, model.IndustryTypeId_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.env, model.env_OverrideForStore, storeScope, false); await _settingService.SaveSettingOverridablePerStoreAsync(PaytmPaymentSettings, x => x.CallBackUrl, model.CallBackUrl_OverrideForStore, storeScope, false); //now clear settings cache await _settingService.ClearCacheAsync(); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Plugins.Saved")); return(await Configure()); }