Class DefaultTaxRequestService
java.lang.Object
com.broadleafcommerce.orderoperation.service.messaging.tax.DefaultTaxRequestService
- All Implemented Interfaces:
TaxRequestService
Service class to create tax requests to be sent to the
TaxDelegate-
Field Summary
Fields inherited from interface com.broadleafcommerce.orderoperation.service.messaging.tax.TaxRequestService
TAX_ID_KEY, TAX_PROVIDER_ID_KEY -
Constructor Summary
ConstructorsConstructorDescriptionDefaultTaxRequestService(FromTaxAddressResolver fromTaxAddressResolver, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFulfillmentTaxItem(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, List<com.broadleafcommerce.tax.domain.TaxItem> taxItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.tax.domain.TaxItembuildFulfillmentTaxItem(String taxCode, String itemId, String description, javax.money.MonetaryAmount subtotal, String skuCode) protected com.broadleafcommerce.tax.domain.TaxItembuildTaxItemForAdjustment(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> fulfillmentItems) protected StringdetermineTaxProviderIdForCommit(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.order.client.domain.OrderFulfillment cancelledFulfillment, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> nonCancelledFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point to determine the tax provider ID.protected StringdetermineTaxProviderIdForCommit(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point to determine the tax provider ID.protected StringdetermineTaxProviderIdForCommit(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point to determine the tax provider ID.protected com.broadleafcommerce.order.client.domain.OrderFulfillmentfindFulfillmentForReturn(List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization) com.broadleafcommerce.tax.domain.AdjustTaxTransactionRequestgetAdjustTaxRequest(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.order.client.domain.OrderFulfillment cancelledFulfillment, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> nonCancelledFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an adjusted transaction based on the supplied order and fulfillmentscom.broadleafcommerce.tax.domain.CommitTaxRequestgetCommitTaxRequest(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create a commit tax request for used when committing taxes.protected StringgetCustomer(com.broadleafcommerce.order.client.domain.Order order) protected com.broadleafcommerce.tax.domain.TaxAddressgetFromAddress(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected FromTaxAddressResolvergetOrderFulfillmentItemMap(List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments) getOrderItemMap(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment) protected com.broadleafcommerce.tax.domain.TaxCalculationGroupgetReturnTaxCalculationGroup(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) com.broadleafcommerce.tax.domain.ReverseTaxTransactionRequestgetReverseTransactionRequest(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create a reverse tax transaction request.protected List<com.broadleafcommerce.tax.domain.TaxCalculationGroup>getTaxGroupsForCommit(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.tax.domain.TaxItemgetTaxItemFromFulfillmentOption(com.broadleafcommerce.order.common.domain.FulfillmentOption fulfillmentOption, javax.money.MonetaryAmount amount) protected com.broadleafcommerce.tax.domain.TaxItemgetTaxItemFromPricedFulfillmentOption(com.broadleafcommerce.order.common.domain.PricedFulfillmentOption pricedFulfillmentOption, javax.money.MonetaryAmount amount) protected List<com.broadleafcommerce.tax.domain.TaxItem>getTaxItemsForAdjustment(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> nonCancelledFulfillments, com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.tax.domain.TaxItem>getTaxItemsForCommit(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.tax.domain.TaxItem>getTaxItemsForReturn(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, Map<String, com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> orderItemMap) Builds the tax items based onReturnConfirmationrecords that are currently in aReturnConfirmationStatus.PENDINGstate.protected com.broadleafcommerce.tax.domain.TaxAddressgetToAddress(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.common.extension.TypeFactorycom.broadleafcommerce.tax.domain.VoidTransactionRequestgetVoidTransaction(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create a void transaction request.
-
Constructor Details
-
DefaultTaxRequestService
public DefaultTaxRequestService(@Nullable FromTaxAddressResolver fromTaxAddressResolver, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
getCommitTaxRequest
public com.broadleafcommerce.tax.domain.CommitTaxRequest getCommitTaxRequest(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:TaxRequestServiceCreate a commit tax request for used when committing taxes.- Specified by:
getCommitTaxRequestin interfaceTaxRequestService- Parameters:
order- The submitted orderorderFulfillments- The order fulfillmentscontextInfo- The context- Returns:
- A commit tax request
-
getAdjustTaxRequest
public com.broadleafcommerce.tax.domain.AdjustTaxTransactionRequest getAdjustTaxRequest(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.order.client.domain.OrderFulfillment cancelledFulfillment, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> nonCancelledFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create an adjusted transaction based on the supplied order and fulfillments- Specified by:
getAdjustTaxRequestin interfaceTaxRequestService- Parameters:
order- The original ordercancelledFulfillment- The cancelled fulfillmentnonCancelledFulfillments- The non-cancelled fulfillmentscontextInfo- The context- Returns:
- A populated adjust transaction request
-
getReverseTransactionRequest
public com.broadleafcommerce.tax.domain.ReverseTaxTransactionRequest getReverseTransactionRequest(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:TaxRequestServiceCreate a reverse tax transaction request. Used to submit reverse transactions to the tax provider.- Specified by:
getReverseTransactionRequestin interfaceTaxRequestService- Parameters:
order- The original orderfulfillments- The order's fulfillmentsreturnAuthorization- The return authorization. If null, it's assumed this is an order that has been cancelled without ever fulfillingcontextInfo- The current context- Returns:
- A reverse tax transaction request
-
getVoidTransaction
public com.broadleafcommerce.tax.domain.VoidTransactionRequest getVoidTransaction(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:TaxRequestServiceCreate a void transaction request.- Specified by:
getVoidTransactionin interfaceTaxRequestService- Parameters:
order- The original orderfulfillments- The fulfillmentscontextInfo- The current context- Returns:
- A void transaction request
-
getTaxGroupsForCommit
protected List<com.broadleafcommerce.tax.domain.TaxCalculationGroup> getTaxGroupsForCommit(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getTaxItemsForCommit
protected List<com.broadleafcommerce.tax.domain.TaxItem> getTaxItemsForCommit(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
addFulfillmentTaxItem
protected void addFulfillmentTaxItem(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, List<com.broadleafcommerce.tax.domain.TaxItem> taxItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getTaxItemFromPricedFulfillmentOption
protected com.broadleafcommerce.tax.domain.TaxItem getTaxItemFromPricedFulfillmentOption(com.broadleafcommerce.order.common.domain.PricedFulfillmentOption pricedFulfillmentOption, javax.money.MonetaryAmount amount) -
getTaxItemFromFulfillmentOption
protected com.broadleafcommerce.tax.domain.TaxItem getTaxItemFromFulfillmentOption(com.broadleafcommerce.order.common.domain.FulfillmentOption fulfillmentOption, javax.money.MonetaryAmount amount) -
buildFulfillmentTaxItem
-
getCustomer
-
getTaxItemsForAdjustment
protected List<com.broadleafcommerce.tax.domain.TaxItem> getTaxItemsForAdjustment(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> nonCancelledFulfillments, com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
buildTaxItemForAdjustment
protected com.broadleafcommerce.tax.domain.TaxItem buildTaxItemForAdjustment(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> fulfillmentItems) -
getOrderFulfillmentItemMap
-
getToAddress
protected com.broadleafcommerce.tax.domain.TaxAddress getToAddress(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getFromAddress
protected com.broadleafcommerce.tax.domain.TaxAddress getFromAddress(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getReturnTaxCalculationGroup
protected com.broadleafcommerce.tax.domain.TaxCalculationGroup getReturnTaxCalculationGroup(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getOrderItemMap
-
getTaxItemsForReturn
protected List<com.broadleafcommerce.tax.domain.TaxItem> getTaxItemsForReturn(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, Map<String, com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> orderItemMap) Builds the tax items based onReturnConfirmationrecords that are currently in aReturnConfirmationStatus.PENDINGstate.This approach is preferred over recalculating proration from the raw request for several reasons:
- Mathematical Alignment: It uses
ReturnConfirmation.getMerchandiseTotalToRefund(), which has already been penny-rounded and prorated by theDefaultReturnConfirmationGenerationService. This ensures the tax engine receives the exact same merchandise value that the payment engine uses for the refund payout. - Partial Confirmation Support: By only processing
PENDINGconfirmations, this naturally supports partial returns. Any confirmations from previous return events will already be in aCOMPLETEDorREFUND_FAILEDstate and will be correctly ignored. - Override Safety: It inherently ignores financial overrides (e.g., restocking fees or concessions) which only impact the grand total payout, ensuring the tax engine always receives the true underlying taxable merchandise value.
It is safe to rely on the
PENDINGstatus because theReturnConfirmationis synchronously generated and persisted to theReturnAuthorizationwith aPENDINGstate immediately before the asyncReturnConfirmedEventis published. Since the tax handler operates on the event payload (which reflects the state at the time of emission), it is guaranteed to see the new confirmation in itsPENDINGstate. - Mathematical Alignment: It uses
-
findFulfillmentForReturn
protected com.broadleafcommerce.order.client.domain.OrderFulfillment findFulfillmentForReturn(List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization) -
determineTaxProviderIdForCommit
protected String determineTaxProviderIdForCommit(com.broadleafcommerce.order.client.domain.Order order, @Nullable List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments, @Nullable com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point to determine the tax provider ID. Defaults to return the same tax provider ID that was used for commit.- Parameters:
order- The orderfulfillments- The order's fulfillmentreturnAuthorization- The return authorizationcontextInfo- The current context- Returns:
- The ID of the tax provider to use.
-
determineTaxProviderIdForCommit
protected String determineTaxProviderIdForCommit(com.broadleafcommerce.order.client.domain.Order order, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point to determine the tax provider ID. Defaults to return null.- Parameters:
order- The orderorderFulfillments- The order's fulfillmentscontextInfo- The current context- Returns:
- The ID of the tax provider to use.
-
determineTaxProviderIdForCommit
protected String determineTaxProviderIdForCommit(com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.order.client.domain.OrderFulfillment cancelledFulfillment, @Nullable List<com.broadleafcommerce.order.client.domain.OrderFulfillment> nonCancelledFulfillments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Extension point to determine the tax provider ID. Defaults to return the same tax provider ID used during commit- Parameters:
order- The ordercancelledFulfillment- The cancelled fulfillmentnonCancelledFulfillments- The still active fulfillmentscontextInfo- The current context- Returns:
- The ID of the tax provider to use.
-
getFromTaxAddressResolver
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-