Currency Module

In this section of the documentation, you will find resources to learn more about the Currency Module and how to use it in your application.

Medusa has currency related features available out-of-the-box through the Currency Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Currency Module.

NoteLearn more about why modules are isolated in this documentation.

Currency Features#


How to Use the Currency Module#

In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.

You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows package.

For example:

src/workflows/retrieve-price-with-currency.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6  transform,7} from "@medusajs/framework/workflows-sdk"8import { Modules } from "@medusajs/framework/utils"9
10const retrieveCurrencyStep = createStep(11  "retrieve-currency",12  async ({}, { container }) => {13    const currencyModuleService = container.resolve(Modules.CURRENCY)14
15    const currency = await currencyModuleService16      .retrieveCurrency("usd")17
18    return new StepResponse({ currency })19  }20)21
22type Input = {23  price: number24}25
26export const retrievePriceWithCurrency = createWorkflow(27  "create-currency",28  (input: Input) => {29    const { currency } = retrieveCurrencyStep()30
31    const formattedPrice = transform({32      input,33      currency,34    }, (data) => {35      return `${data.currency.symbol}${data.input.price}`36    })37
38    return new WorkflowResponse({39      formattedPrice,40    })41  }42)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

Learn more about workflows in this documentation.


Was this page helpful?
Edit this page