Search in sources :

Example 6 with MerchantConfiguration

use of com.salesmanager.core.model.system.MerchantConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingServiceImpl method saveCustomShippingConfiguration.

@Override
public void saveCustomShippingConfiguration(String moduleCode, CustomIntegrationConfiguration shippingConfiguration, MerchantStore store) throws ServiceException {
    ShippingQuoteModule quoteModule = shippingModules.get(moduleCode);
    if (quoteModule == null) {
        throw new ServiceException("Shipping module " + moduleCode + " does not exist");
    }
    String configurationValue = shippingConfiguration.toJSONString();
    try {
        MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(moduleCode, store);
        if (configuration == null) {
            configuration = new MerchantConfiguration();
            configuration.setKey(moduleCode);
            configuration.setMerchantStore(store);
        }
        configuration.setValue(configurationValue);
        merchantConfigurationService.saveOrUpdate(configuration);
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) ShippingQuoteModule(com.salesmanager.core.modules.integration.shipping.model.ShippingQuoteModule) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 7 with MerchantConfiguration

use of com.salesmanager.core.model.system.MerchantConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentServiceImpl method getPaymentModulesConfigured.

@Override
public Map<String, IntegrationConfiguration> getPaymentModulesConfigured(MerchantStore store) throws ServiceException {
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(Constants.PAYMENT_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
        }
        return modules;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) HashMap(java.util.HashMap) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 8 with MerchantConfiguration

use of com.salesmanager.core.model.system.MerchantConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentServiceImpl method removePaymentModuleConfiguration.

@Override
public void removePaymentModuleConfiguration(String moduleCode, MerchantStore store) throws ServiceException {
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(Constants.PAYMENT_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
            modules.remove(moduleCode);
            String configs = ConfigurationModulesLoader.toJSONString(modules);
            String encrypted = encryption.encrypt(configs);
            merchantConfiguration.setValue(encrypted);
            merchantConfigurationService.saveOrUpdate(merchantConfiguration);
        }
        MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(moduleCode, store);
        if (configuration != null) {
            // custom module
            merchantConfigurationService.delete(configuration);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) HashMap(java.util.HashMap) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 9 with MerchantConfiguration

use of com.salesmanager.core.model.system.MerchantConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentServiceImpl method savePaymentModuleConfiguration.

@Override
public void savePaymentModuleConfiguration(IntegrationConfiguration configuration, MerchantStore store) throws ServiceException {
    // validate entries
    try {
        String moduleCode = configuration.getModuleCode();
        PaymentModule module = paymentModules.get(moduleCode);
        if (module == null) {
            throw new ServiceException("Payment module " + moduleCode + " does not exist");
        }
        module.validateModuleConfiguration(configuration, store);
    } catch (IntegrationException ie) {
        throw ie;
    }
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(Constants.PAYMENT_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
        } else {
            merchantConfiguration = new MerchantConfiguration();
            merchantConfiguration.setMerchantStore(store);
            merchantConfiguration.setKey(Constants.PAYMENT_MODULES);
        }
        modules.put(configuration.getModuleCode(), configuration);
        String configs = ConfigurationModulesLoader.toJSONString(modules);
        String encrypted = encryption.encrypt(configs);
        merchantConfiguration.setValue(encrypted);
        merchantConfigurationService.saveOrUpdate(merchantConfiguration);
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : PaymentModule(com.salesmanager.core.modules.integration.payment.model.PaymentModule) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) HashMap(java.util.HashMap) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 10 with MerchantConfiguration

use of com.salesmanager.core.model.system.MerchantConfiguration in project shopizer by shopizer-ecommerce.

the class EmailServiceImpl method getEmailConfiguration.

@Override
public EmailConfig getEmailConfiguration(MerchantStore store) throws ServiceException {
    MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(Constants.EMAIL_CONFIG, store);
    EmailConfig emailConfig = null;
    if (configuration != null) {
        String value = configuration.getValue();
        ObjectMapper mapper = new ObjectMapper();
        try {
            emailConfig = mapper.readValue(value, EmailConfig.class);
        } catch (Exception e) {
            throw new ServiceException("Cannot parse json string " + value);
        }
    }
    return emailConfig;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) EmailConfig(com.salesmanager.core.business.modules.email.EmailConfig) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Aggregations

MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)23 ServiceException (com.salesmanager.core.business.exception.ServiceException)15 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)6 HashMap (java.util.HashMap)6 CustomIntegrationConfiguration (com.salesmanager.core.model.system.CustomIntegrationConfiguration)3 ArrayList (java.util.ArrayList)3 ShippingConfiguration (com.salesmanager.core.model.shipping.ShippingConfiguration)2 MerchantConfig (com.salesmanager.core.model.system.MerchantConfig)2 ShippingQuoteModule (com.salesmanager.core.modules.integration.shipping.model.ShippingQuoteModule)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 EmailConfig (com.salesmanager.core.business.modules.email.EmailConfig)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 MerchantConfigurationService (com.salesmanager.core.business.services.system.MerchantConfigurationService)1 MeasureUnit (com.salesmanager.core.constants.MeasureUnit)1