Search in sources :

Example 1 with ReadableTransactionPopulator

use of com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator 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;
}
Also used : ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction)

Example 2 with ReadableTransactionPopulator

use of com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator 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;
}
Also used : PersistablePayment(com.salesmanager.shop.model.order.transaction.PersistablePayment) Payment(com.salesmanager.core.model.payments.Payment) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) PersistablePaymentPopulator(com.salesmanager.shop.populator.order.transaction.PersistablePaymentPopulator) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ReadableTransactionPopulator

use of com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator 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() + "]");
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ReadableTransactionPopulator

use of com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator 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;
    }
}
Also used : PersistablePayment(com.salesmanager.shop.model.order.transaction.PersistablePayment) Payment(com.salesmanager.core.model.payments.Payment) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) Customer(com.salesmanager.core.model.customer.Customer) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) PersistablePaymentPopulator(com.salesmanager.shop.populator.order.transaction.PersistablePaymentPopulator) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Principal(java.security.Principal) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Transaction (com.salesmanager.core.model.payments.Transaction)4 ReadableTransaction (com.salesmanager.shop.model.order.transaction.ReadableTransaction)4 ReadableTransactionPopulator (com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator)4 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 Payment (com.salesmanager.core.model.payments.Payment)2 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)2 PersistablePayment (com.salesmanager.shop.model.order.transaction.PersistablePayment)2 PersistablePaymentPopulator (com.salesmanager.shop.populator.order.transaction.PersistablePaymentPopulator)2 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Customer (com.salesmanager.core.model.customer.Customer)1 Order (com.salesmanager.core.model.order.Order)1 ShopOrder (com.salesmanager.shop.model.order.ShopOrder)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1