Skip to main content
Skip to main content

TaxProviderService

Finds tax providers and assists in tax related operations.

Constructors

constructor

**new TaxProviderService**(container)

Parameters

containerAwilixContainer<any>Required

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
cacheService_ICacheServiceRequired
container_AwilixContainer<any>Required
eventBus_IEventBusServiceRequired
manager_EntityManagerRequired
smTaxLineRepo_Repository<ShippingMethodTaxLine> & &#123; deleteForCart: Method deleteForCart ; upsertLines: Method upsertLines &#125;Required
taxLineRepo_Repository<LineItemTaxLine> & &#123; deleteForCart: Method deleteForCart ; upsertLines: Method upsertLines &#125;Required
taxProviderRepo_Repository<TaxProvider>Required
taxRateService_TaxRateServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

clearLineItemsTaxLines

**clearLineItemsTaxLines**(itemIds): Promise&#60;void&#62;

Parameters

itemIdsstring[]Required

Returns

Promise<void>

PromisePromise<void>Required

clearTaxLines

**clearTaxLines**(cartId): Promise&#60;void&#62;

Parameters

cartIdstringRequired

Returns

Promise<void>

PromisePromise<void>Required

createShippingTaxLines

**createShippingTaxLines**(shippingMethod, calculationContext): Promise&#60;([LineItemTaxLine](/references/services/classes/LineItemTaxLine) \| [ShippingMethodTaxLine](/references/services/classes/ShippingMethodTaxLine))[]&#62;

Persists the tax lines relevant for a shipping method to the database. Used for return shipping methods.

Parameters

shippingMethodShippingMethodRequired
the shipping method to create tax lines for
calculationContextTaxCalculationContextRequired
the calculation context to get tax lines by

Returns

Promise<(LineItemTaxLine | ShippingMethodTaxLine)[]>

PromisePromise<(LineItemTaxLine | ShippingMethodTaxLine)[]>Required
the newly created tax lines

createTaxLines

**createTaxLines**(cartOrLineItems, calculationContext): Promise&#60;([LineItemTaxLine](/references/services/classes/LineItemTaxLine) \| [ShippingMethodTaxLine](/references/services/classes/ShippingMethodTaxLine))[]&#62;

Persists the tax lines relevant for an order to the database.

Parameters

cartOrLineItemsLineItem[] | CartRequired
the cart or line items to create tax lines for
calculationContextTaxCalculationContextRequired
the calculation context to get tax lines by

Returns

Promise<(LineItemTaxLine | ShippingMethodTaxLine)[]>

PromisePromise<(LineItemTaxLine | ShippingMethodTaxLine)[]>Required
the newly created tax lines

getCacheKey

Private **getCacheKey**(id, regionId): string

The cache key to get cache hits by.

Parameters

idstringRequired
the entity id to cache
regionIdstringRequired
the region id to cache

Returns

string

stringstring
the cache key to use for the id set

getRegionRatesForProduct

**getRegionRatesForProduct**(productIds, region): Promise&#60;Map&#60;string, [TaxServiceRate](/references/services/types/TaxServiceRate)[]&#62;&#62;

Gets the tax rates configured for a product. The rates are cached between calls.

Parameters

productIdsstring | string[]Required
regionRegionDetailsRequired
the region to get configured rates for.

Returns

Promise<Map<string, TaxServiceRate[]>>

PromisePromise<Map<string, TaxServiceRate[]>>Required
the tax rates configured for the shipping option. A map by product id

getRegionRatesForShipping

**getRegionRatesForShipping**(optionId, regionDetails): Promise&#60;[TaxServiceRate](/references/services/types/TaxServiceRate)[]&#62;

Gets the tax rates configured for a shipping option. The rates are cached between calls.

Parameters

optionIdstringRequired
the option id of the shipping method.
regionDetailsRegionDetailsRequired
the region to get configured rates for.

Returns

Promise<TaxServiceRate[]>

PromisePromise<TaxServiceRate[]>Required
the tax rates configured for the shipping option.

getShippingTaxLines

**getShippingTaxLines**(shippingMethod, calculationContext): Promise&#60;[ShippingMethodTaxLine](/references/services/classes/ShippingMethodTaxLine)[]&#62;

Gets the relevant tax lines for a shipping method. Note: this method doesn't persist the tax lines. Use createShippingTaxLines if you wish to persist the tax lines to the DB layer.

Parameters

shippingMethodShippingMethodRequired
the shipping method to get tax lines for
calculationContextTaxCalculationContextRequired
the calculation context to get tax lines by

Returns

Promise<ShippingMethodTaxLine[]>

PromisePromise<ShippingMethodTaxLine[]>Required
the computed tax lines

getTaxLines

**getTaxLines**(lineItems, calculationContext): Promise&#60;([LineItemTaxLine](/references/services/classes/LineItemTaxLine) \| [ShippingMethodTaxLine](/references/services/classes/ShippingMethodTaxLine))[]&#62;

Gets the relevant tax lines for an order or cart. If an order is provided the order's tax lines will be returned. If a cart is provided the tax lines will be computed from the tax rules and potentially a 3rd party tax plugin. Note: this method doesn't persist the tax lines. Use createTaxLines if you wish to persist the tax lines to the DB layer.

Parameters

lineItemsLineItem[]Required
the cart or order to get tax lines for
calculationContextTaxCalculationContextRequired
the calculation context to get tax lines by

Returns

Promise<(LineItemTaxLine | ShippingMethodTaxLine)[]>

PromisePromise<(LineItemTaxLine | ShippingMethodTaxLine)[]>Required
the computed tax lines

getTaxLinesMap

Protected **getTaxLinesMap**(items, calculationContext): Promise&#60;[TaxLinesMaps](/references/services/types/TaxLinesMaps)&#62;

Return a map of tax lines for line items and shipping methods

Parameters

itemsLineItem[]Required
calculationContextTaxCalculationContextRequired

Returns

Promise<TaxLinesMaps>

PromisePromise<TaxLinesMaps>Required

list

**list**(): Promise&#60;[TaxProvider](/references/services/classes/TaxProvider)[]&#62;

Returns

Promise<TaxProvider[]>

PromisePromise<TaxProvider[]>Required

registerInstalledProviders

**registerInstalledProviders**(providers): Promise&#60;void&#62;

Parameters

providersstring[]Required

Returns

Promise<void>

PromisePromise<void>Required

retrieveProvider

**retrieveProvider**(region): [ITaxService](/references/services/interfaces/ITaxService)

Retrieves the relevant tax provider for the given region.

Parameters

regionRegionRequired
the region to get tax provider for.

Returns

ITaxService

getTaxLines(itemLines: ItemTaxCalculationLine[], shippingLines: ShippingTaxCalculationLine[], context: TaxCalculationContext) => Promise<ProviderTaxLine[]>Required

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

withTransaction

**withTransaction**(transactionManager?): [TaxProviderService](/references/services/classes/TaxProviderService)

Parameters

transactionManagerEntityManager

Returns

TaxProviderService

TaxProviderServiceTaxProviderServiceRequired
Was this section helpful?