Search in sources :

Example 21 with IntegrationException

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;
    }
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 22 with IntegrationException

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;
    }
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 23 with IntegrationException

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);
    }
}
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 24 with IntegrationException

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);
    }
}
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 25 with IntegrationException

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);
    }
}
Also used : GeocodingResult(com.google.maps.model.GeocodingResult) LatLng(com.google.maps.model.LatLng) DistanceMatrix(com.google.maps.model.DistanceMatrix) GeoApiContext(com.google.maps.GeoApiContext) DistanceMatrixRow(com.google.maps.model.DistanceMatrixRow) Distance(com.google.maps.model.Distance) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Aggregations

IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)42 Date (java.util.Date)18 Transaction (com.salesmanager.core.model.payments.Transaction)17 AuthenticationException (com.stripe.exception.AuthenticationException)11 CardException (com.stripe.exception.CardException)11 InvalidRequestException (com.stripe.exception.InvalidRequestException)11 StripeException (com.stripe.exception.StripeException)11 HashMap (java.util.HashMap)10 ServiceException (com.salesmanager.core.business.exception.ServiceException)9 ArrayList (java.util.ArrayList)8 ModuleConfig (com.salesmanager.core.model.system.ModuleConfig)5 PaymentIntent (com.stripe.model.PaymentIntent)5 BraintreeGateway (com.braintreegateway.BraintreeGateway)4 Environment (com.braintreegateway.Environment)4 ValidationError (com.braintreegateway.ValidationError)4 ShippingOption (com.salesmanager.core.model.shipping.ShippingOption)4 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)4 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)4 ShippingQuoteModule (com.salesmanager.core.modules.integration.shipping.model.ShippingQuoteModule)4 Charge (com.stripe.model.Charge)4