Search in sources :

Example 6 with IntegrationConfiguration

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

the class ConfigurationModulesLoader method loadIntegrationConfigurations.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map<String, IntegrationConfiguration> loadIntegrationConfigurations(String value) throws Exception {
    Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
    ObjectMapper mapper = new ObjectMapper();
    try {
        Map[] objects = mapper.readValue(value, Map[].class);
        for (Map object : objects) {
            IntegrationConfiguration configuration = new IntegrationConfiguration();
            String moduleCode = (String) object.get("moduleCode");
            if (object.get("active") != null) {
                configuration.setActive((Boolean) object.get("active"));
            }
            if (object.get("defaultSelected") != null) {
                configuration.setDefaultSelected((Boolean) object.get("defaultSelected"));
            }
            if (object.get("environment") != null) {
                configuration.setEnvironment((String) object.get("environment"));
            }
            configuration.setModuleCode(moduleCode);
            modules.put(moduleCode, configuration);
            if (object.get("integrationKeys") != null) {
                Map<String, String> confs = (Map<String, String>) object.get("integrationKeys");
                configuration.setIntegrationKeys(confs);
            }
            if (object.get("integrationKeys") != null) {
                Map<String, List<String>> options = (Map<String, List<String>>) object.get("integrationOptions");
                configuration.setIntegrationOptions(options);
            }
        }
        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) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 7 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration 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 IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration 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 IntegrationConfiguration

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

the class PaymentServiceImpl method getAcceptedPaymentMethods.

@Override
public List<PaymentMethod> getAcceptedPaymentMethods(MerchantStore store) throws ServiceException {
    Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
    List<PaymentMethod> returnModules = new ArrayList<PaymentMethod>();
    for (String module : modules.keySet()) {
        IntegrationConfiguration config = modules.get(module);
        if (config.isActive()) {
            IntegrationModule md = this.getPaymentMethodByCode(store, config.getModuleCode());
            if (md == null) {
                continue;
            }
            PaymentMethod paymentMethod = new PaymentMethod();
            paymentMethod.setDefaultSelected(config.isDefaultSelected());
            paymentMethod.setPaymentMethodCode(config.getModuleCode());
            paymentMethod.setModule(md);
            paymentMethod.setInformations(config);
            PaymentType type = PaymentType.fromString(md.getType());
            paymentMethod.setPaymentType(type);
            returnModules.add(paymentMethod);
        }
    }
    return returnModules;
}
Also used : IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ArrayList(java.util.ArrayList) PaymentMethod(com.salesmanager.core.model.payments.PaymentMethod) PaymentType(com.salesmanager.core.model.payments.PaymentType) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule)

Example 10 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration 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)

Aggregations

IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)27 ServiceException (com.salesmanager.core.business.exception.ServiceException)20 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)16 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 List (java.util.List)9 Language (com.salesmanager.core.model.reference.language.Language)8 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)8 CustomIntegrationConfiguration (com.salesmanager.core.model.system.CustomIntegrationConfiguration)7 PaymentModule (com.salesmanager.core.modules.integration.payment.model.PaymentModule)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)6 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)6 IntegrationModuleConfiguration (com.salesmanager.shop.model.system.IntegrationModuleConfiguration)6 IntegrationModuleSummaryEntity (com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity)6 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)6 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)6 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)6