Files
medusa-store/www/apps/resources/app/commerce-modules/currency/page.mdx
Shahed Nasser 2e16949979 docs: update imports and package names across docs (#9375)
* docs: update imports and package names across docs
+ reference configs

* generate files

* fix import

* change preview to rc
2024-10-01 11:03:42 +02:00

100 lines
2.7 KiB
Plaintext

import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Currency Module`,
}
# {metadata.title}
The Currency Module is the `@medusajs/medusa/currency` NPM package that provides currency-related features in your Medusa and Node.js applications.
## How to Use Currency Module's Service
You can use the Currency Module's main service by resolving from the Medusa container the resource `Modules.CURRENCY` imported from `@medusajs/framework/utils`.
For example:
<CodeTabs groupId="resource-type">
<CodeTab label="API Route" value="api-route">
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
Modules.CURRENCY
)
res.json({
currencies: await currencyModuleService.listCurrencies(),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { ICurrencyModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
export default async function subscriberHandler({ container }: SubscriberArgs) {
const currencyModuleService: ICurrencyModuleService = container.resolve(
Modules.CURRENCY
)
const currencies = await currencyModuleService.listCurrencies()
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { ICurrencyModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"
const step1 = createStep("step-1", async (_, { container }) => {
const currencyModuleService: ICurrencyModuleService = container.resolve(
Modules.CURRENCY
)
const currencies = await currencyModuleService.listCurrencies()
})
```
</CodeTab>
</CodeTabs>
---
## Features
### Currency Retrieval
List and retrieve currencies stored in your application.
```ts
const currency = await currencyModuleService.retrieveCurrency("usd")
```
### Support Currencies in Modules
Other commerce modules use currency codes in their data models or operations. You can use the Currency Module to retrieve a currency code and its details.
An example with the Region Module:
```ts
const region = await regionModuleService.retrieveCurrency("reg_123")
const currency = await currencyModuleService.retrieveCurrency(
region.currency_code
)
```