Co-authored-by: olivermrbl <olivermrbl@users.noreply.github.com>
74 lines
2.0 KiB
Plaintext
74 lines
2.0 KiB
Plaintext
---
|
||
displayed_sidebar: taxReference
|
||
---
|
||
|
||
import { TypeList } from "docs-ui"
|
||
|
||
# ITaxProvider
|
||
|
||
### Identifier Property
|
||
|
||
Each tax provider has a unique identifier defined in its class. The provider's ID
|
||
will be stored as `tp_{identifier}_{id}`, where `{id}` is the provider's `id`
|
||
property in the `medusa-config.ts`.
|
||
|
||
For example:
|
||
|
||
```ts title="src/modules/my-tax/service.ts"
|
||
export default class MyTaxProvider implements ITaxProvider {
|
||
static identifier = "my-tax"
|
||
// ...
|
||
}
|
||
```
|
||
|
||
### constructor
|
||
|
||
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 provider’s APIs, you can initialize it in the constructor and use it in other methods in the service.
|
||
|
||
Additionally, if you’re creating your tax provider as a plugin or a module provider to be installed in any Medusa application and you want to access its options, you can access them in the second parameter of the constructor.
|
||
|
||
For example:
|
||
|
||
```ts
|
||
import {
|
||
ITaxProvider,
|
||
Logger
|
||
} from "@medusajs/framework/types"
|
||
|
||
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)
|
||
}
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## Methods
|
||
|
||
- [getIdentifier](../../ITaxProvider/methods/tax.ITaxProvider.getIdentifier/page.mdx)
|
||
- [getTaxLines](../../ITaxProvider/methods/tax.ITaxProvider.getTaxLines/page.mdx)
|