use of com.salesmanager.core.model.system.ModuleConfig 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.model.system.ModuleConfig in project shopizer by shopizer-ecommerce.
the class IntegrationModulesLoader method loadModule.
@SuppressWarnings({ "rawtypes", "unchecked" })
public IntegrationModule loadModule(Map object) throws Exception {
ObjectMapper mapper = new ObjectMapper();
IntegrationModule module = new IntegrationModule();
module.setModule((String) object.get("module"));
module.setCode((String) object.get("code"));
module.setImage((String) object.get("image"));
if (object.get("type") != null) {
module.setType((String) object.get("type"));
}
if (object.get("customModule") != null) {
Object o = object.get("customModule");
Boolean b = false;
if (o instanceof Boolean) {
b = (Boolean) object.get("customModule");
} else {
try {
b = Boolean.valueOf((String) object.get("customModule"));
} catch (Exception e) {
LOGGER.error("Cannot cast " + o.getClass() + " tp a boolean value");
}
}
module.setCustomModule(b);
}
// module.setRegions(regions)
if (object.get("details") != null) {
Map<String, String> details = (Map<String, String>) object.get("details");
module.setDetails(details);
// maintain the original json structure
StringBuilder detailsStructure = new StringBuilder();
int count = 0;
detailsStructure.append("{");
for (String key : details.keySet()) {
String jsonKeyString = mapper.writeValueAsString(key);
detailsStructure.append(jsonKeyString);
detailsStructure.append(":");
String jsonValueString = mapper.writeValueAsString(details.get(key));
detailsStructure.append(jsonValueString);
if (count < (details.size() - 1)) {
detailsStructure.append(",");
}
count++;
}
detailsStructure.append("}");
module.setConfigDetails(detailsStructure.toString());
}
List confs = (List) object.get("configuration");
if (confs != null) {
StringBuilder configString = new StringBuilder();
configString.append("[");
Map<String, ModuleConfig> moduleConfigs = new HashMap<String, ModuleConfig>();
int count = 0;
for (Object oo : confs) {
Map values = (Map) oo;
String env = (String) values.get("env");
ModuleConfig config = new ModuleConfig();
config.setScheme((String) values.get("scheme"));
config.setHost((String) values.get("host"));
config.setPort((String) values.get("port"));
config.setUri((String) values.get("uri"));
config.setEnv((String) values.get("env"));
if (values.get("config1") != null) {
config.setConfig1((String) values.get("config1"));
}
if (values.get("config2") != null) {
config.setConfig2((String) values.get("config2"));
}
String jsonConfigString = mapper.writeValueAsString(config);
configString.append(jsonConfigString);
moduleConfigs.put(env, config);
if (count < (confs.size() - 1)) {
configString.append(",");
}
count++;
}
configString.append("]");
module.setConfiguration(configString.toString());
module.setModuleConfigs(moduleConfigs);
}
List<String> regions = (List<String>) object.get("regions");
if (regions != null) {
StringBuilder configString = new StringBuilder();
configString.append("[");
int count = 0;
for (String region : regions) {
module.getRegionsSet().add(region);
String jsonConfigString = mapper.writeValueAsString(region);
configString.append(jsonConfigString);
if (count < (regions.size() - 1)) {
configString.append(",");
}
count++;
}
configString.append("]");
module.setRegions(configString.toString());
}
return module;
}
Aggregations