Search in sources :

Example 1 with PersistableTransaction

use of com.salesmanager.shop.model.order.transaction.PersistableTransaction in project shopizer by shopizer-ecommerce.

the class PersistableTransactionPopulator method populate.

@Override
public Transaction populate(PersistableTransaction source, Transaction 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 Transaction();
    }
    try {
        target.setAmount(pricingService.getAmount(source.getAmount()));
        target.setDetails(source.getDetails());
        target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
        target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
        target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
        if (source.getOrderId() != null && source.getOrderId().longValue() > 0) {
            Order order = orderService.getById(source.getOrderId());
            if (order == null) {
                throw new ConversionException("Order with id " + source.getOrderId() + "does not exist");
            }
            target.setOrder(order);
        }
        return target;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
Also used : Order(com.salesmanager.core.model.order.Order) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableTransaction(com.salesmanager.shop.model.order.transaction.PersistableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Aggregations

ConversionException (com.salesmanager.core.business.exception.ConversionException)1 Order (com.salesmanager.core.model.order.Order)1 Transaction (com.salesmanager.core.model.payments.Transaction)1 PersistableTransaction (com.salesmanager.shop.model.order.transaction.PersistableTransaction)1