Search in sources :

Example 1 with PersistablePayment

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

the class PersistablePaymentPopulator method populate.

@Override
public Payment populate(PersistablePayment source, Payment target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(source, "PersistablePayment cannot be null");
    Validate.notNull(pricingService, "pricingService must be set");
    if (target == null) {
        target = new Payment();
    }
    try {
        target.setAmount(pricingService.getAmount(source.getAmount()));
        target.setModuleName(source.getPaymentModule());
        target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
        target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
        Map<String, String> metadata = new HashMap<String, String>();
        metadata.put("paymentToken", source.getPaymentToken());
        target.setPaymentMetaData(metadata);
        return target;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistablePayment(com.salesmanager.shop.model.order.transaction.PersistablePayment) Payment(com.salesmanager.core.model.payments.Payment) HashMap(java.util.HashMap) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 2 with PersistablePayment

use of com.salesmanager.shop.model.order.transaction.PersistablePayment 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 PersistablePayment

use of com.salesmanager.shop.model.order.transaction.PersistablePayment 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

Payment (com.salesmanager.core.model.payments.Payment)3 PersistablePayment (com.salesmanager.shop.model.order.transaction.PersistablePayment)3 Transaction (com.salesmanager.core.model.payments.Transaction)2 ShoppingCart (com.salesmanager.core.model.shoppingcart.ShoppingCart)2 ReadableTransaction (com.salesmanager.shop.model.order.transaction.ReadableTransaction)2 PersistablePaymentPopulator (com.salesmanager.shop.populator.order.transaction.PersistablePaymentPopulator)2 ReadableTransactionPopulator (com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)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 Customer (com.salesmanager.core.model.customer.Customer)1 Principal (java.security.Principal)1 HashMap (java.util.HashMap)1