97 lines
2.4 KiB
Plaintext
97 lines
2.4 KiB
Plaintext
import { CodeTabs, CodeTab } from "docs-ui"
|
|
|
|
export const metadata = {
|
|
title: `Currency Module`,
|
|
}
|
|
|
|
# {metadata.title}
|
|
|
|
The Currency Module 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="Workflow Step" value="workflow-step">
|
|
|
|
```ts title="src/workflows/hello-world/step1.ts"
|
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
|
import { Modules } from "@medusajs/framework/utils"
|
|
|
|
const step1 = createStep("step-1", async (_, { container }) => {
|
|
const currencyModuleService = container.resolve(
|
|
Modules.CURRENCY
|
|
)
|
|
|
|
const currencies = await currencyModuleService.listCurrencies()
|
|
})
|
|
```
|
|
|
|
</CodeTab>
|
|
<CodeTab label="API Route" value="api-route">
|
|
|
|
```ts title="src/api/store/custom/route.ts"
|
|
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
import { Modules } from "@medusajs/framework/utils"
|
|
|
|
export async function GET(
|
|
req: MedusaRequest,
|
|
res: MedusaResponse
|
|
): Promise<void> {
|
|
const currencyModuleService = 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/framework"
|
|
import { Modules } from "@medusajs/framework/utils"
|
|
|
|
export default async function subscriberHandler({ container }: SubscriberArgs) {
|
|
const currencyModuleService = 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. Use the Currency Module to retrieve a currency code and its details.
|
|
|
|
An example with the Region Module:
|
|
|
|
```ts
|
|
const region = await regionModuleService.retrieveRegion("reg_123")
|
|
const currency = await currencyModuleService.retrieveCurrency(
|
|
region.currency_code
|
|
)
|
|
```
|