Search in sources :

Example 36 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class CustomWeightBasedShippingQuote method getCustomModuleConfiguration.

@Override
public CustomIntegrationConfiguration getCustomModuleConfiguration(MerchantStore store) throws IntegrationException {
    try {
        MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(MODULE_CODE, store);
        if (configuration != null) {
            String value = configuration.getValue();
            ObjectMapper mapper = new ObjectMapper();
            try {
                return mapper.readValue(value, CustomShippingQuotesConfiguration.class);
            } catch (Exception e) {
                throw new ServiceException("Cannot parse json string " + value);
            }
        } else {
            CustomShippingQuotesConfiguration custom = new CustomShippingQuotesConfiguration();
            custom.setModuleCode(MODULE_CODE);
            return custom;
        }
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) CustomShippingQuotesConfiguration(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesConfiguration) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 37 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class CustomWeightBasedShippingQuote method getShippingQuotes.

@Override
public List<ShippingOption> getShippingQuotes(ShippingQuote shippingQuote, List<PackageDetails> packages, BigDecimal orderTotal, Delivery delivery, ShippingOrigin origin, MerchantStore store, IntegrationConfiguration configuration, IntegrationModule module, ShippingConfiguration shippingConfiguration, Locale locale) throws IntegrationException {
    if (StringUtils.isBlank(delivery.getPostalCode())) {
        return null;
    }
    // get configuration
    CustomShippingQuotesConfiguration customConfiguration = (CustomShippingQuotesConfiguration) this.getCustomModuleConfiguration(store);
    List<CustomShippingQuotesRegion> regions = customConfiguration.getRegions();
    ShippingBasisType shippingType = shippingConfiguration.getShippingBasisType();
    ShippingOption shippingOption = null;
    try {
        for (CustomShippingQuotesRegion region : customConfiguration.getRegions()) {
            for (String countryCode : region.getCountries()) {
                if (countryCode.equals(delivery.getCountry().getIsoCode())) {
                    // determine shipping weight
                    double weight = 0;
                    for (PackageDetails packageDetail : packages) {
                        weight = weight + packageDetail.getShippingWeight();
                    }
                    // see the price associated with the width
                    List<CustomShippingQuoteWeightItem> quoteItems = region.getQuoteItems();
                    for (CustomShippingQuoteWeightItem quoteItem : quoteItems) {
                        if (weight <= quoteItem.getMaximumWeight()) {
                            shippingOption = new ShippingOption();
                            shippingOption.setOptionCode(new StringBuilder().append(CUSTOM_WEIGHT).toString());
                            shippingOption.setOptionId(new StringBuilder().append(CUSTOM_WEIGHT).append("_").append(region.getCustomRegionName()).toString());
                            shippingOption.setOptionPrice(quoteItem.getPrice());
                            shippingOption.setOptionPriceText(productPriceUtils.getStoreFormatedAmountWithCurrency(store, quoteItem.getPrice()));
                            break;
                        }
                    }
                }
            }
        }
        if (shippingOption != null) {
            List<ShippingOption> options = new ArrayList<ShippingOption>();
            options.add(shippingOption);
            return options;
        }
        return null;
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : ShippingBasisType(com.salesmanager.core.model.shipping.ShippingBasisType) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) CustomShippingQuotesConfiguration(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesConfiguration) CustomShippingQuotesRegion(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuotesRegion) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) ShippingOption(com.salesmanager.core.model.shipping.ShippingOption) CustomShippingQuoteWeightItem(com.salesmanager.core.modules.integration.shipping.model.CustomShippingQuoteWeightItem) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails)

Example 38 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BeanStreamPayment method validateModuleConfiguration.

@Override
public void validateModuleConfiguration(IntegrationConfiguration integrationConfiguration, MerchantStore store) throws IntegrationException {
    List<String> errorFields = null;
    Map<String, String> keys = integrationConfiguration.getIntegrationKeys();
    // validate integrationKeys['merchantid']
    if (keys == null || StringUtils.isBlank(keys.get("merchantid"))) {
        errorFields = new ArrayList<String>();
        errorFields.add("merchantid");
    }
    // validate integrationKeys['username']
    if (keys == null || StringUtils.isBlank(keys.get("username"))) {
        if (errorFields == null) {
            errorFields = new ArrayList<String>();
        }
        errorFields.add("username");
    }
    // validate integrationKeys['password']
    if (keys == null || StringUtils.isBlank(keys.get("password"))) {
        if (errorFields == null) {
            errorFields = new ArrayList<String>();
        }
        errorFields.add("password");
    }
    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 39 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BeanStreamPayment method refund.

@Override
public Transaction refund(boolean partial, MerchantStore store, Transaction transaction, Order order, BigDecimal amount, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    HttpURLConnection conn = null;
    try {
        boolean bSandbox = false;
        if (configuration.getEnvironment().equals("TEST")) {
            // sandbox
            bSandbox = true;
        }
        ModuleConfig configs = module.getModuleConfigs().get("PROD");
        if (bSandbox) {
            configs = module.getModuleConfigs().get("TEST");
        }
        if (configs == null) {
            throw new IntegrationException("Module not configured for TEST or PROD");
        }
        String server = new StringBuffer().append(configs.getScheme()).append("://").append(configs.getHost()).append(":").append(configs.getPort()).append(configs.getUri()).toString();
        String trnID = transaction.getTransactionDetails().get("TRANSACTIONID");
        String amnt = productPriceUtils.getAdminFormatedAmount(store, amount);
        /**
         *			merchant_id=123456789&requestType=BACKEND
         *			&trnType=R&username=user1234&password=pass1234
         *			&trnOrderNumber=1234&trnAmount=1.00&adjId=1000
         *			2115
         */
        StringBuilder messageString = new StringBuilder();
        messageString.append("requestType=BACKEND&");
        messageString.append("merchant_id=").append(configuration.getIntegrationKeys().get("merchantid")).append("&");
        messageString.append("trnType=").append("R").append("&");
        messageString.append("username=").append(configuration.getIntegrationKeys().get("username")).append("&");
        messageString.append("password=").append(configuration.getIntegrationKeys().get("password")).append("&");
        messageString.append("trnOrderNumber=").append(transaction.getTransactionDetails().get("TRNORDERNUMBER")).append("&");
        messageString.append("trnAmount=").append(amnt).append("&");
        messageString.append("adjId=").append(trnID);
        LOGGER.debug("REQUEST SENT TO BEANSTREAM -> " + messageString.toString());
        URL postURL = new URL(server);
        conn = (HttpURLConnection) postURL.openConnection();
        return sendTransaction(null, store, messageString.toString(), "R", TransactionType.REFUND, PaymentType.CREDITCARD, amount, configuration, module);
    } catch (Exception e) {
        if (e instanceof IntegrationException)
            throw (IntegrationException) e;
        throw new IntegrationException("Error while processing BeanStream transaction", e);
    } finally {
        if (conn != null) {
            try {
                conn.disconnect();
            } catch (Exception ignore) {
            // TODO: handle exception
            }
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) ModuleConfig(com.salesmanager.core.model.system.ModuleConfig) URL(java.net.URL) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 40 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BraintreePayment method validateModuleConfiguration.

@Override
public void validateModuleConfiguration(IntegrationConfiguration integrationConfiguration, MerchantStore store) throws IntegrationException {
    List<String> errorFields = null;
    Map<String, String> keys = integrationConfiguration.getIntegrationKeys();
    // validate integrationKeys['merchant_id']
    if (keys == null || StringUtils.isBlank(keys.get("merchant_id"))) {
        errorFields = new ArrayList<String>();
        errorFields.add("merchant_id");
    }
    // validate integrationKeys['public_key']
    if (keys == null || StringUtils.isBlank(keys.get("public_key"))) {
        if (errorFields == null) {
            errorFields = new ArrayList<String>();
        }
        errorFields.add("public_key");
    }
    // validate integrationKeys['private_key']
    if (keys == null || StringUtils.isBlank(keys.get("private_key"))) {
        if (errorFields == null) {
            errorFields = new ArrayList<String>();
        }
        errorFields.add("private_key");
    }
    // validate integrationKeys['tokenization_key']
    if (keys == null || StringUtils.isBlank(keys.get("tokenization_key"))) {
        if (errorFields == null) {
            errorFields = new ArrayList<String>();
        }
        errorFields.add("tokenization_key");
    }
    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)

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