Back to Medusa

ITaxProvider

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

2.14.21.9 KB
Original Source

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
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.

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