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

            var model = new ConfigurationModel();
            model.UseSandbox = yenePayCheckoutPaymentSettings.UseSandbox;
            model.MerchantCode = yenePayCheckoutPaymentSettings.MerchantCode;
            model.PdtToken = yenePayCheckoutPaymentSettings.PdtToken;
            model.PdtValidateOrderTotal = yenePayCheckoutPaymentSettings.PdtValidateOrderTotal;
            model.AdditionalFee = yenePayCheckoutPaymentSettings.AdditionalFee;
            model.AdditionalFeePercentage = yenePayCheckoutPaymentSettings.AdditionalFeePercentage;
            model.PassProductNamesAndTotals = yenePayCheckoutPaymentSettings.PassProductNamesAndTotals;
            model.EnableIpn = yenePayCheckoutPaymentSettings.EnableIpn;
            model.IpnUrl = yenePayCheckoutPaymentSettings.IpnUrl;

            model.ActiveStoreScopeConfiguration = storeScope;
            if (storeScope > 0)
            {
                model.UseSandbox_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.UseSandbox, storeScope);
                model.MerchantId_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.MerchantCode, storeScope);
                model.PdtToken_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.PdtToken, storeScope);
                model.PdtValidateOrderTotal_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.PdtValidateOrderTotal, storeScope);
                model.AdditionalFee_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.AdditionalFee, storeScope);
                model.AdditionalFeePercentage_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.AdditionalFeePercentage, storeScope);
                model.PassProductNamesAndTotals_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.PassProductNamesAndTotals, storeScope);
                model.EnableIpn_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.EnableIpn, storeScope);
                model.IpnUrl_OverrideForStore = _settingService.SettingExists(yenePayCheckoutPaymentSettings, x => x.IpnUrl, storeScope);
            }

            return View("Nop.Plugin.Payments.YenePayCheckout.Views.PaymentYenePayCheckout.Configure", 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 yenePayStandardPaymentSettings = _settingService.LoadSetting<YenePayPaymentSettings>(storeScope);

            //save settings
            yenePayStandardPaymentSettings.UseSandbox = model.UseSandbox;
            yenePayStandardPaymentSettings.MerchantCode = model.MerchantCode;
            yenePayStandardPaymentSettings.PdtToken = model.PdtToken;
            yenePayStandardPaymentSettings.PdtValidateOrderTotal = model.PdtValidateOrderTotal;
            yenePayStandardPaymentSettings.AdditionalFee = model.AdditionalFee;
            yenePayStandardPaymentSettings.AdditionalFeePercentage = model.AdditionalFeePercentage;
            yenePayStandardPaymentSettings.PassProductNamesAndTotals = model.PassProductNamesAndTotals;
            yenePayStandardPaymentSettings.EnableIpn = model.EnableIpn;
            yenePayStandardPaymentSettings.IpnUrl = model.IpnUrl;

            /* 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(yenePayStandardPaymentSettings, x => x.UseSandbox, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.UseSandbox, storeScope);

            if (model.MerchantId_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(yenePayStandardPaymentSettings, x => x.MerchantCode, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.MerchantCode, storeScope);

            if (model.PdtToken_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(yenePayStandardPaymentSettings, x => x.PdtToken, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.PdtToken, storeScope);

            if (model.PdtValidateOrderTotal_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(yenePayStandardPaymentSettings, x => x.PdtValidateOrderTotal, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.PdtValidateOrderTotal, storeScope);

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

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

            if (model.PassProductNamesAndTotals_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(yenePayStandardPaymentSettings, x => x.PassProductNamesAndTotals, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.PassProductNamesAndTotals, storeScope);

            if (model.EnableIpn_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(yenePayStandardPaymentSettings, x => x.EnableIpn, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.EnableIpn, storeScope);

            if (model.IpnUrl_OverrideForStore || storeScope == 0)
                _settingService.SaveSetting(yenePayStandardPaymentSettings, x => x.IpnUrl, storeScope, false);
            else if (storeScope > 0)
                _settingService.DeleteSetting(yenePayStandardPaymentSettings, x => x.IpnUrl, storeScope);

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

            return Configure();
        }