java.lang.Object
org.broadleafcommerce.core.pricing.service.tax.provider.SimpleTaxProvider
All Implemented Interfaces:
org.broadleafcommerce.common.config.service.ModuleProvider, TaxProvider

public class SimpleTaxProvider extends Object implements TaxProvider

Simple factor-based tax module that can be configured by adding rates for specific postalCodes, city, state, or country.

Through configuration, this module can be used to set a specific tax rate for items and shipping for a given postal code, city, state, or country.

Utilizes the fulfillment group's address to determine the tax location.

Useful for those with very simple tax needs that want to configure rates programmatically.

Author:
jfischer, brian polster, Phillip Verheyden (phillipuniverse)
  • Field Details

    • itemPostalCodeTaxRateMap

      protected Map<String,Double> itemPostalCodeTaxRateMap
    • itemCityTaxRateMap

      protected Map<String,Double> itemCityTaxRateMap
    • itemStateTaxRateMap

      protected Map<String,Double> itemStateTaxRateMap
    • itemCountryTaxRateMap

      protected Map<String,Double> itemCountryTaxRateMap
    • fulfillmentGroupPostalCodeTaxRateMap

      protected Map<String,Double> fulfillmentGroupPostalCodeTaxRateMap
    • fulfillmentGroupCityTaxRateMap

      protected Map<String,Double> fulfillmentGroupCityTaxRateMap
    • fulfillmentGroupStateTaxRateMap

      protected Map<String,Double> fulfillmentGroupStateTaxRateMap
    • fulfillmentGroupCountryTaxRateMap

      protected Map<String,Double> fulfillmentGroupCountryTaxRateMap
    • defaultItemTaxRate

      protected Double defaultItemTaxRate
    • defaultFulfillmentGroupTaxRate

      protected Double defaultFulfillmentGroupTaxRate
    • taxFees

      protected boolean taxFees
    • entityConfig

      protected org.broadleafcommerce.common.persistence.EntityConfiguration entityConfig
  • Constructor Details

    • SimpleTaxProvider

      public SimpleTaxProvider()
  • Method Details

    • canRespond

      public boolean canRespond(org.broadleafcommerce.common.config.domain.ModuleConfiguration config)
      Specified by:
      canRespond in interface org.broadleafcommerce.common.config.service.ModuleProvider
    • calculateTaxForOrder

      public Order calculateTaxForOrder(Order order, org.broadleafcommerce.common.config.domain.ModuleConfiguration config) throws TaxException
      Description copied from interface: TaxProvider
      Calculates taxes on an entire order. Returns the order with taxes included.
      Specified by:
      calculateTaxForOrder in interface TaxProvider
      Returns:
      Throws:
      TaxException
    • handleFulfillmentGroupItemTaxes

      protected void handleFulfillmentGroupItemTaxes(FulfillmentGroup fulfillmentGroup)
    • handleFulfillmentGroupFeeTaxes

      protected void handleFulfillmentGroupFeeTaxes(FulfillmentGroup fulfillmentGroup)
    • handleFulfillmentGroupTaxes

      protected void handleFulfillmentGroupTaxes(FulfillmentGroup fulfillmentGroup)
    • applyTaxFactor

      protected void applyTaxFactor(List<TaxDetail> taxes, BigDecimal taxFactor, org.broadleafcommerce.common.money.Money taxMultiplier)
    • findExistingTaxDetail

      protected TaxDetail findExistingTaxDetail(List<TaxDetail> taxes)
    • commitTaxForOrder

      public Order commitTaxForOrder(Order order, org.broadleafcommerce.common.config.domain.ModuleConfiguration config) throws TaxException
      Description copied from interface: TaxProvider
      This method provides the implementation an opportunity to finalize taxes on the order. This is often required when tax sub systems require tax documents to be created on checkout. This method will typically be called by the checkout workflow, rather than by the pricing workflow. Some implementations may wish to do nothing in this method, except perhaps recalculate taxes.
      Specified by:
      commitTaxForOrder in interface TaxProvider
      Returns:
      Throws:
      TaxException
    • cancelTax

      public void cancelTax(Order order, org.broadleafcommerce.common.config.domain.ModuleConfiguration config) throws TaxException
      Description copied from interface: TaxProvider
      Some tax providers store tax details from an order on an external system for reporting and tax reconcilliation. This allows one to cancel or undo tax recording in an external system. Typically, this will be called to offset a call to commitTaxForOrder. This might be called, for example, in a rollback handler for a checkout workflow activity that calls commitTaxForOrder. Many implementations may wish to do nothing in this method.
      Specified by:
      cancelTax in interface TaxProvider
      Throws:
      TaxException
    • lookupPostalCodeRate

      public Double lookupPostalCodeRate(Map<String,Double> postalCodeTaxRateMap, String postalCode)
      Returns the taxAmount for the passed in postal code or null if no match is found.
      Parameters:
      postalCode -
      Returns:
    • lookupCityRate

      public Double lookupCityRate(Map<String,Double> cityTaxRateMap, String city)
      Changes the city to upper case before checking the configuration.

      Return null if no match is found.

      Parameters:
      cityTaxRateMap - , city
      Returns:
    • lookupStateRate

      public Double lookupStateRate(Map<String,Double> stateTaxRateMap, String stateProvinceRegion)
      Returns the taxAmount for the passed in stateProvinceRegion or null if no match is found.

      First checks the abbreviation (uppercase) followed by the name (uppercase).

      Parameters:
      stateTaxRateMap - , stateProvinceRegion
      Returns:
    • lookupCountryRate

      public Double lookupCountryRate(Map<String,Double> countryTaxRateMap, org.broadleafcommerce.profile.core.domain.Country country)
      Returns the taxAmount for the passed in country or null if no match is found.

      First checks the abbreviation (uppercase) followed by the name (uppercase).

      Parameters:
      countryTaxRateMap - , country
      Returns:
    • lookupCountryRate

      public Double lookupCountryRate(Map<String,Double> countryTaxRateMap, org.broadleafcommerce.common.i18n.domain.ISOCountry isoCountry)
      Returns the taxAmount for the passed in country or null if no match is found.

      First checks the alpha2 (uppercase) followed by the name (uppercase).

      Parameters:
      countryTaxRateMap - , isoCountry
      Returns:
    • isItemTaxable

      protected boolean isItemTaxable(FulfillmentGroupItem item)
    • isFeeTaxable

      protected boolean isFeeTaxable(FulfillmentGroupFee fee)
    • determineItemTaxRate

      public BigDecimal determineItemTaxRate(org.broadleafcommerce.profile.core.domain.Address address)
      Uses the passed in address to determine if the item is taxable.

      Checks the configured maps in order - (postal code, city, state, country)

      Parameters:
      address -
      Returns:
    • determineTaxRateForFulfillmentGroup

      public BigDecimal determineTaxRateForFulfillmentGroup(FulfillmentGroup fulfillmentGroup)
      Uses the passed in address to determine if the item is taxable.

      Checks the configured maps in order - (postal code, city, state, country)

      Parameters:
      fulfillmentGroup -
      Returns:
    • getItemPostalCodeTaxRateMap

      public Map<String,Double> getItemPostalCodeTaxRateMap()
    • setItemPostalCodeTaxRateMap

      public void setItemPostalCodeTaxRateMap(Map<String,Double> itemPostalCodeTaxRateMap)
    • getItemCityTaxRateMap

      public Map<String,Double> getItemCityTaxRateMap()
    • setItemCityTaxRateMap

      public void setItemCityTaxRateMap(Map<String,Double> itemCityTaxRateMap)
    • getItemStateTaxRateMap

      public Map<String,Double> getItemStateTaxRateMap()
    • setItemStateTaxRateMap

      public void setItemStateTaxRateMap(Map<String,Double> itemStateTaxRateMap)
    • getItemCountryTaxRateMap

      public Map<String,Double> getItemCountryTaxRateMap()
    • setItemCountryTaxRateMap

      public void setItemCountryTaxRateMap(Map<String,Double> itemCountryTaxRateMap)
    • getFulfillmentGroupPostalCodeTaxRateMap

      public Map<String,Double> getFulfillmentGroupPostalCodeTaxRateMap()
    • setFulfillmentGroupPostalCodeTaxRateMap

      public void setFulfillmentGroupPostalCodeTaxRateMap(Map<String,Double> fulfillmentGroupPostalCodeTaxRateMap)
    • getFulfillmentGroupCityTaxRateMap

      public Map<String,Double> getFulfillmentGroupCityTaxRateMap()
    • setFulfillmentGroupCityTaxRateMap

      public void setFulfillmentGroupCityTaxRateMap(Map<String,Double> fulfillmentGroupCityTaxRateMap)
    • getFulfillmentGroupStateTaxRateMap

      public Map<String,Double> getFulfillmentGroupStateTaxRateMap()
    • setFulfillmentGroupStateTaxRateMap

      public void setFulfillmentGroupStateTaxRateMap(Map<String,Double> fulfillmentGroupStateTaxRateMap)
    • getFulfillmentGroupCountryTaxRateMap

      public Map<String,Double> getFulfillmentGroupCountryTaxRateMap()
    • setFulfillmentGroupCountryTaxRateMap

      public void setFulfillmentGroupCountryTaxRateMap(Map<String,Double> fulfillmentGroupCountryTaxRateMap)
    • getDefaultItemTaxRate

      public Double getDefaultItemTaxRate()
    • setDefaultItemTaxRate

      public void setDefaultItemTaxRate(Double defaultItemTaxRate)
    • getDefaultFulfillmentGroupTaxRate

      public Double getDefaultFulfillmentGroupTaxRate()
    • setDefaultFulfillmentGroupTaxRate

      public void setDefaultFulfillmentGroupTaxRate(Double defaultFulfillmentGroupTaxRate)