use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.
the class MoneyOrderPayment method validateModuleConfiguration.
@Override
public void validateModuleConfiguration(IntegrationConfiguration integrationConfiguration, MerchantStore store) throws IntegrationException {
List<String> errorFields = null;
Map<String, String> keys = integrationConfiguration.getIntegrationKeys();
// validate integrationKeys['address']
if (keys == null || StringUtils.isBlank(keys.get("address"))) {
errorFields = new ArrayList<String>();
errorFields.add("address");
}
if (errorFields != null) {
IntegrationException ex = new IntegrationException(IntegrationException.ERROR_VALIDATION_SAVE);
ex.setErrorFields(errorFields);
throw ex;
}
}
use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.
the class PayPalExpressCheckoutPayment method validateModuleConfiguration.
@Override
public void validateModuleConfiguration(IntegrationConfiguration integrationConfiguration, MerchantStore store) throws IntegrationException {
List<String> errorFields = null;
// validate integrationKeys['account']
Map<String, String> keys = integrationConfiguration.getIntegrationKeys();
if (keys == null || StringUtils.isBlank(keys.get("api"))) {
errorFields = new ArrayList<String>();
errorFields.add("api");
}
if (keys == null || StringUtils.isBlank(keys.get("username"))) {
if (errorFields == null) {
errorFields = new ArrayList<String>();
}
errorFields.add("username");
}
if (keys == null || StringUtils.isBlank(keys.get("signature"))) {
if (errorFields == null) {
errorFields = new ArrayList<String>();
}
errorFields.add("signature");
}
if (errorFields != null) {
IntegrationException ex = new IntegrationException(IntegrationException.ERROR_VALIDATION_SAVE);
ex.setErrorFields(errorFields);
throw ex;
}
}
use of com.salesmanager.core.modules.integration.IntegrationException 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);
}
}
use of com.salesmanager.core.modules.integration.IntegrationException 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);
}
}
use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.
the class ShippingDistancePreProcessorImpl method prePostProcessShippingQuotes.
public void prePostProcessShippingQuotes(ShippingQuote quote, List<PackageDetails> packages, BigDecimal orderTotal, Delivery delivery, ShippingOrigin origin, MerchantStore store, IntegrationConfiguration globalShippingConfiguration, IntegrationModule currentModule, ShippingConfiguration shippingConfiguration, List<IntegrationModule> allModules, Locale locale) throws IntegrationException {
if (delivery.getZone() == null) {
return;
}
boolean zoneAllowed = false;
if (allowedZonesCodes != null) {
for (String zoneCode : allowedZonesCodes) {
if (zoneCode.equals(delivery.getZone().getCode())) {
zoneAllowed = true;
break;
}
}
}
if (!zoneAllowed) {
return;
}
if (StringUtils.isBlank(delivery.getPostalCode())) {
return;
}
Validate.notNull(apiKey, "Requires the configuration of google apiKey");
GeoApiContext context = new GeoApiContext().setApiKey(apiKey);
// build origin address
StringBuilder originAddress = new StringBuilder();
originAddress.append(origin.getAddress()).append(BLANK).append(origin.getCity()).append(BLANK).append(origin.getPostalCode()).append(BLANK);
if (!StringUtils.isBlank(origin.getState())) {
originAddress.append(origin.getState()).append(" ");
}
if (origin.getZone() != null) {
originAddress.append(origin.getZone().getCode()).append(" ");
}
originAddress.append(origin.getCountry().getIsoCode());
// build destination address
StringBuilder destinationAddress = new StringBuilder();
destinationAddress.append(delivery.getAddress()).append(BLANK);
if (!StringUtils.isBlank(delivery.getCity())) {
destinationAddress.append(delivery.getCity()).append(BLANK);
}
destinationAddress.append(delivery.getPostalCode()).append(BLANK);
if (!StringUtils.isBlank(delivery.getState())) {
destinationAddress.append(delivery.getState()).append(" ");
}
if (delivery.getZone() != null) {
destinationAddress.append(delivery.getZone().getCode()).append(" ");
}
destinationAddress.append(delivery.getCountry().getIsoCode());
try {
GeocodingResult[] originAdressResult = GeocodingApi.geocode(context, originAddress.toString()).await();
GeocodingResult[] destinationAdressResult = GeocodingApi.geocode(context, destinationAddress.toString()).await();
if (originAdressResult.length > 0 && destinationAdressResult.length > 0) {
LatLng originLatLng = originAdressResult[0].geometry.location;
LatLng destinationLatLng = destinationAdressResult[0].geometry.location;
delivery.setLatitude(String.valueOf(destinationLatLng.lat));
delivery.setLongitude(String.valueOf(destinationLatLng.lng));
// keep latlng for further usage in order to display the map
DistanceMatrix distanceRequest = DistanceMatrixApi.newRequest(context).origins(new LatLng(originLatLng.lat, originLatLng.lng)).destinations(new LatLng(destinationLatLng.lat, destinationLatLng.lng)).awaitIgnoreError();
if (distanceRequest != null) {
DistanceMatrixRow distanceMax = distanceRequest.rows[0];
Distance distance = distanceMax.elements[0].distance;
quote.getQuoteInformations().put(Constants.DISTANCE_KEY, 0.001 * distance.inMeters);
} else {
LOGGER.error("Expected distance inner google api to return DistanceMatrix, it returned null. API key might not be working for this request");
}
}
} catch (Exception e) {
LOGGER.error("Exception while calculating the shipping distance", e);
}
}
Aggregations