Search in sources :

Example 6 with PricingException

use of org.broadleafcommerce.core.pricing.service.exception.PricingException in project BroadleafCommerce by BroadleafCommerce.

the class PricingServiceImpl method executePricing.

public Order executePricing(Order order) throws PricingException {
    try {
        ProcessContext<Order> context = (ProcessContext<Order>) pricingWorkflow.doActivities(order);
        Order response = context.getSeedData();
        return response;
    } catch (WorkflowException e) {
        throw new PricingException("Unable to execute pricing for order -- id: " + order.getId(), e);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) ProcessContext(org.broadleafcommerce.core.workflow.ProcessContext)

Example 7 with PricingException

use of org.broadleafcommerce.core.pricing.service.exception.PricingException in project BroadleafCommerce by BroadleafCommerce.

the class ConfirmPaymentsRollbackHandler method rollbackState.

@Override
public void rollbackState(Activity<ProcessContext<CheckoutSeed>> activity, ProcessContext<CheckoutSeed> processContext, Map<String, Object> stateConfiguration) throws RollbackFailureException {
    CheckoutSeed seed = processContext.getSeedData();
    if (paymentConfigurationServiceProvider == null) {
        throw new RollbackFailureException("There is no rollback service configured for the payment gateway configuration, cannot rollback unconfirmed" + " payments");
    }
    Map<OrderPayment, PaymentTransaction> rollbackResponseTransactions = new HashMap<>();
    Collection<PaymentTransaction> transactions = (Collection<PaymentTransaction>) stateConfiguration.get(ValidateAndConfirmPaymentActivity.ROLLBACK_TRANSACTIONS);
    if (CollectionUtils.isNotEmpty(transactions)) {
        for (PaymentTransaction tx : transactions) {
            PaymentRequestDTO rollbackRequest = transactionToPaymentRequestDTOService.translatePaymentTransaction(tx.getAmount(), tx);
            PaymentGatewayConfigurationService cfg = paymentConfigurationServiceProvider.getGatewayConfigurationService(tx.getOrderPayment().getGatewayType());
            try {
                PaymentResponseDTO responseDTO = null;
                if (PaymentTransactionType.AUTHORIZE.equals(tx.getType())) {
                    if (cfg.getRollbackService() != null) {
                        responseDTO = cfg.getRollbackService().rollbackAuthorize(rollbackRequest);
                    }
                } else if (PaymentTransactionType.AUTHORIZE_AND_CAPTURE.equals(tx.getType())) {
                    if (cfg.getRollbackService() != null) {
                        responseDTO = cfg.getRollbackService().rollbackAuthorizeAndCapture(rollbackRequest);
                    }
                } else {
                    LOG.warn("The transaction with id " + tx.getId() + " will NOT be rolled back as it is not an AUTHORIZE or AUTHORIZE_AND_CAPTURE transaction but is" + " of type " + tx.getType() + ". If you need to roll back transactions of this type then provide a customized rollback handler for" + " confirming transactions.");
                }
                if (responseDTO != null) {
                    PaymentTransaction transaction = orderPaymentService.createTransaction();
                    transaction.setAmount(responseDTO.getAmount());
                    transaction.setRawResponse(responseDTO.getRawResponse());
                    transaction.setSuccess(responseDTO.isSuccessful());
                    transaction.setType(responseDTO.getPaymentTransactionType());
                    transaction.setParentTransaction(tx);
                    transaction.setOrderPayment(tx.getOrderPayment());
                    transaction.setAdditionalFields(responseDTO.getResponseMap());
                    rollbackResponseTransactions.put(tx.getOrderPayment(), transaction);
                    if (!responseDTO.isSuccessful()) {
                        LOG.fatal("Unable to rollback transaction with id " + tx.getId() + ". The call was unsuccessful with" + " raw response: " + responseDTO.getRawResponse());
                    }
                }
            } catch (PaymentException e) {
                throw new RollbackFailureException("The transaction with id " + tx.getId() + " encountered and exception when it was attempted to roll back" + " its confirmation", e);
            }
        }
        Order order = seed.getOrder();
        List<OrderPayment> paymentsToInvalidate = new ArrayList<>();
        // Add the new rollback transactions to the appropriate payment and mark the payment as invalid.
        // If there was a failed transaction rolling back we will need to throw a RollbackFailureException after saving the
        // Transaction Response to the DB
        boolean rollbackFailure = false;
        for (OrderPayment payment : order.getPayments()) {
            if (rollbackResponseTransactions.containsKey(payment)) {
                PaymentTransaction rollbackTX = rollbackResponseTransactions.get(payment);
                payment.addTransaction(rollbackTX);
                payment = orderPaymentService.save(payment);
                paymentsToInvalidate.add(payment);
                if (!rollbackTX.getSuccess()) {
                    rollbackFailure = true;
                }
            }
        }
        for (OrderPayment payment : paymentsToInvalidate) {
            paymentGatewayCheckoutService.markPaymentAsInvalid(payment.getId());
            orderPaymentService.save(payment);
        }
        if (rollbackFailure) {
            throw new RollbackFailureException("The ConfirmPaymentsRollbackHandler encountered and exception when it " + "attempted to roll back a transaction on one of the payments. Please see LOG for details.");
        }
        try {
            processContext.getSeedData().setOrder(orderService.save(order, false));
        } catch (PricingException e) {
            throw new RollbackFailureException("Unable to save the order with invalidated payments.");
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) RollbackFailureException(org.broadleafcommerce.core.workflow.state.RollbackFailureException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) PaymentException(org.broadleafcommerce.common.vendor.service.exception.PaymentException) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) Collection(java.util.Collection) PaymentRequestDTO(org.broadleafcommerce.common.payment.dto.PaymentRequestDTO) PaymentGatewayConfigurationService(org.broadleafcommerce.common.payment.service.PaymentGatewayConfigurationService) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Example 8 with PricingException

use of org.broadleafcommerce.core.pricing.service.exception.PricingException in project BroadleafCommerce by BroadleafCommerce.

the class LegacyCartServiceImpl method updateItemQuantity.

@Override
public Order updateItemQuantity(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws UpdateCartException {
    try {
        Order order = findOrderById(orderId);
        updateItemQuantity(order, orderItemRequestDTO);
        return order;
    } catch (PricingException e) {
        throw new UpdateCartException("Could not update cart", e);
    } catch (ItemNotFoundException e) {
        throw new UpdateCartException("Could not update cart", e);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) UpdateCartException(org.broadleafcommerce.core.order.service.exception.UpdateCartException) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 9 with PricingException

use of org.broadleafcommerce.core.pricing.service.exception.PricingException in project BroadleafCommerce by BroadleafCommerce.

the class CartStateRequestProcessor method mergeCart.

/**
 * Looks up the anonymous customer and merges that cart with the cart from the given logged in <b>customer</b>. This
 * will also remove the customer from session after it has finished since it is no longer needed
 */
public Order mergeCart(Customer customer, WebRequest request) {
    Customer anonymousCustomer = customerStateRequestProcessor.getAnonymousCustomer(request);
    MergeCartResponse mergeCartResponse;
    try {
        Order cart = orderService.findCartForCustomer(anonymousCustomer);
        mergeCartResponse = mergeCartService.mergeCart(customer, cart);
    } catch (PricingException e) {
        throw new RuntimeException(e);
    } catch (RemoveFromCartException e) {
        throw new RuntimeException(e);
    }
    if (BLCRequestUtils.isOKtoUseSession(request)) {
        // The anonymous customer from session is no longer needed; it can be safely removed
        request.removeAttribute(CustomerStateRequestProcessor.getAnonymousCustomerSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION);
        request.removeAttribute(CustomerStateRequestProcessor.getAnonymousCustomerIdSessionAttributeName(), WebRequest.SCOPE_GLOBAL_SESSION);
        request.setAttribute(mergeCartResponseKey, mergeCartResponse, WebRequest.SCOPE_GLOBAL_SESSION);
    }
    return mergeCartResponse.getOrder();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) RemoveFromCartException(org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)

Example 10 with PricingException

use of org.broadleafcommerce.core.pricing.service.exception.PricingException in project BroadleafCommerce by BroadleafCommerce.

the class MergeCartProcessorImpl method execute.

@Override
public void execute(WebRequest request, Authentication authResult) {
    Customer loggedInCustomer = customerService.readCustomerByUsername(authResult.getName());
    Customer anonymousCustomer = customerStateRequestProcessor.getAnonymousCustomer(request);
    Order cart = null;
    if (anonymousCustomer != null) {
        cart = orderService.findCartForCustomer(anonymousCustomer);
    }
    MergeCartResponse mergeCartResponse;
    try {
        mergeCartResponse = mergeCartService.mergeCart(loggedInCustomer, cart);
    } catch (PricingException e) {
        throw new RuntimeException(e);
    } catch (RemoveFromCartException e) {
        throw new RuntimeException(e);
    }
    if (BLCRequestUtils.isOKtoUseSession(request)) {
        request.setAttribute(mergeCartResponseKey, mergeCartResponse, WebRequest.SCOPE_GLOBAL_SESSION);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PricingException(org.broadleafcommerce.core.pricing.service.exception.PricingException) Customer(org.broadleafcommerce.profile.core.domain.Customer) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse) RemoveFromCartException(org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)

Aggregations

PricingException (org.broadleafcommerce.core.pricing.service.exception.PricingException)11 Order (org.broadleafcommerce.core.order.domain.Order)7 RemoveFromCartException (org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)4 WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PaymentException (org.broadleafcommerce.common.vendor.service.exception.PaymentException)2 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)2 AddToCartException (org.broadleafcommerce.core.order.service.exception.AddToCartException)2 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)2 UpdateCartException (org.broadleafcommerce.core.order.service.exception.UpdateCartException)2 Customer (org.broadleafcommerce.profile.core.domain.Customer)2 Collection (java.util.Collection)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 PaymentRequestDTO (org.broadleafcommerce.common.payment.dto.PaymentRequestDTO)1 PaymentResponseDTO (org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)1 PaymentGatewayConfigurationService (org.broadleafcommerce.common.payment.service.PaymentGatewayConfigurationService)1 CheckoutException (org.broadleafcommerce.core.checkout.service.exception.CheckoutException)1