Currency Module
The Currency Module is the @medusajs/currency
NPM package that provides currency-related features in your Medusa and Node.js applications.
Features
Currency Retrieval
List and retrieve currencies stored in your application.
By default, the module, on application start, adds currencies defined in this file to the database.
Support Currencies in Modules
Other commerce modules use currency codes in their models or operations. You can use the Currency Module to retrieve a currency code and its details.
An example with the Region Module:
Configure Currency Module
After installing the @medusajs/currency
package in your Medusa application, add it to the modules
object in medusa-config.js
:
How to Use Currency Module's Service
You can use the Currency Module's main service by resolving from the dependency container the resource ModuleRegistrationName.CURRENCY
imported from @medusajs/modules-sdk
.
For example:
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService =
req.scope.resolve(ModuleRegistrationName.CURRENCY)
res.json({
currencies: await currencyModuleService.list(),
})
}
import { SubscriberArgs } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const currencyModuleService: ICurrencyModuleService =
container.resolve(ModuleRegistrationName.CURRENCY)
const currencies = await currencyModuleService.list()
}
import { createStep } from "@medusajs/workflows-sdk"
import { ICurrencyModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const currencyModuleService: ICurrencyModuleService =
context.container.resolve(
ModuleRegistrationName.CURRENCY
)
const currencies = await currencyModuleService.list()
})