Files
Shahed Nasser 76bc21ff25 docs: tax provider updates for next release (#12431)
* docs: tax provider updates for next release

* change images

* fix vale error

* fix vale errors

* generate
2025-05-13 14:13:17 +03:00

72 lines
1.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const metadata = {
title: `Tax Calculation with the Tax Provider`,
}
# {metadata.title}
In this guide, youll learn how tax lines are calculated using the tax provider.
## Tax Lines Calculation
Tax lines are calculated and retrieved using the [getTaxLines method of the Tax Modules main service](/references/tax/getTaxLines). It accepts an array of line items and shipping methods, and the context of the calculation.
For example:
```ts
const taxLines = await taxModuleService.getTaxLines(
[
{
id: "cali_123",
product_id: "prod_123",
unit_price: 1000,
quantity: 1,
},
{
id: "casm_123",
shipping_option_id: "so_123",
unit_price: 2000,
},
],
{
address: {
country_code: "us",
},
}
)
```
The context object is used to determine which tax regions and rates to use in the calculation. It includes properties related to the address and customer.
The example above retrieves the tax lines based on the tax region for the United States.
The method returns tax lines for the line item and shipping methods. For example:
```json
[
{
"line_item_id": "cali_123",
"rate_id": "txr_1",
"rate": 10,
"code": "XXX",
"name": "Tax Rate 1"
},
{
"shipping_line_id": "casm_123",
"rate_id": "txr_2",
"rate": 5,
"code": "YYY",
"name": "Tax Rate 2"
}
]
```
---
## Using the Tax Provider in the Calculation
The tax lines retrieved by the `getTaxLines` method are actually retrieved from the tax regions [Tax Module Provider](../tax-provider/page.mdx).
A tax module implements the logic to shape tax lines. Each tax region uses a tax provider.
Learn more about tax providers, configuring, and creating them in the [Tax Module Provider](../tax-provider/page.mdx) guide.