Class DefaultTaxDelegate<T1 extends TaxRequest,​T2 extends TaxResponse>

  • 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 Detail

      • 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 Detail

      • 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:
      • 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 TaxCalculationRequestTaxProvider<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 TaxCalculationRequestTaxProvider<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()
      • getTypeFactory

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