Search in sources :

Example 16 with Transaction

use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.

the class OrderServiceImpl method getCapturableOrders.

@Override
public List<Order> getCapturableOrders(MerchantStore store, Date startDate, Date endDate) throws ServiceException {
    List<Transaction> transactions = transactionService.listTransactions(startDate, endDate);
    List<Order> returnOrders = null;
    if (!CollectionUtils.isEmpty(transactions)) {
        returnOrders = new ArrayList<Order>();
        // order id
        Map<Long, Order> preAuthOrders = new HashMap<Long, Order>();
        // order id
        Map<Long, List<Transaction>> processingTransactions = new HashMap<Long, List<Transaction>>();
        for (Transaction trx : transactions) {
            Order order = trx.getOrder();
            if (TransactionType.AUTHORIZE.name().equals(trx.getTransactionType().name())) {
                preAuthOrders.put(order.getId(), order);
            }
            // put transaction
            List<Transaction> listTransactions = null;
            if (processingTransactions.containsKey(order.getId())) {
                listTransactions = processingTransactions.get(order.getId());
            } else {
                listTransactions = new ArrayList<Transaction>();
                processingTransactions.put(order.getId(), listTransactions);
            }
            listTransactions.add(trx);
        }
        for (Long orderId : processingTransactions.keySet()) {
            List<Transaction> trx = processingTransactions.get(orderId);
            if (CollectionUtils.isNotEmpty(trx)) {
                boolean capturable = true;
                for (Transaction t : trx) {
                    if (TransactionType.CAPTURE.name().equals(t.getTransactionType().name())) {
                        capturable = false;
                    } else if (TransactionType.AUTHORIZECAPTURE.name().equals(t.getTransactionType().name())) {
                        capturable = false;
                    } else if (TransactionType.REFUND.name().equals(t.getTransactionType().name())) {
                        capturable = false;
                    }
                }
                if (capturable) {
                    Order o = preAuthOrders.get(orderId);
                    returnOrders.add(o);
                }
            }
        }
    }
    return returnOrders;
}
Also used : Order(com.salesmanager.core.model.order.Order) Transaction(com.salesmanager.core.model.payments.Transaction) HashMap(java.util.HashMap) OrderList(com.salesmanager.core.model.order.OrderList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with Transaction

use of com.salesmanager.core.model.payments.Transaction 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)

Example 18 with Transaction

use of com.salesmanager.core.model.payments.Transaction 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 19 with Transaction

use of com.salesmanager.core.model.payments.Transaction 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 20 with Transaction

use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.

the class PayPalExpressCheckoutPayment method capture.

@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    try {
        Validate.notNull(capturableTransaction, "Transaction cannot be null");
        Validate.notNull(capturableTransaction.getTransactionDetails().get("TRANSACTIONID"), "Transaction details must contain a TRANSACTIONID");
        Validate.notNull(order, "Order must not be null");
        Validate.notNull(order.getCurrency(), "Order nust contain Currency object");
        String mode = "sandbox";
        String env = configuration.getEnvironment();
        if (Constants.PRODUCTION_ENVIRONMENT.equals(env)) {
            mode = "production";
        }
        Map<String, String> configurationMap = new HashMap<String, String>();
        configurationMap.put("mode", mode);
        configurationMap.put("acct1.UserName", configuration.getIntegrationKeys().get("username"));
        configurationMap.put("acct1.Password", configuration.getIntegrationKeys().get("api"));
        configurationMap.put("acct1.Signature", configuration.getIntegrationKeys().get("signature"));
        DoCaptureReq doCaptureReq = new DoCaptureReq();
        BasicAmountType amount = new BasicAmountType();
        amount.setValue(pricingService.getStringAmount(order.getTotal(), store));
        amount.setCurrencyID(urn.ebay.apis.eBLBaseComponents.CurrencyCodeType.fromValue(order.getCurrency().getCode()));
        // DoCaptureRequest which takes mandatory params:
        // 
        // Authorization ID - Authorization identification number of the
        // payment you want to capture. This is the transaction ID
        DoCaptureRequestType doCaptureRequest = new DoCaptureRequestType(capturableTransaction.getTransactionDetails().get("TRANSACTIONID"), amount, CompleteCodeType.NOTCOMPLETE);
        doCaptureReq.setDoCaptureRequest(doCaptureRequest);
        // ## Creating service wrapper object
        // Creating service wrapper object to make API call and loading
        // configuration file for your credentials and endpoint
        PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
        DoCaptureResponseType doCaptureResponse = null;
        // ## Making API call
        // Invoke the appropriate method corresponding to API in service
        // wrapper object
        doCaptureResponse = service.doCapture(doCaptureReq);
        // ### Success values
        if (!"Success".equals(doCaptureResponse.getAck().getValue())) {
            LOGGER.error("Wrong value from transaction commit " + doCaptureResponse.getAck().getValue());
            throw new IntegrationException("Wrong paypal ack from refund transaction " + doCaptureResponse.getAck().getValue());
        }
        // if (doCaptureResponse.getAck().getValue()
        // .equalsIgnoreCase("success")) {
        // Authorization identification number
        // logger.info("Authorization ID:"
        // + doCaptureResponse.getDoCaptureResponseDetails()
        // .getAuthorizationID());
        // }
        // ### Error Values
        // Access error values from error list using getter methods
        // else {
        // List<ErrorType> errorList = doCaptureResponse.getErrors();
        // logger.severe("API Error Message : "
        // + errorList.get(0).getLongMessage());
        // }
        // String refundAck = refundTransactionResponse.getAck().getValue();
        Transaction newTransaction = new Transaction();
        newTransaction.setAmount(order.getTotal());
        newTransaction.setTransactionDate(new Date());
        newTransaction.setTransactionType(TransactionType.CAPTURE);
        newTransaction.setPaymentType(PaymentType.PAYPAL);
        newTransaction.getTransactionDetails().put("AUTHORIZATIONID", doCaptureResponse.getDoCaptureResponseDetails().getAuthorizationID());
        newTransaction.getTransactionDetails().put("TRANSACTIONID", capturableTransaction.getTransactionDetails().get("TRANSACTIONID"));
        return newTransaction;
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : DoCaptureReq(urn.ebay.api.PayPalAPI.DoCaptureReq) DoCaptureResponseType(urn.ebay.api.PayPalAPI.DoCaptureResponseType) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Transaction(com.salesmanager.core.model.payments.Transaction) HashMap(java.util.HashMap) DoCaptureRequestType(urn.ebay.api.PayPalAPI.DoCaptureRequestType) BasicAmountType(urn.ebay.apis.CoreComponentTypes.BasicAmountType) PayPalAPIInterfaceServiceService(urn.ebay.api.PayPalAPI.PayPalAPIInterfaceServiceService) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Aggregations

Transaction (com.salesmanager.core.model.payments.Transaction)38 Date (java.util.Date)25 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)17 ServiceException (com.salesmanager.core.business.exception.ServiceException)15 HashMap (java.util.HashMap)10 AuthenticationException (com.stripe.exception.AuthenticationException)9 CardException (com.stripe.exception.CardException)9 InvalidRequestException (com.stripe.exception.InvalidRequestException)9 StripeException (com.stripe.exception.StripeException)9 BraintreeGateway (com.braintreegateway.BraintreeGateway)5 Environment (com.braintreegateway.Environment)5 Order (com.salesmanager.core.model.order.Order)5 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)5 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)5 PaymentModule (com.salesmanager.core.modules.integration.payment.model.PaymentModule)5 ReadableTransaction (com.salesmanager.shop.model.order.transaction.ReadableTransaction)5 PaymentIntent (com.stripe.model.PaymentIntent)5 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)5 ValidationError (com.braintreegateway.ValidationError)4