use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class PaymentServiceImpl method initTransaction.
@Override
public Transaction initTransaction(Order order, Customer customer, Payment payment, MerchantStore store) throws ServiceException {
Validate.notNull(store);
Validate.notNull(payment);
Validate.notNull(order);
Validate.notNull(order.getTotal());
payment.setCurrency(store.getCurrency());
BigDecimal amount = order.getTotal();
// must have a shipping module configured
Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
if (modules == null) {
throw new ServiceException("No payment module configured");
}
IntegrationConfiguration configuration = modules.get(payment.getModuleName());
if (configuration == null) {
throw new ServiceException("Payment module " + payment.getModuleName() + " is not configured");
}
if (!configuration.isActive()) {
throw new ServiceException("Payment module " + payment.getModuleName() + " is not active");
}
PaymentModule module = this.paymentModules.get(order.getPaymentModuleCode());
if (module == null) {
throw new ServiceException("Payment module " + order.getPaymentModuleCode() + " does not exist");
}
IntegrationModule integrationModule = getPaymentMethodByCode(store, payment.getModuleName());
return module.initTransaction(store, customer, amount, payment, configuration, integrationModule);
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class PaymentServiceImpl method processRefund.
@Override
public Transaction processRefund(Order order, Customer customer, MerchantStore store, BigDecimal amount) throws ServiceException {
Validate.notNull(customer);
Validate.notNull(store);
Validate.notNull(amount);
Validate.notNull(order);
Validate.notNull(order.getOrderTotal());
BigDecimal orderTotal = order.getTotal();
if (amount.doubleValue() > orderTotal.doubleValue()) {
throw new ServiceException("Invalid amount, the refunded amount is greater than the total allowed");
}
String module = order.getPaymentModuleCode();
Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
if (modules == null) {
throw new ServiceException("No payment module configured");
}
IntegrationConfiguration configuration = modules.get(module);
if (configuration == null) {
throw new ServiceException("Payment module " + module + " is not configured");
}
PaymentModule paymentModule = this.paymentModules.get(module);
if (paymentModule == null) {
throw new ServiceException("Payment module " + paymentModule + " does not exist");
}
boolean partial = false;
if (amount.doubleValue() != order.getTotal().doubleValue()) {
partial = true;
}
IntegrationModule integrationModule = getPaymentMethodByCode(store, module);
// get the associated transaction
Transaction refundable = transactionService.getRefundableTransaction(order);
if (refundable == null) {
throw new ServiceException("No refundable transaction for this order");
}
Transaction transaction = paymentModule.refund(partial, store, refundable, order, amount, configuration, integrationModule);
transaction.setOrder(order);
transactionService.create(transaction);
OrderTotal refund = new OrderTotal();
refund.setModule(Constants.OT_REFUND_MODULE_CODE);
refund.setText(Constants.OT_REFUND_MODULE_CODE);
refund.setTitle(Constants.OT_REFUND_MODULE_CODE);
refund.setOrderTotalCode(Constants.OT_REFUND_MODULE_CODE);
refund.setOrderTotalType(OrderTotalType.REFUND);
refund.setValue(amount);
refund.setSortOrder(100);
refund.setOrder(order);
order.getOrderTotal().add(refund);
// update order total
orderTotal = orderTotal.subtract(amount);
// update ordertotal refund
Set<OrderTotal> totals = order.getOrderTotal();
for (OrderTotal total : totals) {
if (total.getModule().equals(Constants.OT_TOTAL_MODULE_CODE)) {
total.setValue(orderTotal);
}
}
order.setTotal(orderTotal);
order.setStatus(OrderStatus.REFUNDED);
OrderStatusHistory orderHistory = new OrderStatusHistory();
orderHistory.setOrder(order);
orderHistory.setStatus(OrderStatus.REFUNDED);
orderHistory.setDateAdded(new Date());
order.getOrderHistory().add(orderHistory);
orderService.saveOrUpdate(order);
return transaction;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class TransactionServiceImpl method getCapturableTransaction.
@Override
public Transaction getCapturableTransaction(Order order) throws ServiceException {
List<Transaction> transactions = transactionRepository.findByOrder(order.getId());
ObjectMapper mapper = new ObjectMapper();
Transaction capturable = null;
for (Transaction transaction : transactions) {
if (transaction.getTransactionType().name().equals(TransactionType.AUTHORIZE.name())) {
if (!StringUtils.isBlank(transaction.getDetails())) {
try {
@SuppressWarnings("unchecked") Map<String, String> objects = mapper.readValue(transaction.getDetails(), Map.class);
transaction.setTransactionDetails(objects);
capturable = transaction;
} catch (Exception e) {
throw new ServiceException(e);
}
}
}
if (transaction.getTransactionType().name().equals(TransactionType.CAPTURE.name())) {
break;
}
if (transaction.getTransactionType().name().equals(TransactionType.REFUND.name())) {
break;
}
}
return capturable;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ZoneServiceImpl method getZones.
@SuppressWarnings("unchecked")
@Override
public List<Zone> getZones(String countryCode, Language language) throws ServiceException {
Validate.notNull(countryCode, "countryCode cannot be null");
Validate.notNull(language, "Language cannot be null");
List<Zone> zones = null;
try {
String cacheKey = ZONE_CACHE_PREFIX + countryCode + Constants.UNDERSCORE + language.getCode();
zones = (List<Zone>) cache.getFromCache(cacheKey);
if (zones == null) {
zones = zoneRepository.listByLanguageAndCountry(countryCode, language.getId());
// set names
for (Zone zone : zones) {
ZoneDescription description = zone.getDescriptions().get(0);
zone.setName(description.getName());
}
cache.putInCache(zones, cacheKey);
}
} catch (Exception e) {
LOGGER.error("getZones()", e);
}
return zones;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class SearchServiceImpl method index.
@Async
@SuppressWarnings("rawtypes")
public void index(MerchantStore store, Product product) throws ServiceException {
if (configuration.getProperty(INDEX_PRODUCTS) == null || configuration.getProperty(INDEX_PRODUCTS).equals(Constants.FALSE)) {
return;
}
FinalPrice price = pricingService.calculateProductPrice(product);
Set<ProductDescription> descriptions = product.getDescriptions();
for (ProductDescription description : descriptions) {
StringBuilder collectionName = new StringBuilder();
collectionName.append(PRODUCT_INDEX_NAME).append(UNDERSCORE).append(description.getLanguage().getCode()).append(UNDERSCORE).append(store.getCode().toLowerCase());
IndexProduct index = new IndexProduct();
index.setId(String.valueOf(product.getId()));
index.setStore(store.getCode().toLowerCase());
index.setLang(description.getLanguage().getCode());
index.setAvailable(product.isAvailable());
index.setDescription(description.getDescription());
index.setName(description.getName());
if (product.getManufacturer() != null) {
index.setManufacturer(String.valueOf(product.getManufacturer().getId()));
}
if (price != null) {
index.setPrice(price.getFinalPrice().doubleValue());
}
index.setHighlight(description.getProductHighlight());
if (!StringUtils.isBlank(description.getMetatagKeywords())) {
String[] tags = description.getMetatagKeywords().split(",");
@SuppressWarnings("unchecked") List<String> tagsList = new ArrayList(Arrays.asList(tags));
index.setTags(tagsList);
}
Set<Category> categories = product.getCategories();
if (!CollectionUtils.isEmpty(categories)) {
List<String> categoryList = new ArrayList<String>();
for (Category category : categories) {
categoryList.add(category.getCode());
}
index.setCategories(categoryList);
}
String jsonString = index.toJSONString();
try {
searchService.index(jsonString, collectionName.toString());
} catch (Exception e) {
throw new ServiceException("Cannot index product id [" + product.getId() + "], " + e.getMessage(), e);
}
}
}
Aggregations