|
1
|
{"slug":"/references/tax/ITaxProvider/methods/tax.ITaxProvider.getTaxLines","title":"getTaxLines","frontmatter":{"displayed_sidebar":"taxReference"},"toc":[{"title":"Example","id":"example","level":2},{"title":"Parameters","id":"gettaxlines-parameters","level":2},{"title":"Returns","id":"gettaxlines-returns","level":2}],"blocks":[{"kind":"markdown","html":"This method is used to retrieve the tax lines of items and shipping methods. It's used during checkout \nwhen the `getTaxLines` method of the Tax Module's main service is called for a tax\nregion that uses this tax provider."},{"kind":"heading","level":2,"text":"Example","id":"example"},{"kind":"markdown","html":"An example of how this method is implemented in the `system` provider:\n\n```ts\n// ...\n\nexport default class SystemTaxService implements ITaxProvider {\n // ...\n\n async getTaxLines(\n itemLines: TaxTypes.ItemTaxCalculationLine[],\n shippingLines: TaxTypes.ShippingTaxCalculationLine[],\n _: TaxTypes.TaxCalculationContext\n ): Promise<(TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[]> {\n let taxLines: (TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[] =\n itemLines.flatMap((l) => {\n return l.rates.map((r) => ({\n rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it\n rate: r.rate || 0, // For example, 10 for 10%\n name: r.name,\n code: r.code,\n line_item_id: l.line_item.id,\n provider_id: this.getIdentifier(),\n }))\n })\n\n taxLines = taxLines.concat(\n shippingLines.flatMap((l) => {\n return l.rates.map((r) => ({\n rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it\n rate: r.rate || 0, // For example, 10 for 10%\n name: r.name,\n code: r.code,\n shipping_line_id: l.shipping_line.id,\n provider_id: this.getIdentifier(),\n }))\n })\n )\n\n return taxLines\n }\n}\n```"},{"kind":"heading","level":2,"text":"Parameters","id":"gettaxlines-parameters"},{"kind":"typeList","sectionTitle":"getTaxLines","types":[{"name":"itemLines","type":"[ItemTaxCalculationLine](/references/tax/types/tax.ItemTaxCalculationLine)[]","description":"The line item lines to calculate taxes for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"line_item","type":"[TaxableItemDTO](/references/tax/interfaces/tax.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](/references/tax/types/tax.BigNumberInput)","description":"The quantity of the taxable item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"unit_price","type":"[BigNumberInput](/references/tax/types/tax.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](/references/tax/interfaces/tax.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](https://docs.medusajs.com/resources/commerce-modules/tax/tax-rates-and-rules#combinable-tax-rates).","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](/references/tax/types/tax.ShippingTaxCalculationLine)[]","description":"The shipping method lines to calculate taxes for.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"shipping_line","type":"[TaxableShippingDTO](/references/tax/interfaces/tax.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](/references/tax/types/tax.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](/references/tax/interfaces/tax.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](https://docs.medusajs.com/resources/commerce-modules/tax/tax-rates-and-rules#combinable-tax-rates).","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](/references/tax/interfaces/tax.TaxCalculationContext)","description":"The context relevant and useful for the taxes calculation.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"locale","type":"`string`","description":"The locale of the tax calculation.","optional":true,"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](https://en.wikipedia.org/wiki/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":"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":[]}]},{"name":"additional_context","type":"`Record<string, unknown>`","description":"Additional context to pass to the underlying tax provider.\n\nUse this to forward custom data that isn't part of the framework-provided\nfields but that your tax provider needs to calculate tax lines accurately.\nIn cart and order tax workflows, this is populated by the `setTaxLineContext` hook.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"kind":"heading","level":2,"text":"Returns","id":"gettaxlines-returns"},{"kind":"typeList","sectionTitle":"getTaxLines","types":[{"name":"Promise","type":"Promise<([ItemTaxLineDTO](/references/tax/interfaces/tax.ItemTaxLineDTO) \\| [ShippingTaxLineDTO](/references/tax/interfaces/tax.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](/references/tax/interfaces/tax.ItemTaxLineDTO) \\| [ShippingTaxLineDTO](/references/tax/interfaces/tax.ShippingTaxLineDTO))[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"ItemTaxLineDTO \\| ShippingTaxLineDTO","type":"[ItemTaxLineDTO](/references/tax/interfaces/tax.ItemTaxLineDTO) \\| [ShippingTaxLineDTO](/references/tax/interfaces/tax.ShippingTaxLineDTO)","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]}]}]} |