Class DefaultDelegatingTaxService
java.lang.Object
com.broadleafcommerce.cartoperation.service.pricing.DefaultDelegatingTaxService
- All Implemented Interfaces:
TaxService
This implementation of
TaxService calls TaxDelegate, which has a discovery
process to determine the best TaxProvider implementation based on configured properties,
the provided TaxCalculationRequest, and the ContextInfo.- Author:
- Kelly Tisdell (ktisdell)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe reference number used for COD Fee Items'TaxCalculationRequest.static final StringDefault name for theTaxDetailfor taxes associated with fulfillment, shipping, and handling.static final StringThe reference number used for Extra Fee Items'TaxCalculationRequest.The list of shipping fulfillment types which are applicable for Retail Delivery Fees.static final StringThe prefix used for RDF Fee Items'TaxItem.getItemId().protected static final SecureRandom -
Constructor Summary
ConstructorsConstructorDescriptionDefaultDelegatingTaxService(@NonNull com.broadleafcommerce.tax.delegate.TaxDelegate<?, ?> taxDelegate, List<TaxAddressSourceHandler> taxAddressSourceHandlers, @NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFulfillmentItemTaxDetails(@NonNull com.broadleafcommerce.tax.domain.TaxInfo taxInfo, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This takes the total from theFulfillmentGroup.getFulfillmentTaxableAmount().protected voidaddFulfillmentItemTaxDetails(@NonNull com.broadleafcommerce.tax.domain.TaxInfo taxInfo, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) AddFulfillmentItemTaxDetailsto the fulfillment item.protected javax.money.MonetaryAmountapplyCODTaxResponse(@NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies theTaxCalculationResponsefor COD fees.protected javax.money.MonetaryAmountapplyFeeTaxResponse(@NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull javax.money.CurrencyUnit expectedCurrency, @NonNull String referenceNumber, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies theTaxCalculationResponsefor fees.protected javax.money.MonetaryAmountapplyFulfillmentTaxDetails(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.tax.domain.TaxResponseGroup taxResponseGroup, javax.money.MonetaryAmount totalGroupTax, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected javax.money.MonetaryAmountapplyRDFTaxResponse(@NonNull com.broadleafcommerce.tax.domain.TaxResponseGroup taxResponseGroup, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies theTaxCalculationResponsefor RDF fees.voidapplyTaxes(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, boolean estimate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Calculates and applies taxes to a cart.protected voidapplyTaxResponses(@NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<com.broadleafcommerce.cart.client.domain.FulfillmentGroup> fulfillmentGroups, @NonNull javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected <T extends com.broadleafcommerce.tax.domain.TaxItem>
com.broadleafcommerce.tax.domain.TaxCalculationGroupbuildTaxCalculationGroup(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull TaxAddressSourceHandler handler, @NonNull Collection<T> taxItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aTaxCalculationGroup, which is used to calculate taxes for a group of items being shipped to or fulfilled at a particular Address.protected com.broadleafcommerce.tax.domain.TaxItembuildTaxItemForFeeItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Builds aTaxItembased on the givenfee item.protected com.broadleafcommerce.tax.domain.TaxItembuildTaxItemForLineItem(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.tax.domain.TaxItem>buildTaxItemsForFulfillment(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) Deprecated.protected List<com.broadleafcommerce.tax.domain.TaxItem>buildTaxItemsForFulfillment(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.tax.domain.TaxItem>buildTaxItemsForLineItems(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidcalculateIncludedTaxes(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull javax.money.CurrencyUnit expectedCurrency, @NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse taxResponse) In some situations, taxes are included in the price of the item.booleancanCalculateTaxes(@NonNull 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 com.broadleafcommerce.tax.domain.TaxCalculationRequestcreateRequest(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull javax.money.CurrencyUnit expectedCurrency, boolean estimate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voiddebugLogTrimmedTaxResponse(@NotNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response) protected StringdetermineCartId(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) We require theCart.getId(), in most cases.protected StringdeterminePreferredProviderId(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, boolean estimate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This method returns the "preferred"Tax Provider ID, which is determined byTaxProvider.getProviderId().protected StringdetermineTaxExemptionCode(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.protected com.broadleafcommerce.tax.domain.TaxCalculationResponseexecuteTaxCalculation(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected TaxAddressSourceHandlerfindTaxAddressSourceHandler(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected Optional<TaxAddressSourceHandler>findTaxAddressSourceHandlerForCODFeeTaxCalculation(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theTaxAddressSourceHandlerfor tax calculation for Collect on Delivery fees.protected Optional<TaxAddressSourceHandler>findTaxAddressSourceHandlerForExtraFeeTaxCalculation(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theTaxAddressSourceHandlerfor tax calculation for extra fees.protected booleanfulfillmentGroupHasSufficientAddress(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fg, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenFulfillmentGrouphas sufficient address to calculate taxes.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtilsgetCartItemMap(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) getCartItemMap(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, String cartItemType) protected CustomerProviderprotected DelegatingTaxServicePropertiesprotected StringgetExtraFeeReferenceNumber(String referenceNumber) Calculating taxes usually requires an address to determine the jurisdiction.protected Optional<com.broadleafcommerce.cart.client.domain.FulfillmentGroup>getFulfillmentGroupForCOD(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets theFulfillmentGroupthat has CollectOnDelivery selected from the givenCart.protected List<com.broadleafcommerce.cart.client.domain.FulfillmentGroup>getFulfillmentGroups(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) protected com.fasterxml.jackson.databind.ObjectMapperprotected StringgetProductDescription(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Retrieves the description of the product represented by theCartItem.protected javax.money.MonetaryAmountgetTaxableItemFulfillmentTotal(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fg, javax.money.CurrencyUnit currency) protected List<TaxAddressSourceHandler>protected com.broadleafcommerce.tax.delegate.TaxDelegate<?,?> protected StringgetTaxItemIdForFulfillment(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) Extension point to modify theTaxItem.getItemId()for fulfillment tax items.protected StringgetTaxItemIdForLineItem(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem) protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanhasNoTaxItems(com.broadleafcommerce.tax.domain.TaxCalculationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determine if there are tax items on the given request.protected voidincludeCODFeesInTaxRequest(@NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles includingCollect/Credit on Delivery feesin aTaxCalculationRequest.protected voidincludeExtraFeesInTaxRequest(@NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles includingextra feesin aTaxCalculationRequest.protected voidincludeExtraFeesInTaxRequest(com.broadleafcommerce.tax.domain.TaxCalculationRequest request, com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, Set<com.broadleafcommerce.tax.domain.TaxItem> items, TaxAddressSourceHandler handler, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles includingextra feesin aTaxCalculationRequest.protected voidincludeFeesInTaxRequest(@NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles including extra and COD fees in aTaxCalculationRequest.protected booleanisCODSelected(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) protected booleanisGroupFulfillmentTaxable(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fg) protected booleanisItemIncludesTaxes(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) In some situations, especially in European countries, for example, merchants are required to display all prices including tax.protected <T extends com.broadleafcommerce.tax.domain.TaxItem>
Map<com.broadleafcommerce.cart.client.domain.FulfillmentGroup,Set<T>> mapFulfillmentGroupsToExtraFees(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Set<T> taxItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines theFulfillmentGroupto use for extra fee tax calculations.protected voidpersistTaxResponseOnCart(@NotNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NotNull com.broadleafcommerce.cart.client.domain.Cart cart) protected voidsetAllTaxToZero(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) voidsetAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) protected voidsetCustomerAndAccountPropertiesOnRequest(com.broadleafcommerce.tax.domain.TaxCalculationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) voidsetCustomerProvider(CustomerProvider customerProvider) voidsetDelegatingTaxServiceProperties(DelegatingTaxServiceProperties delegatingTaxServiceProperties) voidsetMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) protected booleanshouldCalculateItemTaxes(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected booleanshouldConsiderRDFFee(@NonNull com.broadleafcommerce.tax.domain.TaxResponseGroup taxResponseGroup, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) Hook point to enable/disable building Retail Delivery Fee from theTaxResponseGroup.protected booleanshouldTaxFulfillment(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull javax.money.CurrencyUnit currencyUnit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.cartoperation.service.pricing.TaxService
applyTaxes
-
Field Details
-
SECURE_RANDOM
-
RETAIL_DELIVERY_FEE_PREFIX
The prefix used for RDF Fee Items'TaxItem.getItemId().- See Also:
-
COD_REFERENCE_NUMBER
The reference number used for COD Fee Items'TaxCalculationRequest.- See Also:
-
FEE_REFERENCE_NUMBER
The reference number used for Extra Fee Items'TaxCalculationRequest.- See Also:
-
DEFAULT_FULFILLMENT_TAX_NAME
Default name for theTaxDetailfor taxes associated with fulfillment, shipping, and handling.- See Also:
-
rdfShippingFulfillmentTypes
The list of shipping fulfillment types which are applicable for Retail Delivery Fees. By default, this includesFulfillmentType.SHIPandFulfillmentType.SAME_DAY_DELIVERY.
-
-
Constructor Details
-
DefaultDelegatingTaxService
public DefaultDelegatingTaxService(@NonNull @NonNull com.broadleafcommerce.tax.delegate.TaxDelegate<?, ?> taxDelegate, @Nullable List<TaxAddressSourceHandler> taxAddressSourceHandlers, @NonNull @NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
setAuthenticationUtils
@Autowired public void setAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils) -
setCustomerProvider
-
applyTaxes
public void applyTaxes(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, boolean estimate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:TaxServiceCalculates and applies taxes to a cart.- Specified by:
applyTaxesin interfaceTaxService- Parameters:
cart- The cart to apply taxes against.estimate- Hint indicating whether to try to provide only an estimate, possibly for better performancecontextInfo- (Optional) Additional sandbox, tenant, and application info
-
canCalculateTaxes
public boolean canCalculateTaxes(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:TaxServiceWhether the cart contains the information required to calculate taxes.- Specified by:
canCalculateTaxesin interfaceTaxService- Parameters:
cart- The cart to determine whether taxes can be calculated for.contextInfo- Additional sandbox and tenant info- Returns:
- Whether the cart contains the information required to calculate taxes.
-
fulfillmentGroupHasSufficientAddress
protected boolean fulfillmentGroupHasSufficientAddress(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fg, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenFulfillmentGrouphas sufficient address to calculate taxes.By default, for an address to be sufficient, it must have
TaxAddress.getCountry()andTaxAddress.getStateProvinceRegion()at the very least.For different address requirements, customization should be added here
- Parameters:
fg- theFulfillmentGroupto check the address forcart- theCartthat theFulfillmentGroupbelongs tocontextInfo- the contextInfo for this request- Returns:
- true if the given
FulfillmentGrouphas sufficient address to calculate taxes, otherwise false
-
executeTaxCalculation
protected com.broadleafcommerce.tax.domain.TaxCalculationResponse executeTaxCalculation(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getFulfillmentGroups
protected List<com.broadleafcommerce.cart.client.domain.FulfillmentGroup> getFulfillmentGroups(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) -
findTaxAddressSourceHandler
@Nullable protected TaxAddressSourceHandler findTaxAddressSourceHandler(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
createRequest
protected com.broadleafcommerce.tax.domain.TaxCalculationRequest createRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency, boolean estimate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
hasNoTaxItems
protected boolean hasNoTaxItems(com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determine if there are tax items on the given request.- Parameters:
request- TheTaxCalculationRequestto check.contextInfo- The context of this request.- Returns:
- TRUE if there are no
Tax Itemson the request. FALSE if there are any present.
-
includeFeesInTaxRequest
protected void includeFeesInTaxRequest(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles including extra and COD fees in aTaxCalculationRequest. By default, aTaxCalculationGroupis added for extra fees and another for COD fees.- Parameters:
request- theTaxCalculationRequestto add the fee items'TaxCalculationGrouptocart- theCartcontaining fee itemscontextInfo- Context information around sandbox and multitenant state- Since:
- Cart Operations 2.3.0, Release Train 2.3.0
- See Also:
-
includeExtraFeesInTaxRequest
protected void includeExtraFeesInTaxRequest(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles includingextra feesin aTaxCalculationRequest. By default, these fees are added to a separateTaxCalculationGroup.- Parameters:
request- theTaxCalculationRequestto add the fee items'TaxCalculationGrouptocart- theCartcontaining fee itemscontextInfo- Context information around sandbox and multitenant state- Since:
- Cart Operations 2.3.0, Release Train 2.3.0
-
includeExtraFeesInTaxRequest
protected void includeExtraFeesInTaxRequest(com.broadleafcommerce.tax.domain.TaxCalculationRequest request, com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.FulfillmentGroup group, Set<com.broadleafcommerce.tax.domain.TaxItem> items, TaxAddressSourceHandler handler, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles includingextra feesin aTaxCalculationRequest. By default, these fees are added to a separateTaxCalculationGroup.- Parameters:
request- theTaxCalculationRequestto add the fee items'TaxCalculationGrouptocart- theCartcontaining fee itemsgroup- TheFulfillmentGroupto use to tie the fees to for tax purposesitems- Thetax itemsfor the feeshandler- TheTaxAddressSourceHandlerthat provides the address to use for calculation fee taxes.contextInfo- Context information around sandbox and multitenant state- Since:
- Cart Operations 2.3.0, Release Train 2.3.0
-
getExtraFeeReferenceNumber
Calculating taxes usually requires an address to determine the jurisdiction. By default, the system will map the extra fee items to a fulfillment group and create a separate tax calculation group for the fees specifically. This method builds theTaxCalculationGroup.getFulfillmentGroupReferenceNumber()using the chose fulfillment group and a constant,FEE_REFERENCE_NUMBER.- Parameters:
referenceNumber- TheFulfillmentGroup.getReferenceNumber()for the group used as the point of reference for tax calculations for extra fees.- Returns:
- The value to use for the extra fees' tax calculation group's
TaxCalculationGroup.getFulfillmentGroupReferenceNumber(). - Since:
- Cart Operation 2.3.0, Release Train 2.3.0
-
includeCODFeesInTaxRequest
protected void includeCODFeesInTaxRequest(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Handles includingCollect/Credit on Delivery feesin aTaxCalculationRequest. By default, these fees are added to a separateTaxCalculationGroup.- Parameters:
request- theTaxCalculationRequestto add the fee items'TaxCalculationGrouptocart- theCartcontaining fee itemscontextInfo- Context information around sandbox and multitenant state- Since:
- Cart Operations 2.3.0, Release Train 2.3.0
-
setAllTaxToZero
protected void setAllTaxToZero(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) -
buildTaxItemForFeeItem
protected com.broadleafcommerce.tax.domain.TaxItem buildTaxItemForFeeItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Builds aTaxItembased on the givenfee item.- Parameters:
cartItem- the fee item- Returns:
- the
TaxItembuilt from the given fee item
-
getFulfillmentGroupForCOD
protected Optional<com.broadleafcommerce.cart.client.domain.FulfillmentGroup> getFulfillmentGroupForCOD(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets theFulfillmentGroupthat has CollectOnDelivery selected from the givenCart.- Parameters:
cart- the cart that may contain a fulfillment group that has COD selected- Returns:
- an optional of COD fulfillment group
- See Also:
-
FulfillmentGroup.COD_STATUS_ATTR
-
mapFulfillmentGroupsToExtraFees
protected <T extends com.broadleafcommerce.tax.domain.TaxItem> Map<com.broadleafcommerce.cart.client.domain.FulfillmentGroup,Set<T>> mapFulfillmentGroupsToExtraFees(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Set<T> taxItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines theFulfillmentGroupto use for extra fee tax calculations. By default, this picks the first fulfillment group and maps all fee tax items to it.- Parameters:
cart- The cart being taxed.- Returns:
- A mapping of the fulfillment group to use for determining taxes for extra fees to the tee tax item.
- See Also:
-
DefaultCartItemTypes.EXTRA_FEE
-
isCODSelected
protected boolean isCODSelected(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) -
shouldConsiderRDFFee
protected boolean shouldConsiderRDFFee(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxResponseGroup taxResponseGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) Hook point to enable/disable building Retail Delivery Fee from theTaxResponseGroup. -
findTaxAddressSourceHandlerForCODFeeTaxCalculation
protected Optional<TaxAddressSourceHandler> findTaxAddressSourceHandlerForCODFeeTaxCalculation(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theTaxAddressSourceHandlerfor tax calculation for Collect on Delivery fees.By default, it delegates to
findTaxAddressSourceHandler(Cart, FulfillmentGroup, ContextInfo).- Parameters:
cart- theCartcontaining fee itemsfulfillmentGroup- theFulfillmentGroupthat has COD selectedcontextInfo- context information surrounding multitenant state- Returns:
- an optional of
TaxAddressSourceHandlerfor tax calculation for COD fees - Since:
- Cart Operations 2.3.0, Release Train 2.3.0
- See Also:
-
FulfillmentGroup.COD_STATUS_ATTRDefaultCartItemTypes.COD_FEE
-
findTaxAddressSourceHandlerForExtraFeeTaxCalculation
protected Optional<TaxAddressSourceHandler> findTaxAddressSourceHandlerForExtraFeeTaxCalculation(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds theTaxAddressSourceHandlerfor tax calculation for extra fees.By default, it delegates to
findTaxAddressSourceHandler(Cart, FulfillmentGroup, ContextInfo).- Parameters:
cart- theCartcontaining fee itemsfulfillmentGroup- theFulfillmentGroupto associate the fee with for taxing purposes.contextInfo- context information surrounding multitenant state- Returns:
- an optional of
TaxAddressSourceHandlerfor tax calculation for fees - Since:
- Cart Operations 2.3.0, Release Train 2.3.0
- See Also:
-
DefaultCartItemTypes.EXTRA_FEE
-
buildTaxItemsForLineItems
protected List<com.broadleafcommerce.tax.domain.TaxItem> buildTaxItemsForLineItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getCartItemMap
-
getCartItemMap
-
buildTaxItemForLineItem
protected com.broadleafcommerce.tax.domain.TaxItem buildTaxItemForLineItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, @Nullable com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
isItemIncludesTaxes
protected boolean isItemIncludesTaxes(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, @Nullable com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) In some situations, especially in European countries, for example, merchants are required to display all prices including tax. This is especially common with VAT. So, in some situations the price of a Product or Variant will include Value Added Taxes. Some providers (e.g. Avalara) will attempt to back-calculate the taxes from the price of the item if we indicate that tax is included in the price. While the customer does not need to pay additional taxes, this allows us to calculate taxes owed for this item, which we can store on the tax details for informational purposes and remediation. NOTE: By default, this method returns false. Broadleaf Commerce does not currently provide a mechanism to determine if tax is included because catalogs, products, variants, and even pricing can be shared across applications and countries. Implementors may wish to override this method to return true under certain circumstances. For example, if the destination country is a European country (e.g. GB or FR) and/or the currency is a European currency, then you may wish to return true. TheContextInfo(i.e. the tenant or application) may also inform this decision.- Parameters:
fulfillmentGroup-fulfillmentItem-cartItem-contextInfo-- Returns:
-
getTaxItemIdForLineItem
protected String getTaxItemIdForLineItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem) -
getProductDescription
protected String getProductDescription(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Retrieves the description of the product represented by theCartItem.- Parameters:
cartItem- theCartItem- Returns:
- The description of the product that was added to the cart.
-
shouldCalculateItemTaxes
protected boolean shouldCalculateItemTaxes(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
shouldTaxFulfillment
protected boolean shouldTaxFulfillment(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull javax.money.CurrencyUnit currencyUnit, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
isGroupFulfillmentTaxable
protected boolean isGroupFulfillmentTaxable(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fg) -
getTaxableItemFulfillmentTotal
protected javax.money.MonetaryAmount getTaxableItemFulfillmentTotal(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fg, javax.money.CurrencyUnit currency) -
setCustomerAndAccountPropertiesOnRequest
protected void setCustomerAndAccountPropertiesOnRequest(com.broadleafcommerce.tax.domain.TaxCalculationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
determineTaxExemptionCode
@Deprecated @Nullable protected String determineTaxExemptionCode(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated. -
applyTaxResponses
protected void applyTaxResponses(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.FulfillmentGroup> fulfillmentGroups, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
applyFulfillmentTaxDetails
protected javax.money.MonetaryAmount applyFulfillmentTaxDetails(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, com.broadleafcommerce.tax.domain.TaxResponseGroup taxResponseGroup, javax.money.MonetaryAmount totalGroupTax, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
persistTaxResponseOnCart
protected void persistTaxResponseOnCart(@NotNull @NotNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NotNull @NotNull com.broadleafcommerce.cart.client.domain.Cart cart) -
debugLogTrimmedTaxResponse
protected void debugLogTrimmedTaxResponse(@NotNull @NotNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response) -
applyCODTaxResponse
protected javax.money.MonetaryAmount applyCODTaxResponse(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies theTaxCalculationResponsefor COD fees.- Parameters:
response- theTaxCalculationResponsethat contains tax response for COD feescart- theCartthat contains COD fee itemsexpectedCurrency- the expected currencycontextInfo- Context information around sandbox and multitenant state- Returns:
- the total COD fees tax
-
applyFeeTaxResponse
protected javax.money.MonetaryAmount applyFeeTaxResponse(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse response, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency, @NonNull @NonNull String referenceNumber, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies theTaxCalculationResponsefor fees.- Parameters:
response- theTaxCalculationResponsethat contains tax response for COD feescart- theCartthat contains fee itemsexpectedCurrency- the expected currencyreferenceNumber- Reference number to use to resolve the tax response for the fee. Could beCOD_REFERENCE_NUMBERfor COD Fees orFEE_REFERENCE_NUMBERfor Extra Fees.contextInfo- Context information around sandbox and multitenant state- Returns:
- the total fees tax
- Since:
- Cart Operations 2.3.0, Release Train 2.3.0
-
applyRDFTaxResponse
protected javax.money.MonetaryAmount applyRDFTaxResponse(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxResponseGroup taxResponseGroup, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Applies theTaxCalculationResponsefor RDF fees.- Parameters:
taxResponseGroup- theTaxResponseGroupthat contains tax response for RDF feescart- theCartthat contains RDF fee itemsexpectedCurrency- the expected currencycontextInfo- Context information around sandbox and multitenant state- Returns:
- the total RDF fees tax
-
buildTaxItemsForFulfillment
@Deprecated protected List<com.broadleafcommerce.tax.domain.TaxItem> buildTaxItemsForFulfillment(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) Deprecated. -
buildTaxItemsForFulfillment
protected List<com.broadleafcommerce.tax.domain.TaxItem> buildTaxItemsForFulfillment(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getTaxItemIdForFulfillment
protected String getTaxItemIdForFulfillment(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) Extension point to modify theTaxItem.getItemId()for fulfillment tax items. For someTaxProviders, there may be a affix likeFR(for freight) to add to theFulfillmentGroup.getReferenceNumber().- Parameters:
fulfillmentGroup- Fulfillment group from which to derive an id- Returns:
TaxItem.getItemId()for fulfillment tax items
-
calculateIncludedTaxes
protected void calculateIncludedTaxes(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull javax.money.CurrencyUnit expectedCurrency, @NonNull @NonNull com.broadleafcommerce.tax.domain.TaxCalculationResponse taxResponse) In some situations, taxes are included in the price of the item. This is most common with VAT, especially in European countries. This method determines whichTaxInfoshad taxes included prior to calling the TaxProvider. Then we set tax included properties onCartPricing. This determines how much of the total tax amount is included in the subtotal vs how much has to be added to the subtotal. Note that it's common to confuse VAT with "included taxes" because VAT is usually included. However, these are separate properties or indicators, and VAT properties are for informational and remediation purposes, whiletaxIncludedis for calculation purposes as well as informational and remediation purposes.- Parameters:
cart- Cart to be taxedexpectedCurrency- The currency to usetaxResponse- TheTaxResponseresponse containing calculated taxes.
-
addFulfillmentItemTaxDetails
protected void addFulfillmentItemTaxDetails(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxInfo taxInfo, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This takes the total from theFulfillmentGroup.getFulfillmentTaxableAmount(). That should have generated aTaxInfo. We createFulfillmentItemTaxDetailsfor each item, distributing the fulfillment tax across all items, prorated based on merchandise value of each item, with the remainder arbitrarily going to the last item. The assumption is thatTaxInfo.getTaxCalculated()is exactly equal to the sum of allTaxDetail.getTaxCalculated(). This also assumes thatTaxInfo.getTaxableAmount()is exactly equal to the sum of allTaxDetail.getTaxableAmount(). By default, no rounding is performed in this method.- Parameters:
taxInfo-fulfillmentGroup-contextInfo-
-
addFulfillmentItemTaxDetails
protected void addFulfillmentItemTaxDetails(@NonNull @NonNull com.broadleafcommerce.tax.domain.TaxInfo taxInfo, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentItem fulfillmentItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) AddFulfillmentItemTaxDetailsto the fulfillment item.- Parameters:
taxInfo- The tax infofulfillmentItem- The fulfillment itemcontextInfo- the contextInfo for this request
-
buildTaxCalculationGroup
protected <T extends com.broadleafcommerce.tax.domain.TaxItem> com.broadleafcommerce.tax.domain.TaxCalculationGroup buildTaxCalculationGroup(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull TaxAddressSourceHandler handler, @NonNull @NonNull Collection<T> taxItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aTaxCalculationGroup, which is used to calculate taxes for a group of items being shipped to or fulfilled at a particular Address.- Parameters:
cart-fulfillmentGroup-handler-taxItems-contextInfo-- Returns:
-
determinePreferredProviderId
@Nullable protected String determinePreferredProviderId(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, boolean estimate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) This method returns the "preferred"Tax Provider ID, which is determined byTaxProvider.getProviderId(). By default, this will be null. This provides a hook point to allow someone to specify the Tax Provider that should be prioritized for use. For example, you may wish to returnSimpleTaxProvider.SIMPLE_TAX_PROVIDER_IDfor estimates. In this case you could override this method to do so if theestimateargument is true, and return null otherwise. To be clear, this does not guarantee that theTaxProviderspecified will be used; only that it will be prioritized for use. If there is no TaxProvider registered with that ID, then it will be ignored. Or, if the TaxProvider exists with that ID, but it cannot handle the request, then it will be ignored.- Parameters:
cart-estimate-contextInfo-- Returns:
-
determineCartId
protected String determineCartId(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) We require theCart.getId(), in most cases. However, if, for some reason, there is no cart ID available in the cart, then we provide a UUID. The cart ID is generally used to tie requests together in someTax Provider systems. By default, this uses theCart.getId(). However, it generates aUUIDif no cart ID is available at the time this component is invoked.- Parameters:
cart-contextInfo-- Returns:
-
getRDFShippingFulfillmentTypes
-
getTaxAddressSourceHandlers
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getTaxDelegate
protected com.broadleafcommerce.tax.delegate.TaxDelegate<?,?> getTaxDelegate() -
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils() -
getCustomerProvider
-
getDelegatingTaxServiceProperties
-
setDelegatingTaxServiceProperties
@Autowired public void setDelegatingTaxServiceProperties(DelegatingTaxServiceProperties delegatingTaxServiceProperties) -
getMapper
protected com.fasterxml.jackson.databind.ObjectMapper getMapper() -
setMapper
@Autowired public void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
-