use of com.salesmanager.shop.model.order.transaction.ReadableTransaction in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method captureOrder.
@Override
public ReadableTransaction captureOrder(MerchantStore store, Order order, Customer customer, Language language) throws Exception {
Transaction transactionModel = paymentService.processCapturePayment(order, customer, store);
ReadableTransaction transaction = new ReadableTransaction();
ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(transactionModel, transaction, store, language);
return transaction;
}
use of com.salesmanager.shop.model.order.transaction.ReadableTransaction in project shopizer by shopizer-ecommerce.
the class ReadableTransactionPopulator method populate.
@Override
public ReadableTransaction populate(Transaction source, ReadableTransaction target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableTransaction must not be null");
Validate.notNull(orderService, "OrderService must not be null");
Validate.notNull(pricingService, "OrderService must not be null");
if (target == null) {
target = new ReadableTransaction();
}
try {
target.setAmount(pricingService.getDisplayAmount(source.getAmount(), store));
target.setDetails(source.getDetails());
target.setPaymentType(source.getPaymentType());
target.setTransactionType(source.getTransactionType());
target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
target.setId(source.getId());
if (source.getOrder() != null) {
target.setOrderId(source.getOrder().getId());
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.shop.model.order.transaction.ReadableTransaction in project shopizer by shopizer-ecommerce.
the class OrderPaymentApi method init.
@RequestMapping(value = { "/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) throws Exception {
ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
if (cart == null) {
throw new ResourceNotFoundException("Cart code " + code + " does not exist");
}
PersistablePaymentPopulator populator = new PersistablePaymentPopulator();
populator.setPricingService(pricingService);
Payment paymentModel = new Payment();
populator.populate(payment, paymentModel, merchantStore, language);
Transaction transactionModel = paymentService.initTransaction(null, paymentModel, merchantStore);
ReadableTransaction transaction = new ReadableTransaction();
ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(transactionModel, transaction, merchantStore, language);
return transaction;
}
use of com.salesmanager.shop.model.order.transaction.ReadableTransaction in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method listTransactions.
@Override
public List<ReadableTransaction> listTransactions(Long orderId, MerchantStore store) {
Validate.notNull(orderId, "orderId must not be null");
Validate.notNull(store, "MerchantStore must not be null");
List<ReadableTransaction> trx = new ArrayList<ReadableTransaction>();
try {
Order modelOrder = orderService.getOrder(orderId, store);
if (modelOrder == null) {
throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
}
List<Transaction> transactions = transactionService.listTransactions(modelOrder);
ReadableTransaction transaction = null;
ReadableTransactionPopulator trxPopulator = null;
for (Transaction tr : transactions) {
transaction = new ReadableTransaction();
trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(tr, transaction, store, store.getDefaultLanguage());
trx.add(transaction);
}
return trx;
} catch (Exception e) {
LOGGER.error("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
throw new ServiceRuntimeException("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
}
}
use of com.salesmanager.shop.model.order.transaction.ReadableTransaction 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