public ActionResult Configure()
        {
            //load settings for a chosen store scope
            var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
            var authorizeNetPaymentSettings = _settingService.LoadSetting<BridgePaySettings>(storeScope);

            var model = new ConfigurationModel();
            model.UseSandbox = authorizeNetPaymentSettings.UseSandbox;
            model.TransactModeId = Convert.ToInt32(authorizeNetPaymentSettings.TransactMode);
            model.TransactionKey = authorizeNetPaymentSettings.TransactionKey;
            model.Username = authorizeNetPaymentSettings.Username;
            model.Password = authorizeNetPaymentSettings.Password;
            model.MerchantKey = authorizeNetPaymentSettings.MerchantKey;
            model.GatewayUrl = authorizeNetPaymentSettings.GatewayUrl;
            model.AdditionalFee = authorizeNetPaymentSettings.AdditionalFee;
            model.AdditionalFeePercentage = authorizeNetPaymentSettings.AdditionalFeePercentage;
            //model.TransactModeValues = authorizeNetPaymentSettings.TransactMode.ToSelectList();

            model.ActiveStoreScopeConfiguration = storeScope;
            if (storeScope > 0)
            {
                model.UseSandbox_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.UseSandbox, storeScope);
                model.TransactModeId_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.TransactMode, storeScope);
                model.TransactionKey_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.TransactionKey, storeScope);
                model.Username_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.Username, storeScope);
                model.Password_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.Password, storeScope);
                model.MerchantKey_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.MerchantKey, storeScope);
                model.GatewayUrl_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.GatewayUrl, storeScope);
                model.AdditionalFee_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.AdditionalFee, storeScope);
                model.AdditionalFeePercentage_OverrideForStore = _settingService.SettingExists(authorizeNetPaymentSettings, x => x.AdditionalFeePercentage, storeScope);
            }

            return View("~/Plugins/Tameion.BridgePay/Views/BridgePay/Configure.cshtml", model);
        }
        public ActionResult Configure(ConfigurationModel model)
        {
            if (!ModelState.IsValid)
                return Configure();

            //load settings for a chosen store scope
            var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
            var bridgePaySettings = _settingService.LoadSetting<BridgePaySettings>(storeScope);

            //save settings
            bridgePaySettings.UseSandbox = model.UseSandbox;
            bridgePaySettings.TransactMode = (TransactionMode)model.TransactModeId;
            bridgePaySettings.TransactionKey = model.TransactionKey;
            bridgePaySettings.Username = model.Username;
            bridgePaySettings.Password = model.Password;
            bridgePaySettings.MerchantKey = model.MerchantKey;
            bridgePaySettings.GatewayUrl = model.GatewayUrl;
            bridgePaySettings.AdditionalFee = model.AdditionalFee;
            bridgePaySettings.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 */
            if (model.UseSandbox_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.UseSandbox, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.UseSandbox, storeScope);

            //if (model.TransactModeId_OverrideForStore || storeScope == 0)
            //    _settingService.SaveSetting(bridgePaySettings, x => x.TransactMode, storeScope, false);
            //else if (storeScope > 0)
            //    _settingService.DeleteSetting(bridgePaySettings, x => x.TransactMode, storeScope);

            if (model.TransactionKey_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.TransactionKey, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.TransactionKey, storeScope);

            if (model.Username_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.Username, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.Username, storeScope);

            if (model.Password_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.Password, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.Password, storeScope);

            if (model.MerchantKey_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.MerchantKey, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.MerchantKey, storeScope);

            if (model.GatewayUrl_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.GatewayUrl, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.GatewayUrl, storeScope);

            if (model.AdditionalFee_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.AdditionalFee, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.AdditionalFee, storeScope);

            if (model.AdditionalFeePercentage_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(bridgePaySettings, x => x.AdditionalFeePercentage, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(bridgePaySettings, x => x.AdditionalFeePercentage, storeScope);

            //now clear settings cache
            _settingService.ClearCache();

            SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return Configure();
        }