www/apps/resources/references/tax/ITaxProvider/methods/tax.ITaxProvider.getTaxLines/page.mdx
import { TypeList } from "docs-ui"
This method is used to retrieve the tax lines of items and shipping methods. It's used during checkout
when the getTaxLines method of the Tax Module's main service is called for a tax
region that uses this tax provider.
An example of how this method is implemented in the system provider:
// ...
export default class SystemTaxService implements ITaxProvider {
// ...
async getTaxLines(
itemLines: TaxTypes.ItemTaxCalculationLine[],
shippingLines: TaxTypes.ShippingTaxCalculationLine[],
_: TaxTypes.TaxCalculationContext
): Promise<(TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[]> {
let taxLines: (TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[] =
itemLines.flatMap((l) => {
return l.rates.map((r) => ({
rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it
rate: r.rate || 0, // For example, 10 for 10%
name: r.name,
code: r.code,
line_item_id: l.line_item.id,
provider_id: this.getIdentifier(),
}))
})
taxLines = taxLines.concat(
shippingLines.flatMap((l) => {
return l.rates.map((r) => ({
rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it
rate: r.rate || 0, // For example, 10 for 10%
name: r.name,
code: r.code,
shipping_line_id: l.shipping_line.id,
provider_id: this.getIdentifier(),
}))
})
)
return taxLines
}
}
<TypeList types={[{"name":"itemLines","type":"ItemTaxCalculationLine[]","description":"The line item lines to calculate taxes for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"line_item","type":"TaxableItemDTO","description":"The line item to calculate taxes for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The ID of the taxable item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_id","type":"string","description":"The associated product's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"product_type_id","type":"string","description":"The ID of the type of the item's product.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"BigNumberInput","description":"The quantity of the taxable item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"unit_price","type":"BigNumberInput","description":"The unit price of the taxable item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"string","description":"The ISO 3 character currency code of the taxable item.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rates","type":"TaxRateDTO[]","description":"The rates applicable on the item.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The ID of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"null \| number","description":"The rate to charge.","optional":false,"defaultValue":"","example":"10","expandable":false,"children":[]},{"name":"code","type":"null \| string","description":"The code the tax rate is identified by.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"string","description":"The name of the Tax Rate.","optional":false,"defaultValue":"","example":"VAT","expandable":false,"children":[]},{"name":"metadata","type":"null \| Record<string, unknown>","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region_id","type":"string","description":"The ID of the associated tax region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_combinable","type":"boolean","description":"Whether the tax rate should be combined with parent rates.\n\nLearn more here.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"boolean","description":"Whether the tax rate is the default rate for the region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"string \| Date","description":"The creation date of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"string \| Date","description":"The update date of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"null \| Date","description":"The deletion date of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"null \| string","description":"Who created the tax rate. For example, the ID of the user that created the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"shippingLines","type":"ShippingTaxCalculationLine[]","description":"The shipping method lines to calculate taxes for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"shipping_line","type":"TaxableShippingDTO","description":"The shipping method to calculate taxes for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The ID of the taxable shipping.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_id","type":"string","description":"The associated shipping option's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"unit_price","type":"BigNumberInput","description":"The unit price of the taxable shipping.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"currency_code","type":"string","description":"The ISO 3 character currency code of the taxable shipping.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"rates","type":"TaxRateDTO[]","description":"The rates applicable on the shipping method.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The ID of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"rate","type":"null \| number","description":"The rate to charge.","optional":false,"defaultValue":"","example":"10","expandable":false,"children":[]},{"name":"code","type":"null \| string","description":"The code the tax rate is identified by.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"string","description":"The name of the Tax Rate.","optional":false,"defaultValue":"","example":"VAT","expandable":false,"children":[]},{"name":"metadata","type":"null \| Record<string, unknown>","description":"Holds custom data in key-value pairs.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"tax_region_id","type":"string","description":"The ID of the associated tax region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_combinable","type":"boolean","description":"Whether the tax rate should be combined with parent rates.\n\nLearn more here.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_default","type":"boolean","description":"Whether the tax rate is the default rate for the region.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_at","type":"string \| Date","description":"The creation date of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"updated_at","type":"string \| Date","description":"The update date of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"deleted_at","type":"null \| Date","description":"The deletion date of the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"created_by","type":"null \| string","description":"Who created the tax rate. For example, the ID of the user that created the tax rate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"context","type":"TaxCalculationContext","description":"The context relevant and useful for the taxes calculation.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"address","type":"object","description":"The customer's address","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"country_code","type":"string","description":"The ISO 2 character currency code.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"province_code","type":"null \| string","description":"The lower-case ISO 3166-2 province or state code.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_1","type":"string","description":"The first line of the address.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"address_2","type":"null \| string","description":"The second line of the address","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"city","type":"string","description":"The city.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"postal_code","type":"string","description":"The postal code.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"null \| Record<string, unknown>","description":"Address metadata.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"locale","type":"string","description":"The locale of the tax calculation.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"object","description":"The customer's details.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The ID of the customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"string","description":"The email of the customer.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer_groups","type":"string[]","description":"The groups that the customer belongs to.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"metadata","type":"null \| Record<string, unknown>","description":"Customer metadata.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"is_return","type":"boolean","description":"Whether the tax lines are calculated for an order return.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_methods","type":"object[]","description":"The shipping method details.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"string","description":"The associated shipping method's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"name","type":"string","description":"The name of the shipping method.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option_id","type":"string","description":"The associated shipping options's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"number","description":"The amount of the shipping method.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getTaxLines"/>
<TypeList types={[{"name":"Promise","type":"Promise<(ItemTaxLineDTO \| ShippingTaxLineDTO)[]>","optional":false,"defaultValue":"","description":"The list of calculated line item and shipping tax lines.\nIf an item in the array has the shipping_line_id property, then it's a shipping tax line. Otherwise, if it has\nthe line_item_id property, then it's a line item tax line.","expandable":false,"children":[{"name":"(ItemTaxLineDTO \| ShippingTaxLineDTO)[]","type":"(ItemTaxLineDTO \| ShippingTaxLineDTO)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"ItemTaxLineDTO \| ShippingTaxLineDTO","type":"ItemTaxLineDTO \| ShippingTaxLineDTO","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getTaxLines"/>