Skip to content

Commit 8d574d6

Browse files
authored
docs: improvements to tax related docs (medusajs#13845)
1 parent 226984c commit 8d574d6

File tree

4 files changed

+64
-19
lines changed

4 files changed

+64
-19
lines changed

www/apps/book/public/llms-full.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12171,7 +12171,7 @@ Some examples of service events:
1217112171

1217212172
## Emit Event in a Workflow
1217312173

12174-
To emit a workflow event, use the `emitEventStep` helper step provided in the `@medusajs/medusa/core-flows` package.
12174+
To emit a workflow event, use the `emitEventStep` helper step provided in the `@medusajs/medusa/core-flows` package. It allows you to emit an event from within a workflow, and it only emits the event after the workflow has finished successfully.
1217512175

1217612176
For example:
1217712177

@@ -40057,10 +40057,12 @@ Refer to this [Medusa Admin User Guide](https://docs.medusajs.com/user-guide/set
4005740057

4005840058
## What are Tax Rates?
4005940059

40060-
A tax rate is a percentage amount used to calculate the tax amount for each taxable item’s price, such as line items or shipping methods, in a cart. The sum of all calculated tax amounts are then added to the cart’s total as a tax total.
40060+
A tax rate, represented by the [TaxRate data model](https://docs.medusajs.com/references/tax/models/TaxRate/index.html.md), is a percentage amount used to calculate the tax amount for each taxable item’s price, such as line items or shipping methods, in a cart. The sum of all calculated tax amounts are then added to the cart’s total as a tax total.
4006140061

4006240062
Each tax region has a default tax rate. This tax rate is applied to all taxable items of a cart in that region.
4006340063

40064+
The `TaxRate` data model has a `rate` property that represents the percentage amount. For example, a `rate` of `10` means a tax rate of 10%.
40065+
4006440066
### Combinable Tax Rates
4006540067

4006640068
Tax regions can have parent tax regions. To inherit the tax rates of the parent tax region, set the `is_combinable` of the child’s tax rates to `true`.
@@ -83007,7 +83009,7 @@ A module is created under the `src/modules` directory of your Medusa application
8300783009

8300883010
### c. Define Module Options
8300983011

83010-
Next, define a TypeScript type for the Avalara module options. These options configure the module when it's registered in the Medusa application.
83012+
Next, define a TypeScript type for the Avalara Module options. These options configure the module when it's registered in the Medusa application.
8301183013

8301283014
Create the file `src/modules/avalara/types.ts` with the following content:
8301383015

@@ -83094,7 +83096,7 @@ The constructor of a module's service receives the following parameters:
8309483096
1. An object with the dependencies to resolve from the [Module's container](https://docs.medusajs.com/docs/learn/fundamentals/modules/container/index.html.md).
8309583097
2. An object with the module options passed to the provider when it's registered.
8309683098

83097-
In the constructor, you validate that the required module options are provided. Then, you create an instance of the `Avatax` client using the provided options.
83099+
In the constructor, you validate that the required options are provided. Then, you create an instance of the `Avatax` client using the provided options.
8309883100

8309983101
You also define the `getIdentifier` method required by the `ITaxProvider` interface, which returns the provider's identifier.
8310083102

@@ -84138,7 +84140,7 @@ In the compensation function, you revert the updates by restoring the original v
8413884140

8413984141
You can now create the workflow. Create the file `src/workflows/update-product-item.ts` with the following content:
8414084142

84141-
```ts title="src/workflows/update-variant-item.ts" highlights={updateVariantItemWorkflowHighlights}
84143+
```ts title="src/workflows/update-variant-item.ts" highlights={updateProductItemWorkflowHighlights}
8414284144
import { createWorkflow, WorkflowResponse, transform, when } from "@medusajs/framework/workflows-sdk"
8414384145
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
8414484146
import { updateItemStep } from "./steps/update-item"

www/apps/resources/app/commerce-modules/tax/tax-rates-and-rules/page.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ Refer to this [Medusa Admin User Guide](!user-guide!/settings/tax-regions#manage
1414

1515
## What are Tax Rates?
1616

17-
A tax rate is a percentage amount used to calculate the tax amount for each taxable item’s price, such as line items or shipping methods, in a cart. The sum of all calculated tax amounts are then added to the cart’s total as a tax total.
17+
A tax rate, represented by the [TaxRate data model](/references/tax/models/TaxRate), is a percentage amount used to calculate the tax amount for each taxable item’s price, such as line items or shipping methods, in a cart. The sum of all calculated tax amounts are then added to the cart’s total as a tax total.
1818

1919
Each tax region has a default tax rate. This tax rate is applied to all taxable items of a cart in that region.
2020

21+
The `TaxRate` data model has a `rate` property that represents the percentage amount. For example, a `rate` of `10` means a tax rate of 10%.
22+
2123
### Combinable Tax Rates
2224

2325
Tax regions can have parent tax regions. To inherit the tax rates of the parent tax region, set the `is_combinable` of the child’s tax rates to `true`.

www/apps/resources/generated/edit-dates.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const generatedEditDates = {
9090
"app/commerce-modules/tax/_events/page.mdx": "2024-07-03T19:27:13+03:00",
9191
"app/commerce-modules/tax/module-options/page.mdx": "2025-05-20T07:51:40.711Z",
9292
"app/commerce-modules/tax/tax-calculation-with-provider/page.mdx": "2025-05-20T07:51:40.711Z",
93-
"app/commerce-modules/tax/tax-rates-and-rules/page.mdx": "2025-02-26T11:35:15.214Z",
93+
"app/commerce-modules/tax/tax-rates-and-rules/page.mdx": "2025-10-24T06:02:42.062Z",
9494
"app/commerce-modules/tax/tax-region/page.mdx": "2025-05-20T07:51:40.711Z",
9595
"app/commerce-modules/tax/page.mdx": "2025-05-20T07:51:40.711Z",
9696
"app/commerce-modules/user/_events/_events-table/page.mdx": "2024-07-03T19:27:13+03:00",
@@ -1583,7 +1583,7 @@ export const generatedEditDates = {
15831583
"references/tax/interfaces/tax.TaxRateRuleDTO/page.mdx": "2024-12-10T14:55:13.509Z",
15841584
"references/tax/interfaces/tax.UpdateTaxRateDTO/page.mdx": "2024-12-10T14:55:13.523Z",
15851585
"references/tax/types/tax.JoinerRelationship/page.mdx": "2024-12-09T13:22:04.496Z",
1586-
"references/tax_provider/interfaces/tax_provider.ITaxProvider/page.mdx": "2025-05-20T07:51:41.054Z",
1586+
"references/tax_provider/interfaces/tax_provider.ITaxProvider/page.mdx": "2025-10-24T06:00:50.804Z",
15871587
"references/tax_provider/types/tax_provider.ItemTaxCalculationLine/page.mdx": "2024-12-09T13:22:04.464Z",
15881588
"references/tax_provider/types/tax_provider.ShippingTaxCalculationLine/page.mdx": "2024-12-09T13:22:04.460Z",
15891589
"references/types/DAL/interfaces/types.DAL.RepositoryService/page.mdx": "2025-10-21T08:10:45.266Z",

www/apps/resources/references/tax_provider/interfaces/tax_provider.ITaxProvider/page.mdx

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class MyTaxProvider implements ITaxProvider {
8686

8787
### constructor
8888

89-
You can use the `constructor` of your tax provider to access the resources registered in the [Module Container](https://docs.medusajs.com/resources/medusa-container-resources#module-container-resources).
89+
You can use the `constructor` of your Tax Module Provider's service to access the resources registered in the [Module Container](https://docs.medusajs.com/resources/medusa-container-resources#module-container-resources).
9090

9191
You can also use the constructor to initialize your integration with the third-party provider. For example, if you use a client to connect to the third-party provider’s APIs, you can initialize it in the constructor and use it in other methods in the service.
9292

@@ -95,20 +95,61 @@ Additionally, if you’re creating your tax provider as a plugin or a module pro
9595
For example:
9696

9797
```ts
98-
export default class MyTaxProvider implements ITaxProvider {
99-
// ...
100-
constructor(container, options) {
101-
// you can access options here
98+
import {
99+
ITaxProvider,
100+
Logger
101+
} from "@medusajs/framework/types"
102+
103+
type InjectedDependencies = {
104+
logger: Logger
105+
}
106+
107+
type Options = {
108+
apiKey: string
109+
}
102110

103-
// you can also initialize a client that
104-
// communicates with a third-party service.
111+
export default class MyTaxProvider implements ITaxProvider {
112+
static identifier = "my-tax"
113+
protected logger_: Logger
114+
protected options_: Options
115+
// assuming you're initializing a client
116+
protected client
117+
118+
constructor (
119+
{ logger }: InjectedDependencies,
120+
options: Options
121+
) {
122+
this.logger_ = logger
123+
this.options_ = options
124+
125+
// assuming you're initializing a client
105126
this.client = new Client(options)
106127
}
107128
}
108129
```
109130

110131
---
111132

133+
### getIdentifier
134+
135+
This method is used to retrieve the unique identifier of the tax provider.
136+
137+
#### Example
138+
139+
```ts
140+
export default class MyTaxProvider implements ITaxProvider {
141+
static identifier = "my-tax"
142+
143+
getIdentifier(): string {
144+
return MyTaxProvider.identifier
145+
}
146+
}
147+
```
148+
149+
#### Returns
150+
151+
<TypeList types={[{"name":"string","type":"`string`","optional":false,"defaultValue":"","description":"The unique identifier of the tax provider.","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getIdentifier"/>
152+
112153
### getTaxLines
113154

114155
This method is used to retrieve the tax lines of items and shipping methods. It's used during checkout
@@ -133,8 +174,8 @@ export default class SystemTaxService implements ITaxProvider {
133174
let taxLines: (TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[] =
134175
itemLines.flatMap((l) => {
135176
return l.rates.map((r) => ({
136-
rate_id: r.id,
137-
rate: r.rate || 0,
177+
rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it
178+
rate: r.rate || 0, // For example, 10 for 10%
138179
name: r.name,
139180
code: r.code,
140181
line_item_id: l.line_item.id,
@@ -145,8 +186,8 @@ export default class SystemTaxService implements ITaxProvider {
145186
taxLines = taxLines.concat(
146187
shippingLines.flatMap((l) => {
147188
return l.rates.map((r) => ({
148-
rate_id: r.id,
149-
rate: r.rate || 0,
189+
rate_id: r.id, // this is optional. When integrating with a third-party, you don't need to provide it
190+
rate: r.rate || 0, // For example, 10 for 10%
150191
name: r.name,
151192
code: r.code,
152193
shipping_line_id: l.shipping_line.id,

0 commit comments

Comments
 (0)