Interface TaxService
- All Superinterfaces:
Service
public interface TaxService extends Service
TaxService is used to acquire a TaxProvider based on its fully qualified class name or alias.
The TaxProvider can then be used to make a request to the service it depends on for how much
tax should be collected.
A typical use case would look something like below:
TaxService taxService = Services.get(TaxService.class); TaxProvider provider = taxService.getProvider(providerAlias).orElseThrow( () -> new RuntimeException("Provider not found: " + providerAlias )); TaxResponse response = provider.makeRequest( EnhancedOrderTaxRequest.from(order) ); Optionalerror = response.getError(); if(!error.isPresent()) { double taxDue = response.getTotalTax(); ... } else { order.setError(error.get()); }
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
AVATAX
Constant String alias used to register the Avatax TaxProvider. -
Method Summary
Modifier and Type Method Description java.util.Optional<TaxProvider>
getProvider(java.lang.String name)
Returns the provider with the given name if it is registered.java.util.Optional<java.lang.String>
getTaxCode(java.lang.String provider, long owningEntId, long itemId, PlatformUserContext context)
Looks up the TaxCode associated with the given provider and item owned by the given enterprise.java.util.Set<TaxProvider>
listProviders()
Returns all providers registered in the service.void
registerProvider(TaxProvider provider)
Registers a provider in the service based on its fully qualified class name.void
registerProvider(TaxProvider provider, java.lang.String alias)
Registers a provider in the service based on the provided alias.
-
Field Details
-
AVATAX
static final java.lang.String AVATAXConstant String alias used to register the Avatax TaxProvider. Any ItemTaxCode entries for Avatax should be registered with this value. Can be used as: TaxService.getProvider(TaxService.AVATAX);- See Also:
- Constant Field Values
-
-
Method Details
-
getProvider
Returns the provider with the given name if it is registered. Name can be either the fully qualified class name of the provider or the alias used to register it. If no such provider is registered then Optional.empty() will be returned. -
listProviders
java.util.Set<TaxProvider> listProviders()Returns all providers registered in the service. The set is not guaranteed to be sorted in any way. -
registerProvider
Registers a provider in the service based on its fully qualified class name. -
registerProvider
Registers a provider in the service based on the provided alias. It also registers a provider in the service based on its fully qualified class name. -
getTaxCode
java.util.Optional<java.lang.String> getTaxCode(java.lang.String provider, long owningEntId, long itemId, PlatformUserContext context)Looks up the TaxCode associated with the given provider and item owned by the given enterprise. Note that owningEntId is the owner of the ItemTaxCode and need not be the same enterprise that owns the item.
-