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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations