Files
medusa-store/www/apps/docs/content/references/services/classes/TaxProviderService.mdx
github-actions[bot] 39649b3552 chore(docs): Generated References (#5602)
Generated the following references:
- `pricing`
- `product`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-11-10 17:31:02 +00:00

869 lines
19 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# TaxProviderService
Finds tax providers and assists in tax related operations.
## Constructors
### constructor
**new TaxProviderService**(`container`)
#### Parameters
<ParameterTypes parameters={[
{
"name": "container",
"type": "`AwilixContainer`<`any`\\>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Properties
<ParameterTypes parameters={[
{
"name": "__configModule__",
"type": "Record<`string`, `unknown`\\>",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__container__",
"type": "`any`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "__moduleDeclaration__",
"type": "Record<`string`, `unknown`\\>",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "cacheService_",
"type": "[`ICacheService`](../interfaces/ICacheService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "container_",
"type": "`AwilixContainer`<`any`\\>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "eventBus_",
"type": "[`IEventBusService`](../interfaces/IEventBusService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "manager_",
"type": "`EntityManager`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "smTaxLineRepo_",
"type": "`Repository`<[`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx)\\> & { `deleteForCart`: Method deleteForCart ; `upsertLines`: Method upsertLines }",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "taxLineRepo_",
"type": "`Repository`<[`LineItemTaxLine`](LineItemTaxLine.mdx)\\> & { `deleteForCart`: Method deleteForCart ; `upsertLines`: Method upsertLines }",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "taxProviderRepo_",
"type": "`Repository`<[`TaxProvider`](TaxProvider.mdx)\\>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "taxRateService_",
"type": "[`TaxRateService`](TaxRateService.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "transactionManager_",
"type": "`undefined` \\| `EntityManager`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Accessors
### activeManager\_
`Protected` `get` **activeManager_**(): `EntityManager`
#### Returns
`EntityManager`
<ParameterTypes parameters={[
{
"name": "EntityManager",
"type": "`EntityManager`",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
## Methods
### atomicPhase\_
`Protected` **atomicPhase_**<`TResult`, `TError`\>(`work`, `isolationOrErrorHandler?`, `maybeErrorHandlerOrDontFail?`): `Promise`<`TResult`\>
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.
<ParameterTypes parameters={[
{
"name": "TResult",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "TError",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Parameters
<ParameterTypes parameters={[
{
"name": "work",
"type": "(`transactionManager`: `EntityManager`) => `Promise`<`TResult`\\>",
"description": "the transactional work to be done",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "isolationOrErrorHandler",
"type": "`IsolationLevel` \\| (`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
"description": "the isolation level to be used for the work.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "maybeErrorHandlerOrDontFail",
"type": "(`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
"description": "Potential error handler",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`TResult`\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`TResult`\\>",
"optional": false,
"defaultValue": "",
"description": "the result of the transactional work",
"expandable": false,
"children": []
}
]} />
___
### clearLineItemsTaxLines
**clearLineItemsTaxLines**(`itemIds`): `Promise`<`void`\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "itemIds",
"type": "`string`[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`void`\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`void`\\>",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### clearTaxLines
**clearTaxLines**(`cartId`): `Promise`<`void`\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "cartId",
"type": "`string`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`void`\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`void`\\>",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### createShippingTaxLines
**createShippingTaxLines**(`shippingMethod`, `calculationContext`): `Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\>
Persists the tax lines relevant for a shipping method to the database. Used
for return shipping methods.
#### Parameters
<ParameterTypes parameters={[
{
"name": "shippingMethod",
"type": "[`ShippingMethod`](ShippingMethod.mdx)",
"description": "the shipping method to create tax lines for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "calculationContext",
"type": "[`TaxCalculationContext`](../types/TaxCalculationContext.mdx)",
"description": "the calculation context to get tax lines by",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \\| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\\>",
"optional": false,
"defaultValue": "",
"description": "the newly created tax lines",
"expandable": false,
"children": []
}
]} />
___
### createTaxLines
**createTaxLines**(`cartOrLineItems`, `calculationContext`): `Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\>
Persists the tax lines relevant for an order to the database.
#### Parameters
<ParameterTypes parameters={[
{
"name": "cartOrLineItems",
"type": "[`LineItem`](LineItem.mdx)[] \\| [`Cart`](Cart.mdx)",
"description": "the cart or line items to create tax lines for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "calculationContext",
"type": "[`TaxCalculationContext`](../types/TaxCalculationContext.mdx)",
"description": "the calculation context to get tax lines by",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \\| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\\>",
"optional": false,
"defaultValue": "",
"description": "the newly created tax lines",
"expandable": false,
"children": []
}
]} />
___
### getCacheKey
`Private` **getCacheKey**(`id`, `regionId`): `string`
The cache key to get cache hits by.
#### Parameters
<ParameterTypes parameters={[
{
"name": "id",
"type": "`string`",
"description": "the entity id to cache",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "regionId",
"type": "`string`",
"description": "the region id to cache",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`string`
<ParameterTypes parameters={[
{
"name": "string",
"type": "`string`",
"optional": true,
"defaultValue": "",
"description": "the cache key to use for the id set",
"expandable": false,
"children": []
}
]} />
___
### getRegionRatesForProduct
**getRegionRatesForProduct**(`productIds`, `region`): `Promise`<`Map`<`string`, [`TaxServiceRate`](../types/TaxServiceRate.mdx)[]\>\>
Gets the tax rates configured for a product. The rates are cached between
calls.
#### Parameters
<ParameterTypes parameters={[
{
"name": "productIds",
"type": "`string` \\| `string`[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "region",
"type": "[`RegionDetails`](../types/RegionDetails.mdx)",
"description": "the region to get configured rates for.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`Map`<`string`, [`TaxServiceRate`](../types/TaxServiceRate.mdx)[]\>\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`Map`<`string`, [`TaxServiceRate`](../types/TaxServiceRate.mdx)[]\\>\\>",
"optional": false,
"defaultValue": "",
"description": "the tax rates configured for the shipping option. A map by product id",
"expandable": false,
"children": []
}
]} />
___
### getRegionRatesForShipping
**getRegionRatesForShipping**(`optionId`, `regionDetails`): `Promise`<[`TaxServiceRate`](../types/TaxServiceRate.mdx)[]\>
Gets the tax rates configured for a shipping option. The rates are cached
between calls.
#### Parameters
<ParameterTypes parameters={[
{
"name": "optionId",
"type": "`string`",
"description": "the option id of the shipping method.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "regionDetails",
"type": "[`RegionDetails`](../types/RegionDetails.mdx)",
"description": "the region to get configured rates for.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`TaxServiceRate`](../types/TaxServiceRate.mdx)[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`TaxServiceRate`](../types/TaxServiceRate.mdx)[]\\>",
"optional": false,
"defaultValue": "",
"description": "the tax rates configured for the shipping option.",
"expandable": false,
"children": []
}
]} />
___
### getShippingTaxLines
**getShippingTaxLines**(`shippingMethod`, `calculationContext`): `Promise`<[`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx)[]\>
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
<ParameterTypes parameters={[
{
"name": "shippingMethod",
"type": "[`ShippingMethod`](ShippingMethod.mdx)",
"description": "the shipping method to get tax lines for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "calculationContext",
"type": "[`TaxCalculationContext`](../types/TaxCalculationContext.mdx)",
"description": "the calculation context to get tax lines by",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx)[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx)[]\\>",
"optional": false,
"defaultValue": "",
"description": "the computed tax lines",
"expandable": false,
"children": []
}
]} />
___
### getTaxLines
**getTaxLines**(`lineItems`, `calculationContext`): `Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\>
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
<ParameterTypes parameters={[
{
"name": "lineItems",
"type": "[`LineItem`](LineItem.mdx)[]",
"description": "the cart or order to get tax lines for",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "calculationContext",
"type": "[`TaxCalculationContext`](../types/TaxCalculationContext.mdx)",
"description": "the calculation context to get tax lines by",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<([`LineItemTaxLine`](LineItemTaxLine.mdx) \\| [`ShippingMethodTaxLine`](ShippingMethodTaxLine.mdx))[]\\>",
"optional": false,
"defaultValue": "",
"description": "the computed tax lines",
"expandable": false,
"children": []
}
]} />
___
### getTaxLinesMap
`Protected` **getTaxLinesMap**(`items`, `calculationContext`): `Promise`<[`TaxLinesMaps`](../types/TaxLinesMaps.mdx)\>
Return a map of tax lines for line items and shipping methods
#### Parameters
<ParameterTypes parameters={[
{
"name": "items",
"type": "[`LineItem`](LineItem.mdx)[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "calculationContext",
"type": "[`TaxCalculationContext`](../types/TaxCalculationContext.mdx)",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<[`TaxLinesMaps`](../types/TaxLinesMaps.mdx)\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`TaxLinesMaps`](../types/TaxLinesMaps.mdx)\\>",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### list
**list**(): `Promise`<[`TaxProvider`](TaxProvider.mdx)[]\>
#### Returns
`Promise`<[`TaxProvider`](TaxProvider.mdx)[]\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<[`TaxProvider`](TaxProvider.mdx)[]\\>",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### registerInstalledProviders
**registerInstalledProviders**(`providers`): `Promise`<`void`\>
#### Parameters
<ParameterTypes parameters={[
{
"name": "providers",
"type": "`string`[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`Promise`<`void`\>
<ParameterTypes parameters={[
{
"name": "Promise",
"type": "`Promise`<`void`\\>",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### retrieveProvider
**retrieveProvider**(`region`): [`ITaxService`](../interfaces/ITaxService.mdx)
Retrieves the relevant tax provider for the given region.
#### Parameters
<ParameterTypes parameters={[
{
"name": "region",
"type": "[`Region`](Region.mdx)",
"description": "the region to get tax provider for.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
[`ITaxService`](../interfaces/ITaxService.mdx)
<ParameterTypes parameters={[
{
"name": "getTaxLines",
"type": "(`itemLines`: [`ItemTaxCalculationLine`](../types/ItemTaxCalculationLine.mdx)[], `shippingLines`: [`ShippingTaxCalculationLine`](../types/ShippingTaxCalculationLine.mdx)[], `context`: [`TaxCalculationContext`](../types/TaxCalculationContext.mdx)) => `Promise`<[`ProviderTaxLine`](../types/ProviderTaxLine.mdx)[]\\>",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
___
### shouldRetryTransaction\_
`Protected` **shouldRetryTransaction_**(`err`): `boolean`
#### Parameters
<ParameterTypes parameters={[
{
"name": "err",
"type": "Record<`string`, `unknown`\\> \\| { `code`: `string` }",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
`boolean`
<ParameterTypes parameters={[
{
"name": "boolean",
"type": "`boolean`",
"optional": true,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />
___
### withTransaction
**withTransaction**(`transactionManager?`): [`TaxProviderService`](TaxProviderService.mdx)
#### Parameters
<ParameterTypes parameters={[
{
"name": "transactionManager",
"type": "`EntityManager`",
"description": "",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
#### Returns
[`TaxProviderService`](TaxProviderService.mdx)
<ParameterTypes parameters={[
{
"name": "TaxProviderService",
"type": "[`TaxProviderService`](TaxProviderService.mdx)",
"optional": false,
"defaultValue": "",
"description": "",
"expandable": false,
"children": []
}
]} />