TaxProviderService
Finds tax providers and assists in tax related operations.
constructor
Parameters
container
AwilixContainer<any>RequiredProperties
manager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequired__container__
anyRequiredcontainer_
AwilixContainer<any>Required__configModule__
Record<string, unknown>__moduleDeclaration__
Record<string, unknown>Accessors
activeManager_
Returns
EntityManager
EntityManagerRequiredMethods
withTransaction
Parameters
transactionManager
EntityManagerReturns
this
thisRequiredshouldRetryTransaction_
Parameters
err
Record<string, unknown> | objectRequiredReturns
boolean
booleanRequiredatomicPhase_
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.
Type Parameters
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
Promise<TResult>Requiredlist
Returns
retrieveProvider
Retrieves the relevant tax provider for the given region.
Parameters
Returns
ITaxService
objectRequiredsystem
provider. You can create your own tax provider,
either in a plugin or directly in your Medusa backend, then use it in any region.
A tax provider class is defined in a TypeScript or JavaScript file under the src/services
directory and the class must extend the
AbstractTaxService
class imported from @medusajs/medusa
. The file's name is the tax provider's class name as a slug and without the word Service
.
For example, you can create the file src/services/my-tax.ts
with the following content:
1import {2 AbstractTaxService,3 ItemTaxCalculationLine,4 ShippingTaxCalculationLine,5 TaxCalculationContext,6} from "@medusajs/medusa"7import {8 ProviderTaxLine,9} from "@medusajs/medusa/dist/types/tax-service"10
11class MyTaxService extends AbstractTaxService {12 async getTaxLines(13 itemLines: ItemTaxCalculationLine[],14 shippingLines: ShippingTaxCalculationLine[],15 context: TaxCalculationContext):16 Promise<ProviderTaxLine[]> {17 throw new Error("Method not implemented.")18 }19}20
21export default MyTaxService
TaxProvider
entity has 2 properties: identifier
and is_installed
. The identifier
property in the tax provider service is used when the tax provider is added to the database.
The value of this property is also used to reference the tax provider throughout Medusa. For example, it is used to change the tax provider to a region.
1class MyTaxService extends AbstractTaxService {2 static identifier = "my-tax"3 // ...4}
clearLineItemsTaxLines
Parameters
itemIds
string[]RequiredReturns
Promise
Promise<void>RequiredclearTaxLines
Parameters
cartId
stringRequiredReturns
Promise
Promise<void>RequiredcreateTaxLines
Persists the tax lines relevant for an order to the database.
Parameters
Returns
createShippingTaxLines
Persists the tax lines relevant for a shipping method to the database. Used for return shipping methods.
Parameters
Returns
getShippingTaxLines
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
Returns
getTaxLines
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
Returns
getTaxLinesMap
Return a map of tax lines for line items and shipping methods
Parameters
Returns
Promise
Promise<TaxLinesMaps>RequiredgetRegionRatesForShipping
Gets the tax rates configured for a shipping option. The rates are cached between calls.
Parameters
optionId
stringRequiredregionDetails
RegionDetailsRequiredReturns
getRegionRatesForProduct
Gets the tax rates configured for a product. The rates are cached between calls.
Parameters
productIds
string | string[]Requiredregion
RegionDetailsRequiredReturns
getCacheKey
The cache key to get cache hits by.
Parameters
id
stringRequiredregionId
stringRequiredReturns
string
stringRequiredregisterInstalledProviders
Parameters
providers
string[]RequiredReturns
Promise
Promise<void>Required