use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class TransactionServiceImpl method listTransactions.
@Override
public List<Transaction> listTransactions(Order order) throws ServiceException {
List<Transaction> transactions = transactionRepository.findByOrder(order.getId());
ObjectMapper mapper = new ObjectMapper();
for (Transaction transaction : transactions) {
if (!StringUtils.isBlank(transaction.getDetails())) {
try {
@SuppressWarnings("unchecked") Map<String, String> objects = mapper.readValue(transaction.getDetails(), Map.class);
transaction.setTransactionDetails(objects);
} catch (Exception e) {
throw new ServiceException(e);
}
}
}
return transactions;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class TransactionServiceImpl method getRefundableTransaction.
@Override
public Transaction getRefundableTransaction(Order order) throws ServiceException {
List<Transaction> transactions = transactionRepository.findByOrder(order.getId());
Map<String, Transaction> finalTransactions = new HashMap<String, Transaction>();
Transaction finalTransaction = null;
for (Transaction transaction : transactions) {
if (transaction.getTransactionType().name().equals(TransactionType.AUTHORIZECAPTURE.name())) {
finalTransactions.put(TransactionType.AUTHORIZECAPTURE.name(), transaction);
continue;
}
if (transaction.getTransactionType().name().equals(TransactionType.CAPTURE.name())) {
finalTransactions.put(TransactionType.CAPTURE.name(), transaction);
continue;
}
if (transaction.getTransactionType().name().equals(TransactionType.REFUND.name())) {
// check transaction id
Transaction previousRefund = finalTransactions.get(TransactionType.REFUND.name());
if (previousRefund != null) {
Date previousDate = previousRefund.getTransactionDate();
Date currentDate = transaction.getTransactionDate();
if (previousDate.before(currentDate)) {
finalTransactions.put(TransactionType.REFUND.name(), transaction);
continue;
}
} else {
finalTransactions.put(TransactionType.REFUND.name(), transaction);
continue;
}
}
}
if (finalTransactions.containsKey(TransactionType.AUTHORIZECAPTURE.name())) {
finalTransaction = finalTransactions.get(TransactionType.AUTHORIZECAPTURE.name());
}
if (finalTransactions.containsKey(TransactionType.CAPTURE.name())) {
finalTransaction = finalTransactions.get(TransactionType.CAPTURE.name());
}
if (finalTransaction != null && !StringUtils.isBlank(finalTransaction.getDetails())) {
try {
ObjectMapper mapper = new ObjectMapper();
@SuppressWarnings("unchecked") Map<String, String> objects = mapper.readValue(finalTransaction.getDetails(), Map.class);
finalTransaction.setTransactionDetails(objects);
} catch (Exception e) {
throw new ServiceException(e);
}
}
return finalTransaction;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class OrderPaymentApi method init.
@RequestMapping(value = { "/auth/cart/{code}/payment/init" }, method = RequestMethod.POST)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableTransaction init(@Valid @RequestBody PersistablePayment payment, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while initializing the payment customer not authorized");
return null;
}
ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
if (cart == null) {
throw new ResourceNotFoundException("Cart code " + code + " does not exist");
}
if (cart.getCustomerId() == null) {
response.sendError(404, "Cart code " + code + " does not exist for exist for user " + userName);
return null;
}
if (cart.getCustomerId().longValue() != customer.getId().longValue()) {
response.sendError(404, "Cart code " + code + " does not exist for exist for user " + userName);
return null;
}
PersistablePaymentPopulator populator = new PersistablePaymentPopulator();
populator.setPricingService(pricingService);
Payment paymentModel = new Payment();
populator.populate(payment, paymentModel, merchantStore, language);
Transaction transactionModel = paymentService.initTransaction(customer, paymentModel, merchantStore);
ReadableTransaction transaction = new ReadableTransaction();
ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(transactionModel, transaction, merchantStore, language);
return transaction;
} catch (Exception e) {
LOGGER.error("Error while initializing the payment", e);
try {
response.sendError(503, "Error while initializing the payment " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations