docs: improvements to tax related docs (#13845)

This commit is contained in:
Shahed Nasser
2025-10-24 09:44:47 +03:00
committed by GitHub
parent 226984cf0f
commit 8d574d6f29
4 changed files with 64 additions and 19 deletions
@@ -86,7 +86,7 @@ export default class MyTaxProvider implements ITaxProvider {
### constructor
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).
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).
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 providers APIs, you can initialize it in the constructor and use it in other methods in the service.
@@ -95,13 +95,34 @@ Additionally, if youre creating your tax provider as a plugin or a module pro
For example:
```ts
export default class MyTaxProvider implements ITaxProvider {
// ...
constructor(container, options) {
// you can access options here
import {
ITaxProvider,
Logger
} from "@medusajs/framework/types"
// you can also initialize a client that
// communicates with a third-party service.
type InjectedDependencies = {
logger: Logger
}
type Options = {
apiKey: string
}
export default class MyTaxProvider implements ITaxProvider {
static identifier = "my-tax"
protected logger_: Logger
protected options_: Options
// assuming you're initializing a client
protected client
constructor (
{ logger }: InjectedDependencies,
options: Options
) {
this.logger_ = logger
this.options_ = options
// assuming you're initializing a client
this.client = new Client(options)
}
}
@@ -109,6 +130,26 @@ export default class MyTaxProvider implements ITaxProvider {
---
### getIdentifier
This method is used to retrieve the unique identifier of the tax provider.
#### Example
```ts
export default class MyTaxProvider implements ITaxProvider {
static identifier = "my-tax"
getIdentifier(): string {
return MyTaxProvider.identifier
}
}
```
#### Returns
<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"/>
### getTaxLines
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 {
let taxLines: (TaxTypes.ItemTaxLineDTO | TaxTypes.ShippingTaxLineDTO)[] =
itemLines.flatMap((l) => {
return l.rates.map((r) => ({
rate_id: r.id,
rate: r.rate || 0,
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,
@@ -145,8 +186,8 @@ export default class SystemTaxService implements ITaxProvider {
taxLines = taxLines.concat(
shippingLines.flatMap((l) => {
return l.rates.map((r) => ({
rate_id: r.id,
rate: r.rate || 0,
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,