* docs: tax provider updates for next release * change images * fix vale error * fix vale errors * generate
72 lines
1.8 KiB
Plaintext
72 lines
1.8 KiB
Plaintext
export const metadata = {
|
||
title: `Tax Calculation with the Tax Provider`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
In this guide, you’ll 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 Module’s 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 region’s [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.
|