Search in sources :

Example 1 with TaxException

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

the class CommitTaxRollbackHandler method rollbackState.

@Override
public void rollbackState(Activity<ProcessContext<CheckoutSeed>> activity, ProcessContext<CheckoutSeed> processContext, Map<String, Object> stateConfiguration) throws RollbackFailureException {
    ProcessContext<CheckoutSeed> ctx = processContext;
    Order order = ctx.getSeedData().getOrder();
    try {
        taxService.cancelTax(order);
    } catch (TaxException e) {
        throw new RollbackFailureException("An exception occured cancelling taxes for order id: " + order.getId(), e);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) RollbackFailureException(org.broadleafcommerce.core.workflow.state.RollbackFailureException) TaxException(org.broadleafcommerce.core.pricing.service.exception.TaxException)

Example 2 with TaxException

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

the class TaxServiceImpl method calculateTaxForOrder.

@Override
public Order calculateTaxForOrder(Order order) throws TaxException {
    List<ModuleConfiguration> configurations = moduleConfigService.findActiveConfigurationsByType(ModuleConfigurationType.TAX_CALCULATION);
    // Try to find a default configuration
    ModuleConfiguration config = null;
    if (configurations != null) {
        for (ModuleConfiguration configuration : configurations) {
            if (configuration.getIsDefault()) {
                config = configuration;
                break;
            }
        }
        if (config == null && CollectionUtils.isNotEmpty(configurations)) {
            // if there wasn't a default one, use the first active one...
            config = configurations.get(0);
        }
    }
    if (CollectionUtils.isNotEmpty(providers)) {
        for (TaxProvider provider : providers) {
            if (provider.canRespond(config)) {
                return provider.calculateTaxForOrder(order, config);
            }
        }
    }
    // haven't returned anything, nothing must have run
    if (!mustCalculate) {
        return order;
    }
    throw new TaxException("No eligible tax providers were configured.");
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) TaxException(org.broadleafcommerce.core.pricing.service.exception.TaxException) TaxProvider(org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider)

Aggregations

TaxException (org.broadleafcommerce.core.pricing.service.exception.TaxException)2 ModuleConfiguration (org.broadleafcommerce.common.config.domain.ModuleConfiguration)1 Order (org.broadleafcommerce.core.order.domain.Order)1 TaxProvider (org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider)1 RollbackFailureException (org.broadleafcommerce.core.workflow.state.RollbackFailureException)1