Class DefaultTaxDelegate<T1 extends TaxRequest,T2 extends TaxResponse>

java.lang.Object
com.broadleafcommerce.tax.delegate.DefaultTaxDelegate<T1,T2>
Type Parameters:
T1 -
T2 -
All Implemented Interfaces:
TaxDelegate<T1,T2>, TaxAccessor<T1,T2>

public class DefaultTaxDelegate<T1 extends TaxRequest,T2 extends TaxResponse> extends Object implements TaxDelegate<T1,T2>
This component resolves a TaxProvider based on the provided ContextInfo and delegates appropriate tax calls to that provider. This component also uses a CircuitBreaker for resiliance and falls back to a SimpleTaxProvider in cases of errors.
Author:
Kelly Tisdell (ktisdell)
  • Constructor Details

    • DefaultTaxDelegate

      public DefaultTaxDelegate(@NonNull List<TaxProvider<T1,T2>> taxProviders, @NonNull TaxDelegateProperties properties, @NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • DefaultTaxDelegate

      public DefaultTaxDelegate(@NonNull List<TaxProvider<T1,T2>> taxProviders, @NonNull TaxDelegateProperties properties, @NonNull com.broadleafcommerce.common.extension.TypeFactory typeFactory, @Nullable io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker)
  • Method Details

    • determineSimpleTaxProvider

      @Nullable protected TaxProvider<T1,T2> determineSimpleTaxProvider(List<TaxProvider<T1,T2>> taxProviders)
      This must return a TaxProvider instance whose TaxProvider.getProviderId() returns SimpleTaxProvider.SIMPLE_TAX_PROVIDER_ID or it must return null if no SimpleTaxProvider is configured. Exactly zero or one TaxProviders can be configured with this providerId.
      Parameters:
      taxProviders -
      Returns:
    • determineNonSimpleTaxProviders

      @NonNull protected Map<String,TaxProvider<T1,T2>> determineNonSimpleTaxProviders(List<TaxProvider<T1,T2>> taxProviders)
      Returns a Map of TaxProviders whose key is TaxProvider.getProviderId() and whose value is the TaxProvider instance. This map must not include a SimpleTaxProvider or a TaxProvider whose TaxProvider.getProviderId() method returns SimpleTaxProvider.SIMPLE_TAX_PROVIDER_ID.
      Parameters:
      taxProviders -
      Returns:
    • calculateTaxes

      public TaxCalculationResponse calculateTaxes(TaxCalculationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: TaxAccessor
      Takes the TaxCalculationRequest and computes sales tax. The details of the tax determination are returned via the TaxCalculationResponse.
      Specified by:
      calculateTaxes in interface TaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
      Parameters:
      request - TaxCalculationRequest, or details about what needs to be taxes
      contextInfo - The ContextInfo that determines which tenant and application are making the request
      Returns:
    • adjustTaxes

      public TaxCalculationResponse adjustTaxes(AdjustTaxTransactionRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: TaxAccessor
      For Tax Accessors that support "commitTaxes", this allows for adjustments after taxes have been committed.
      Specified by:
      adjustTaxes in interface TaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
      Returns:
    • commitTaxes

      public CommitTaxResponse commitTaxes(CommitTaxRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: TaxAccessor
      Some TaxAccessor instances allow clients to "commit" taxes, which essentially marks them as being collected and owed to a jurisdiction or tax authority. This is basically a way of saying, "We collected this much taxes for these products... and therefore we are saving these details for reporting and remittance."
      Specified by:
      commitTaxes in interface TaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
      Returns:
    • reverseTaxTransaction

      public ReverseTaxTransactionResponse reverseTaxTransaction(ReverseTaxTransactionRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: TaxAccessor
      For Tax Accessors that support "commitTaxes", this allows for reversal after taxes have been committed.
      Specified by:
      reverseTaxTransaction in interface TaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
      Returns:
    • voidTaxTransaction

      public void voidTaxTransaction(VoidTransactionRequest voidTransactionRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: TaxAccessor
      Typically used in the case of full order cancellations. Completely voids a committed tax transaction.
      Specified by:
      voidTaxTransaction in interface TaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
      Parameters:
      voidTransactionRequest - The void transaction request
      contextInfo - The ContextInfo that determines which tenant and application are making the request
    • resolvePreferredTaxProvider

      @NonNull protected <R extends TaxCalculationRequest> TaxProvider<T1,T2> resolvePreferredTaxProvider(@NonNull R request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Resolves the preferred TaxProvider to be used to execute a tax request. This first evaluates the request for the requested TaxProvider. Then it looks at configs for a "preferred" provider. Then it looks at all TaxProviders that are not the SimpleTaxProvider. Finally, it looks at the SimpleTaxProvider.
      Parameters:
      contextInfo - used to select the appropriate TaxProvider based on properties, credentials, etc.
      Returns:
      the most appropriate TaxProvider based on the supplied arguments
      Throws:
      IllegalStateException - if no provider could be determined for the supplied arguments
    • validateRequest

      protected void validateRequest(@Nullable TaxCalculationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateRequest

      protected void validateRequest(@Nullable CommitTaxRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateRequest

      protected void validateRequest(@Nullable ReverseTaxTransactionRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • resolveFallbackProvider

      @Nullable protected <R extends TaxCalculationRequest> TaxProvider<T1,T2> resolveFallbackProvider(R request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Attempts to resolve a fallback TaxProvider. This tax provider will be used in case of a failure with the preferred or if a CircuitBreaker is closed.

      If a fallback provider is found this method checks to see that the preferred provider can handle the request.

      This method may return null.

      Type Parameters:
      R -
      Parameters:
      request -
      contextInfo -
      Returns:
    • getCircuitBreaker

      protected io.github.resilience4j.circuitbreaker.CircuitBreaker getCircuitBreaker()
    • getSimpleTaxProvider

      protected TaxProvider<T1,T2> getSimpleTaxProvider()
    • getTaxProviderMap

      protected Map<String,TaxProvider<T1,T2>> getTaxProviderMap()
    • getProperties

      protected TaxDelegateProperties getProperties()
    • getTypeFactory

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