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