Class DefaultTaxRequestService

java.lang.Object
com.broadleafcommerce.orderoperation.service.messaging.tax.DefaultTaxRequestService
All Implemented Interfaces:
TaxRequestService

public class DefaultTaxRequestService extends Object implements 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

    Constructors
    Constructor
    Description
    DefaultTaxRequestService(FromTaxAddressResolver fromTaxAddressResolver, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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)
     
    protected com.broadleafcommerce.tax.domain.TaxItem
    buildFulfillmentTaxItem(String taxCode, String itemId, String description, javax.money.MonetaryAmount subtotal, String skuCode)
     
    protected com.broadleafcommerce.tax.domain.TaxItem
    buildTaxItemForAdjustment(List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> fulfillmentItems)
     
    protected String
    determineTaxProviderIdForCommit(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 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.
    protected String
    determineTaxProviderIdForCommit(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.OrderFulfillment
    findFulfillmentForReturn(List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
     
    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
    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)
    Create a commit tax request for used when committing taxes.
    protected String
    getCustomer(com.broadleafcommerce.order.client.domain.Order order)
     
    protected com.broadleafcommerce.tax.domain.TaxAddress
    getFromAddress(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
     
    protected Map<String,List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>>
    getOrderFulfillmentItemMap(List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments)
     
    protected Map<String,com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>
    getOrderItemMap(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment)
     
    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)
     
    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)
    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.TaxItem
    getTaxItemFromFulfillmentOption(com.broadleafcommerce.order.common.domain.FulfillmentOption fulfillmentOption, javax.money.MonetaryAmount amount)
     
    protected com.broadleafcommerce.tax.domain.TaxItem
    getTaxItemFromPricedFulfillmentOption(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 on ReturnConfirmation records that are currently in a ReturnConfirmationStatus.PENDING state.
    protected com.broadleafcommerce.tax.domain.TaxAddress
    getToAddress(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    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)
    Create a void transaction request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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: TaxRequestService
      Create a commit tax request for used when committing taxes.
      Specified by:
      getCommitTaxRequest in interface TaxRequestService
      Parameters:
      order - The submitted order
      orderFulfillments - The order fulfillments
      contextInfo - 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:
      getAdjustTaxRequest in interface TaxRequestService
      Parameters:
      order - The original order
      cancelledFulfillment - The cancelled fulfillment
      nonCancelledFulfillments - The non-cancelled fulfillments
      contextInfo - 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: TaxRequestService
      Create a reverse tax transaction request. Used to submit reverse transactions to the tax provider.
      Specified by:
      getReverseTransactionRequest in interface TaxRequestService
      Parameters:
      order - The original order
      fulfillments - The order's fulfillments
      returnAuthorization - The return authorization. If null, it's assumed this is an order that has been cancelled without ever fulfilling
      contextInfo - 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: TaxRequestService
      Create a void transaction request.
      Specified by:
      getVoidTransaction in interface TaxRequestService
      Parameters:
      order - The original order
      fulfillments - The fulfillments
      contextInfo - 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

      protected com.broadleafcommerce.tax.domain.TaxItem buildFulfillmentTaxItem(String taxCode, String itemId, String description, javax.money.MonetaryAmount subtotal, String skuCode)
    • getCustomer

      protected String getCustomer(com.broadleafcommerce.order.client.domain.Order order)
    • 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

      protected Map<String,List<com.broadleafcommerce.order.client.domain.OrderFulfillmentItem>> getOrderFulfillmentItemMap(List<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillments)
    • 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

      protected Map<String,com.broadleafcommerce.order.client.domain.OrderFulfillmentItem> getOrderItemMap(com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment)
    • 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 on ReturnConfirmation records that are currently in a ReturnConfirmationStatus.PENDING state.

      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 the DefaultReturnConfirmationGenerationService. 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 PENDING confirmations, this naturally supports partial returns. Any confirmations from previous return events will already be in a COMPLETED or REFUND_FAILED state 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 PENDING status because the ReturnConfirmation is synchronously generated and persisted to the ReturnAuthorization with a PENDING state immediately before the async ReturnConfirmedEvent is 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 its PENDING state.

    • 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 order
      fulfillments - The order's fulfillment
      returnAuthorization - The return authorization
      contextInfo - 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 order
      orderFulfillments - The order's fulfillments
      contextInfo - 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 order
      cancelledFulfillment - The cancelled fulfillment
      nonCancelledFulfillments - The still active fulfillments
      contextInfo - The current context
      Returns:
      The ID of the tax provider to use.
    • getFromTaxAddressResolver

      @Nullable protected FromTaxAddressResolver getFromTaxAddressResolver()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()