public class DefaultTaxService<F extends com.broadleafcommerce.cart.client.domain.FulfillmentGroup,TREQ extends com.broadleafcommerce.tax.domain.TaxRequest,TRES extends com.broadleafcommerce.tax.domain.TaxResponse,TI extends com.broadleafcommerce.tax.domain.TaxItem> extends Object implements TaxService
TaxService
which integrates with TaxProviders
. This
service connects to an actualTaxProvider
for accurate actual tax amounts and an optional
estimatedTaxProvider
for quick estimated tax amounts. Callers of this class can choose to
get taxes for either or both actual and estimated. A typical scenario would be to use a quick
synchronous call for estimated taxes when performing cart operations and then get the actual
taxes through a 3rd party provider once the cart is finalized in checkout and ready for the
customer to review final pricing.Constructor and Description |
---|
DefaultTaxService(com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> estimatedTaxProvider,
com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> actualTaxProvider,
com.broadleafcommerce.common.extension.TypeFactory typeFactory) |
DefaultTaxService(com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> estimatedTaxProvider,
com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> actualTaxProvider,
com.broadleafcommerce.common.extension.TypeFactory typeFactory,
List<TaxAddressSourceHandler> handlers) |
Modifier and Type | Method and Description |
---|---|
protected void |
addFulfillmentItemTaxDetails(com.broadleafcommerce.tax.domain.TaxResponse taxResponse,
com.broadleafcommerce.tax.domain.TaxInfo taxInfo,
com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem)
Add
FulfillmentItemTaxDetails to the fulfillment item. |
void |
applyTaxes(com.broadleafcommerce.cart.client.domain.Cart cart,
boolean estimated,
boolean actual,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Calculates and applies taxes to a cart.
|
protected void |
applyTaxesForGroup(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
F fulfillmentGroup,
@NonNull com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> taxProvider,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Deprecated.
|
protected void |
applyTaxesForGroups(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@NonNull List<F> fulfillmentGroups,
@NonNull com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> taxProvider,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Calculates and sets
FulfillmentItem.getMerchandiseTotalTax() and
FulfillmentGroup.getTotalTax() . |
protected void |
applyTaxesInternal(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@NonNull com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> taxProvider,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Performs the bulk of the tax calculations and application for a given
TaxProvider . |
protected void |
applyTaxResponse(TRES taxResponse,
F fulfillmentGroup,
javax.money.CurrencyUnit expectedCurrency)
Deprecated.
In favor of
applyTaxResponses(List, List, CurrencyUnit) |
protected void |
applyTaxResponses(List<TRES> taxResponses,
List<F> fulfillmentGroups,
javax.money.CurrencyUnit expectedCurrency) |
protected TI |
buildTaxItemForLineItem(F fulfillmentGroup,
@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem)
Deprecated.
Since 1.2. Use
#bu |
protected List<TI> |
buildTaxItemsForFulfillment(F fulfillmentGroup) |
protected List<TI> |
buildTaxItemsForLineItems(F fulfillmentGroup)
Deprecated.
Since 1.2. Use
buildTaxItemsForLineItems(FulfillmentGroup, Cart) |
protected Collection<? extends TI> |
buildTaxItemsForLineItems(F fulfillmentGroup,
com.broadleafcommerce.cart.client.domain.Cart cart) |
protected void |
calculateActualTaxesForCart(com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) |
protected void |
calculateEstimatedTaxesForCart(com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) |
boolean |
canCalculateTaxes(com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Whether the cart contains the information required to calculate taxes.
|
protected TaxAddressSourceHandler |
findTaxAddressSourceHandler(com.broadleafcommerce.cart.client.domain.Cart cart,
F fulfillmentGroup) |
protected com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> |
getActualTaxProvider() |
protected com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> |
getEstimatedTaxProvider() |
protected List<F> |
getFulfillmentGroups(com.broadleafcommerce.cart.client.domain.Cart cart) |
protected <T> T |
getInstance(Class<?> clazz) |
protected String |
getProductDescription(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
Retrieves the description of the product represented by the
CartItem . |
protected List<TaxAddressSourceHandler> |
getTaxAddressSourceHandlers() |
protected String |
getTaxItemIdForFulfillment(F fulfillmentGroup)
Extension point to modify the
TaxItem.getItemId() for fulfillment tax items. |
protected String |
getTaxItemIdForLineItem(F fulfillmentGroup,
@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem) |
protected TREQ |
getTaxRequest(com.broadleafcommerce.cart.client.domain.Cart cart,
F fulfillmentGroup,
TaxAddressSourceHandler handler,
List<TI> taxItems) |
protected Map<String,TRES> |
getTaxResponseMap(List<TRES> taxResponses)
Returns a map of tax responses, with the key as the
TaxResponse.getFulfillmentGroupReferenceNumber() |
protected com.broadleafcommerce.common.extension.TypeFactory |
getTypeFactory() |
protected void |
setAllTaxToZero(com.broadleafcommerce.cart.client.domain.Cart cart) |
protected boolean |
shouldCalculateItemTaxes(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) |
protected boolean |
shouldTaxFulfillment(F fulfillmentGroup,
javax.money.CurrencyUnit currencyUnit) |
public DefaultTaxService(@Nullable com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> estimatedTaxProvider, com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> actualTaxProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory, List<TaxAddressSourceHandler> handlers)
public boolean canCalculateTaxes(com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
TaxService
canCalculateTaxes
in interface TaxService
cart
- The cart to determine whether taxes can be calculated for.contextInfo
- Additional sandbox and tenant infopublic void applyTaxes(com.broadleafcommerce.cart.client.domain.Cart cart, boolean estimated, boolean actual, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
TaxService
applyTaxes
in interface TaxService
cart
- The cart to apply taxes against.estimated
- Whether to provide an estimateactual
- Whether to provide the actualcontextInfo
- Additional sandbox and tenant infoprotected void calculateActualTaxesForCart(com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void calculateEstimatedTaxesForCart(com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void applyTaxesInternal(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> taxProvider, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
TaxProvider
.cart
- Cart to be taxedtaxProvider
- The TaxProvider
to facilitate tax calculationsprotected void applyTaxesForGroups(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<F> fulfillmentGroups, @NonNull @NonNull com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> taxProvider, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
FulfillmentItem.getMerchandiseTotalTax()
and
FulfillmentGroup.getTotalTax()
.cart
- The cart with items to be taxedfulfillmentGroups
- The group to be taxed with items to be taxedtaxProvider
- The TaxProvider
that calculates the taxprotected Collection<? extends TI> buildTaxItemsForLineItems(F fulfillmentGroup, com.broadleafcommerce.cart.client.domain.Cart cart)
protected String getProductDescription(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
CartItem
.cartItem
- the CartItem
protected TREQ getTaxRequest(com.broadleafcommerce.cart.client.domain.Cart cart, F fulfillmentGroup, TaxAddressSourceHandler handler, List<TI> taxItems)
protected void applyTaxResponses(List<TRES> taxResponses, List<F> fulfillmentGroups, javax.money.CurrencyUnit expectedCurrency)
protected void addFulfillmentItemTaxDetails(com.broadleafcommerce.tax.domain.TaxResponse taxResponse, com.broadleafcommerce.tax.domain.TaxInfo taxInfo, com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem)
FulfillmentItemTaxDetails
to the fulfillment item.taxResponse
- The tax responsetaxInfo
- The tax infofulfillmentItem
- The fulfillment itemprotected Map<String,TRES> getTaxResponseMap(List<TRES> taxResponses)
TaxResponse.getFulfillmentGroupReferenceNumber()
taxResponses
- A list of tax responses@Deprecated protected void applyTaxesForGroup(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull F fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> taxProvider, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
applyTaxesForGroups(Cart, List, TaxProvider, ContextInfo)
FulfillmentItem.getMerchandiseTotalTax()
and
FulfillmentGroup.getTotalTax()
.cart
- The cart with items to be taxedfulfillmentGroup
- The group to be taxed with items to be taxedtaxProvider
- The TaxProvider
that facilitates calculating the taxprotected String getTaxItemIdForLineItem(@NonNull F fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem)
@Deprecated protected TI buildTaxItemForLineItem(@NonNull F fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem)
#bu
fulfillmentGroup
- fulfillmentItem
- protected List<TI> buildTaxItemsForFulfillment(@NonNull F fulfillmentGroup)
protected String getTaxItemIdForFulfillment(@NonNull F fulfillmentGroup)
TaxItem.getItemId()
for fulfillment tax items. For some
TaxProviders
, there may be a affix like FR
(for freight) to add
to the FulfillmentGroup.getReferenceNumber()
.fulfillmentGroup
- Fulfillment group from which to derive an idTaxItem.getItemId()
for fulfillment tax items@Deprecated protected void applyTaxResponse(@NonNull TRES taxResponse, @NonNull F fulfillmentGroup, javax.money.CurrencyUnit expectedCurrency)
applyTaxResponses(List, List, CurrencyUnit)
TaxResponse
and applies the results to the FulfillmentGroup
and its
items.taxResponse
- Tax response to applyfulfillmentGroup
- Group to which to apply the responseprotected void setAllTaxToZero(com.broadleafcommerce.cart.client.domain.Cart cart)
protected boolean shouldCalculateItemTaxes(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
@Deprecated protected List<TI> buildTaxItemsForLineItems(F fulfillmentGroup)
buildTaxItemsForLineItems(FulfillmentGroup, Cart)
fulfillmentGroup
- protected boolean shouldTaxFulfillment(F fulfillmentGroup, javax.money.CurrencyUnit currencyUnit)
@Nullable protected TaxAddressSourceHandler findTaxAddressSourceHandler(com.broadleafcommerce.cart.client.domain.Cart cart, F fulfillmentGroup)
protected <T> T getInstance(Class<?> clazz)
protected List<F> getFulfillmentGroups(com.broadleafcommerce.cart.client.domain.Cart cart)
@Nullable protected com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> getEstimatedTaxProvider()
protected com.broadleafcommerce.tax.TaxProvider<TREQ,TRES> getActualTaxProvider()
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
protected List<TaxAddressSourceHandler> getTaxAddressSourceHandlers()
Copyright © 2021. All rights reserved.