ITaxModuleService
The main service interface for the Tax Module.
Methods
retrieve
This method retrieves a tax by its ID.
Example
A simple example that retrieves a tax rate by its ID:
To specify relations that should be retrieved:
Parameters
taxRateId
stringRequiredconfig
FindConfig<TaxRateDTO>The configurations determining how the tax rate is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a tax rate.
config
FindConfig<TaxRateDTO>select
or relations
, accept the
attributes or relations associated with a tax rate.Returns
The retrieved tax.
list
This method retrieves a paginated list of tax rates based on optional filters and configuration.
Example
To retrieve a list of tax rates using their IDs:
To specify relations that should be retrieved within the tax rate:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterableTaxRatePropsThe filters to apply on the retrieved tax rates.
filters
FilterableTaxRatePropsconfig
FindConfig<TaxRateDTO>The configurations determining how the tax rate is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a tax rate.
config
FindConfig<TaxRateDTO>select
or relations
, accept the
attributes or relations associated with a tax rate.Returns
The list of tax rates.
listAndCount
This method retrieves a paginated list of tax rates along with the total count of available tax rates satisfying the provided filters.
Example
To retrieve a list of tax rates using their IDs:
To specify relations that should be retrieved within the tax rate:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterableTaxRatePropsThe filters to apply on the retrieved tax rates.
filters
FilterableTaxRatePropsconfig
FindConfig<TaxRateDTO>The configurations determining how the tax rate is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a tax rate.
config
FindConfig<TaxRateDTO>select
or relations
, accept the
attributes or relations associated with a tax rate.Returns
The list of tax rates along with their total count.
create
**create**(data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)[]>
This method creates tax rates.
Example
const taxRates = await taxModuleService.create([
{
tax_region_id: "txreg_123",
name: "Default rate",
rate: 10,
},
{
tax_region_id: "txreg_123",
name: "Custom rate",
rate: 15,
rules: [
{
reference: "product_type",
reference_id: "ptyp_1",
},
{
reference: "product",
reference_id: "prod_123",
},
],
},
])
Parameters
The tax rates to be created.
Returns
The created tax rates.
**create**(data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)>
This method creates a tax rate.
Example
Parameters
The tax rate to be created.
Returns
The created tax rate.
update
**update**(taxRateId, data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)>
This method updates an existing tax rate.
Example
Parameters
taxRateId
stringRequiredThe attributes to update in the tax rate.
Returns
The updated tax rate.
**update**(taxRateIds, data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)[]>
This method updates existing tax rates.
Example
Parameters
taxRateIds
string[]RequiredThe attributes to update in the tax rate.
Returns
The updated tax rates.
**update**(selector, data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)[]>
This method updates existing tax rates matching the specified filters.
Example
Parameters
The filters specifying which tax rates to update.
The attributes to update in the tax rate.
Returns
The updated tax rates.
upsert
**upsert**(data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)>
This method updates or creates a tax rate if it doesn't exist.
Example
Parameters
The attributes in the tax rate to be created or updated.
Returns
The created or updated tax rate.
**upsert**(data, sharedContext?): Promise<[TaxRateDTO](types.TaxTypes.TaxRateDTO.mdx)[]>
This method updates or creates tax rates if they don't exist.
Example
Parameters
The attributes in the tax rates to be created or updated.
Returns
The created or updated tax rates.
delete
**delete**(taxRateIds, sharedContext?): Promise<void>
This method deletes tax rates by their IDs.
Example
Parameters
taxRateIds
string[]RequiredReturns
Promise
Promise<void>Required**delete**(taxRateId, sharedContext?): Promise<void>
This method deletes a tax rate by its ID.
Example
Parameters
taxRateId
stringRequiredReturns
Promise
Promise<void>Requiredrestore
This method restores soft deleted tax rates by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
taxRateIds
string[]Requiredconfig
RestoreReturn<TReturnableLinkableKeys>Configurations determining which relations to restore along with each of the tax. You can pass to its returnLinkableKeys
property any of the tax rate's relation attribute names, such as rules
.
config
RestoreReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the tax rate's relation attribute names, such as rules
.Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were restored, such as the ID of associated rules.
The object's keys are the ID attribute names of the tax rate entity's relations, such as rule_id
,
and its value is an array of strings, each being the ID of the record associated with the tax rate through this relation,
such as the IDs of associated rules.
If there are no related records restored, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredrule_id
,
and its value is an array of strings, each being the ID of the record associated with the tax rate through this relation,
such as the IDs of associated rules.
If there are no related records restored, the promise resolves to void
.createTaxRegions
**createTaxRegions**(data, sharedContext?): Promise<[TaxRegionDTO](types.TaxTypes.TaxRegionDTO.mdx)>
This method creates a tax region.
Example
Parameters
The tax region to be created.
Returns
The created tax region.
**createTaxRegions**(data, sharedContext?): Promise<[TaxRegionDTO](types.TaxTypes.TaxRegionDTO.mdx)[]>
This method creates tax regions.
Example
Parameters
The tax regions to be created.
Returns
The created tax regions.
deleteTaxRegions
**deleteTaxRegions**(taxRegionIds, sharedContext?): Promise<void>
This method deletes tax regions by their IDs.
Example
Parameters
taxRegionIds
string[]RequiredReturns
Promise
Promise<void>Required**deleteTaxRegions**(taxRegionId, sharedContext?): Promise<void>
This method deletes a tax region by its ID.
Example
Parameters
taxRegionId
stringRequiredReturns
Promise
Promise<void>RequiredlistTaxRegions
This method retrieves a paginated list of tax regions based on optional filters and configuration.
Example
To retrieve a list of tax regions using their IDs:
To specify relations that should be retrieved within the tax region:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterableTaxRegionPropsThe filters to apply on the retrieved tax regions.
filters
FilterableTaxRegionPropsconfig
FindConfig<TaxRegionDTO>The configurations determining how the tax region is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a tax region.
config
FindConfig<TaxRegionDTO>select
or relations
, accept the
attributes or relations associated with a tax region.Returns
The list of tax regions.
createTaxRateRules
**createTaxRateRules**(data, sharedContext?): Promise<[TaxRateRuleDTO](types.TaxTypes.TaxRateRuleDTO.mdx)>
This method creates a tax rate rule.
Example
Parameters
The tax rate rule to be created.
Returns
The created tax rate rule.
**createTaxRateRules**(data, sharedContext?): Promise<[TaxRateRuleDTO](types.TaxTypes.TaxRateRuleDTO.mdx)[]>
This method creates tax rate rules.
Example
Parameters
The tax rate rules to be created.
Returns
The created tax rate rules.
deleteTaxRateRules
**deleteTaxRateRules**(taxRateRuleId, sharedContext?): Promise<void>
This method deletes a tax rate rule by its ID.
Example
Parameters
taxRateRuleId
stringRequiredReturns
Promise
Promise<void>Required**deleteTaxRateRules**(taxRateRuleIds, sharedContext?): Promise<void>
This method deletes tax rate rules by their IDs.
Example
Parameters
taxRateRuleIds
string[]RequiredReturns
Promise
Promise<void>RequiredlistTaxRateRules
This method retrieves a paginated list of tax rate rules based on optional filters and configuration.
Example
To retrieve a list of tax rate rules using their associated tax rate's ID:
To specify relations that should be retrieved within the tax rate rule:
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
Parameters
filters
FilterableTaxRateRulePropsThe filters to apply on the retrieved tax rate rules.
filters
FilterableTaxRateRulePropsconfig
FindConfig<TaxRateRuleDTO>The configurations determining how the tax rate rule is retrieved. Its properties, such as select
or relations
, accept the
attributes or relations associated with a tax rate rule.
config
FindConfig<TaxRateRuleDTO>select
or relations
, accept the
attributes or relations associated with a tax rate rule.Returns
The list of tax rate rules.
getTaxLines
This method retrieves tax lines for taxable items and shipping methods in a cart.
Learn more in this guide.
Example
Parameters
The context to pass to the underlying tax provider. It provides more
details that are useful to provide accurate tax lines.
Returns
The item and shipping methods' tax lines.
softDelete
This method soft deletes tax raes by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
taxRateIds
string[]Requiredconfig
SoftDeleteReturn<TReturnableLinkableKeys>An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
config
SoftDeleteReturn<TReturnableLinkableKeys>Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were also soft deleted, such as the ID of the associated rules.
The object's keys are the ID attribute names of the tax rate entity's relations, such as rule_id
, and its value is an array of strings, each being the ID of a record associated
with the tax rate through this relation, such as the IDs of associated rules.
If there are no related records, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredrule_id
, and its value is an array of strings, each being the ID of a record associated
with the tax rate through this relation, such as the IDs of associated rules.
If there are no related records, the promise resolves to void
.softDeleteTaxRegions
This method soft deletes tax regions by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
taxRegionIds
string[]Requiredconfig
SoftDeleteReturn<TReturnableLinkableKeys>An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
config
SoftDeleteReturn<TReturnableLinkableKeys>Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were also soft deleted, such as the ID of the associated tax rates.
The object's keys are the ID attribute names of the tax region entity's relations, such as tax_rate_id
, and its value is an array of strings, each being the ID of a record associated
with the tax region through this relation, such as the IDs of associated tax rates.
If there are no related records, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredtax_rate_id
, and its value is an array of strings, each being the ID of a record associated
with the tax region through this relation, such as the IDs of associated tax rates.
If there are no related records, the promise resolves to void
.restoreTaxRegions
This method restores soft deleted tax regions by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
taxRegionIds
string[]Requiredconfig
RestoreReturn<TReturnableLinkableKeys>Configurations determining which relations to restore along with each of the tax. You can pass to its returnLinkableKeys
property any of the tax region's relation attribute names, such as tax_rates
.
config
RestoreReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the tax region's relation attribute names, such as tax_rates
.Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were restored, such as the ID of associated tax rates.
The object's keys are the ID attribute names of the tax region entity's relations, such as tax_rate_id
,
and its value is an array of strings, each being the ID of the record associated with the tax region through this relation,
such as the IDs of associated tax rates.
If there are no related records restored, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredtax_rate_id
,
and its value is an array of strings, each being the ID of the record associated with the tax region through this relation,
such as the IDs of associated tax rates.
If there are no related records restored, the promise resolves to void
.softDeleteTaxRateRules
This method soft deletes tax rate rules by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
taxRateRuleIds
string[]Requiredconfig
SoftDeleteReturn<TReturnableLinkableKeys>An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted.
config
SoftDeleteReturn<TReturnableLinkableKeys>Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were also soft deleted.
If there are no related records, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredvoid
.restoreTaxRateRules
This method restores soft deleted tax rate rules by their IDs.
Example
Type Parameters
TReturnableLinkableKeys
stringRequiredParameters
taxRateRuleIds
string[]Requiredconfig
RestoreReturn<TReturnableLinkableKeys>Configurations determining which relations to restore along with each of the tax. You can pass to its returnLinkableKeys
property any of the tax rate rule's relation attribute names.
config
RestoreReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the tax rate rule's relation attribute names.Returns
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were restored.
If there are no related records restored, the promise resolves to void
.
Promise
Promise<void | Record<string, string[]>>Requiredvoid
.