Package com.broadleafcommerce.tax.simple
Class SimpleTaxProvider<T1 extends TaxRequest,T2 extends TaxResponse>
- java.lang.Object
-
- com.broadleafcommerce.tax.simple.SimpleTaxProvider<T1,T2>
-
- All Implemented Interfaces:
TaxProvider<T1,T2>
public class SimpleTaxProvider<T1 extends TaxRequest,T2 extends TaxResponse> extends Object implements TaxProvider<T1,T2>
Simple implementation ofTaxProvider
primarily used for estimating taxes, but can be used for providing full taxes for implementors without complex tax needs. Otherwise, aTaxProvider
integrated with a 3rd party, such as Avalara, is preferred. If this simple provider is intended to be used in a live production environment, the implementor must be aware that they own the consequences of tax law and must maintain the tax configuration details.This takes in a
SimpleTaxConfig
provided bySimpleTaxProperties.getConfigPath()
. This property can be configured with Spring Config Server, including Broadleaf's own implementation. This will allow changes to the property value to be reinitialized by this provider, as long as the declaring bean for this provider is annotated withRefreshScope
.- Author:
- Chad Harchar (charchar)
-
-
Constructor Summary
Constructors Constructor Description SimpleTaxProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, SimpleTaxProperties simpleTaxProps)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<T2>
calculateTaxes(List<T1> taxRequests, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
The simple tax provider determines tax rates by looking atSimpleTaxProperties.getConfigPath()
and mapping it into the data structureSimpleTaxConfig
.T2
calculateTaxes(T1 taxRequest)
Deprecated.protected SimpleTaxRecord
defaultIfNoneFound(SimpleTaxConfig simpleTaxConfig)
protected BigDecimal
determineRate(TaxItem item, SimpleTaxRecord chosenConfig)
protected Optional<SimpleTaxRecord>
findByCountry(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
protected Optional<SimpleTaxRecord>
findByPostalCode(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
protected Optional<SimpleTaxRecord>
findBySubdivision(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
protected Optional<SimpleTaxRecord>
findBySubdivisionAndCity(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
protected SimpleTaxRecord
getNoDefaultRateFound()
protected SimpleTaxRecord
getTaxConfig(T1 taxRequest, TaxItem item)
Determines the key to use for looking up tax records.protected TaxInfo
getTaxInfo(SimpleTaxRecord chosenConfig, TaxItem item, javax.money.CurrencyUnit currencyUnit)
protected TaxInfo
getTaxInfo(BigDecimal rate, TaxItem item, javax.money.CurrencyUnit currencyUnit)
Deprecated.since 1.7.protected T2
getTaxResponse(T1 taxRequest)
void
init()
protected boolean
isSubdivisionMatch(TaxAddress address, SimpleTaxRecord taxRecord)
protected Optional<SimpleTaxRecord>
lookupTaxConfig(SimpleTaxConfig simpleTaxConfig, TaxAddress toAddress)
protected Optional<SimpleTaxRecord>
lookupTaxConfig(SimpleTaxConfig simpleTaxConfig, TaxAddress toAddress, String lookupKey)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.tax.TaxProvider
commitTaxes
-
-
-
-
Constructor Detail
-
SimpleTaxProvider
public SimpleTaxProvider(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, SimpleTaxProperties simpleTaxProps)
-
-
Method Detail
-
init
@PostConstruct public void init() throws IOException
- Throws:
IOException
-
calculateTaxes
@Deprecated public T2 calculateTaxes(@NonNull T1 taxRequest)
Deprecated.The simple tax provider determines tax rates by looking atSimpleTaxProperties.getConfigPath()
and mapping it into the data structureSimpleTaxConfig
. This is then used to determine the most accurate correspondingSimpleTaxRecord
by the following priority, moving to the next item if no matching tax record is found:- Postal code
- City and subdivision (i.e. state, province, or region)
- Subdivision (i.e. state, province, or region)
- Country
- Specified by:
calculateTaxes
in interfaceTaxProvider<T1 extends TaxRequest,T2 extends TaxResponse>
- Parameters:
taxRequest
- The request for which to calculate taxes.- Returns:
- The
TaxResponse
response containing calculated taxes.
-
calculateTaxes
public List<T2> calculateTaxes(List<T1> taxRequests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
The simple tax provider determines tax rates by looking atSimpleTaxProperties.getConfigPath()
and mapping it into the data structureSimpleTaxConfig
. This is then used to determine the most accurate correspondingSimpleTaxRecord
by the following priority, moving to the next item if no matching tax record is found:- Postal code
- City and subdivision (i.e. state, province, or region)
- Subdivision (i.e. state, province, or region)
- Country
- Specified by:
calculateTaxes
in interfaceTaxProvider<T1 extends TaxRequest,T2 extends TaxResponse>
- Parameters:
taxRequests
- The request for which to calculate taxes.contextInfo
- Context information. May be null.- Returns:
- The
TaxResponse
response containing calculated taxes.
-
defaultIfNoneFound
protected SimpleTaxRecord defaultIfNoneFound(SimpleTaxConfig simpleTaxConfig)
-
getNoDefaultRateFound
protected SimpleTaxRecord getNoDefaultRateFound()
-
getTaxConfig
protected SimpleTaxRecord getTaxConfig(T1 taxRequest, TaxItem item)
Determines the key to use for looking up tax records. This will use the tax code from the item if available. Otherwise, it will use the country code from the taxRequest address. If there is no configuration for the tax code, it will try the country code before returning the default configuration.- Parameters:
taxRequest
- Represents a fulfillment group for tax calculations.item
- The item to be taxed.- Returns:
- A
SimpleTaxRecord
with a tax rate.
-
getTaxInfo
protected TaxInfo getTaxInfo(SimpleTaxRecord chosenConfig, TaxItem item, javax.money.CurrencyUnit currencyUnit)
-
determineRate
protected BigDecimal determineRate(TaxItem item, SimpleTaxRecord chosenConfig)
-
getTaxInfo
@Deprecated protected TaxInfo getTaxInfo(BigDecimal rate, TaxItem item, javax.money.CurrencyUnit currencyUnit)
Deprecated.since 1.7. UsegetTaxInfo(SimpleTaxRecord, TaxItem, CurrencyUnit)
.
-
lookupTaxConfig
protected Optional<SimpleTaxRecord> lookupTaxConfig(SimpleTaxConfig simpleTaxConfig, TaxAddress toAddress)
-
lookupTaxConfig
protected Optional<SimpleTaxRecord> lookupTaxConfig(SimpleTaxConfig simpleTaxConfig, TaxAddress toAddress, String lookupKey)
-
findByCountry
protected Optional<SimpleTaxRecord> findByCountry(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
-
findBySubdivision
protected Optional<SimpleTaxRecord> findBySubdivision(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
-
findByPostalCode
protected Optional<SimpleTaxRecord> findByPostalCode(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
-
findBySubdivisionAndCity
protected Optional<SimpleTaxRecord> findBySubdivisionAndCity(List<SimpleTaxRecord> taxTable, TaxAddress toAddress)
-
isSubdivisionMatch
protected boolean isSubdivisionMatch(TaxAddress address, SimpleTaxRecord taxRecord)
-
-