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 aTaxProvider
based on the providedContextInfo
and delegates appropriate tax calls to that provider. This component also uses aCircuitBreaker
for resiliance and falls back to aSimpleTaxProvider
in cases of errors.- Author:
- Kelly Tisdell (ktisdell)
-
-
Constructor Summary
Constructors Constructor Description DefaultTaxDelegate(List<TaxProvider<T1,T2>> taxProviders, TaxDelegateProperties properties, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
DefaultTaxDelegate(List<TaxProvider<T1,T2>> taxProviders, TaxDelegateProperties properties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TaxCalculationResponse
adjustTaxes(AdjustTaxTransactionRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
ForTax Accessors
that support "commitTaxes", this allows for adjustments after taxes have been committed.TaxCalculationResponse
calculateTaxes(TaxCalculationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Takes theTaxCalculationRequest
and computes sales tax.CommitTaxResponse
commitTaxes(CommitTaxRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
SomeTaxAccessor
instances allow clients to "commit" taxes, which essentially marks them as being collected and owed to a jurisdiction or tax authority.protected Map<String,TaxProvider<T1,T2>>
determineNonSimpleTaxProviders(List<TaxProvider<T1,T2>> taxProviders)
Returns aMap
ofTaxProviders
whose key isTaxProvider.getProviderId()
and whose value is theTaxProvider
instance.protected TaxProvider<T1,T2>
determineSimpleTaxProvider(List<TaxProvider<T1,T2>> taxProviders)
This must return aTaxProvider
instance whoseTaxProvider.getProviderId()
returnsSimpleTaxProvider.SIMPLE_TAX_PROVIDER_ID
or it must return null if noSimpleTaxProvider
is configured.protected io.github.resilience4j.circuitbreaker.CircuitBreaker
getCircuitBreaker()
protected TaxDelegateProperties
getProperties()
protected TaxProvider<T1,T2>
getSimpleTaxProvider()
protected Map<String,TaxProvider<T1,T2>>
getTaxProviderMap()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected <R extends TaxCalculationRequest>
TaxProvider<T1,T2>resolveFallbackProvider(R request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Attempts to resolve a fallbackTaxProvider
.protected <R extends TaxCalculationRequest>
TaxProvider<T1,T2>resolvePreferredTaxProvider(R request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Resolves the preferredTaxProvider
to be used to execute a tax request.ReverseTaxTransactionResponse
reverseTaxTransaction(ReverseTaxTransactionRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
ForTax Accessors
that support "commitTaxes", this allows for reversal after taxes have been committed.protected void
validateRequest(CommitTaxRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateRequest(ReverseTaxTransactionRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateRequest(TaxCalculationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
void
voidTaxTransaction(VoidTransactionRequest voidTransactionRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Typically used in the case of full order cancellations.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.tax.TaxAccessor
calculateTaxes, calculateTaxes, commitTaxes
-
-
-
-
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
-
determineSimpleTaxProvider
@Nullable protected TaxProvider<T1,T2> determineSimpleTaxProvider(List<TaxProvider<T1,T2>> taxProviders)
This must return aTaxProvider
instance whoseTaxProvider.getProviderId()
returnsSimpleTaxProvider.SIMPLE_TAX_PROVIDER_ID
or it must return null if noSimpleTaxProvider
is configured. Exactly zero or oneTaxProviders
can be configured with this providerId.- Parameters:
taxProviders
-- Returns:
-
determineNonSimpleTaxProviders
@NonNull protected Map<String,TaxProvider<T1,T2>> determineNonSimpleTaxProviders(List<TaxProvider<T1,T2>> taxProviders)
Returns aMap
ofTaxProviders
whose key isTaxProvider.getProviderId()
and whose value is theTaxProvider
instance. This map must not include aSimpleTaxProvider
or aTaxProvider
whoseTaxProvider.getProviderId()
method returnsSimpleTaxProvider.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 theTaxCalculationRequest
and computes sales tax. The details of the tax determination are returned via theTaxCalculationResponse
.- Specified by:
calculateTaxes
in interfaceTaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
- Parameters:
request
- TaxCalculationRequest, or details about what needs to be taxescontextInfo
- 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
ForTax Accessors
that support "commitTaxes", this allows for adjustments after taxes have been committed.- Specified by:
adjustTaxes
in interfaceTaxAccessor<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
SomeTaxAccessor
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 interfaceTaxAccessor<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
ForTax Accessors
that support "commitTaxes", this allows for reversal after taxes have been committed.- Specified by:
reverseTaxTransaction
in interfaceTaxAccessor<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 interfaceTaxAccessor<T1 extends TaxRequest,T2 extends TaxResponse>
- Parameters:
voidTransactionRequest
- The void transaction requestcontextInfo
- 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 preferredTaxProvider
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 fallbackTaxProvider
. This tax provider will be used in case of a failure with the preferred or if aCircuitBreaker
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()
-
-