1 ---
2 generate_toc: true
3 ---
4
5 import { CodeTabs, CodeTab } from "docs-ui"
6
7 export const metadata = {
8 title: `Pricing Module`,
9 }
10
11 # {metadata.title}
12
13 In this section of the documentation, you will find resources to learn more about the Pricing Module and how to use it in your application.
14
15 <Note title="Looking for no-code docs?">
16
17 Refer to the [Medusa Admin User Guide](!user-guide!/price-lists) to learn how to manage price lists using the dashboard.
18
19 </Note>
20
21 Medusa has pricing related features available out-of-the-box through the Pricing Module. A [module](!docs!/learn/fundamentals/modules) 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 Pricing Module.
22
23 <Note>
24
25 Learn more about why modules are isolated in [this documentation](!docs!/learn/fundamentals/modules/isolation).
26
27 </Note>
28
29 ## Pricing Features
30
31 - [Price Management](./concepts/page.mdx): Store and manage prices of a resource, such as a product or a variant.
32 - [Multi-Currency and Region Support](./concepts/page.mdx#multi-currency-support-for-prices): Define prices for a single resource in multiple currencies and regions.
33 - [Advanced Rule Engine](./price-rules/page.mdx): Create prices with tiers and custom rules to condition prices based on different contexts.
34 - [Price Lists](./concepts/page.mdx#price-list): Group prices and apply them only in specific conditions with price lists.
35 - [Price Calculation Strategy](./price-calculation/page.mdx): Retrieve the best price in a given context and for the specified rule values.
36 - [Tax-Inclusive Pricing](./tax-inclusive-pricing/page.mdx): Calculate prices with taxes included in the price, and Medusa will handle calculating the taxes automatically.
37
38 ---
39
40 ## How to Use the Pricing Module
41
42 In your Medusa application, you build flows around Commerce Modules. A flow is built as a [Workflow](!docs!/learn/fundamentals/workflows), which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
43
44 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.
45
46 For example:
47
48 export const highlights = [
49 ["12", "Modules.PRICING", "Resolve the module in a step."]
50 ]
51
52 ```ts title="src/workflows/create-price-set.ts" highlights={highlights}
53 import {
54 createWorkflow,
55 WorkflowResponse,
56 createStep,
57 StepResponse,
58 } from "@medusajs/framework/workflows-sdk"
59 import { Modules } from "@medusajs/framework/utils"
60
61 const createPriceSetStep = createStep(
62 "create-price-set",
63 async ({}, { container }) => {
64 const pricingModuleService = container.resolve(Modules.PRICING)
65
66 const priceSet = await pricingModuleService.createPriceSets({
67 prices: [
68 {
69 amount: 500,
70 currency_code: "USD",
71 },
72 {
73 amount: 400,
74 currency_code: "EUR",
75 min_quantity: 0,
76 max_quantity: 4,
77 rules: {},
78 },
79 ],
80 })
81
82 return new StepResponse({ priceSet }, priceSet.id)
83 },
84 async (priceSetId, { container }) => {
85 if (!priceSetId) {
86 return
87 }
88 const pricingModuleService = container.resolve(Modules.PRICING)
89
90 await pricingModuleService.deletePriceSets([priceSetId])
91 }
92 )
93
94 export const createPriceSetWorkflow = createWorkflow(
95 "create-price-set",
96 () => {
97 const { priceSet } = createPriceSetStep()
98
99 return new WorkflowResponse({
100 priceSet,
101 })
102 }
103 )
104 ```
105
106 You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:
107
108 <CodeTabs group="resource-types">
109 <CodeTab label="API Route" value="api-route">
110
111 ```ts title="src/api/workflow/route.ts" highlights={[["11"], ["12"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports"
112 import type {
113 MedusaRequest,
114 MedusaResponse,
115 } from "@medusajs/framework/http"
116 import { createPriceSetWorkflow } from "../../workflows/create-price-set"
117
118 export async function GET(
119 req: MedusaRequest,
120 res: MedusaResponse
121 ) {
122 const { result } = await createPriceSetWorkflow(req.scope)
123 .run()
124
125 res.send(result)
126 }
127 ```
128
129 </CodeTab>
130 <CodeTab label="Subscriber" value="subscriber">
131
132 ```ts title="src/subscribers/user-created.ts" highlights={[["11"], ["12"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports"
133 import {
134 type SubscriberConfig,
135 type SubscriberArgs,
136 } from "@medusajs/framework"
137 import { createPriceSetWorkflow } from "../workflows/create-price-set"
138
139 export default async function handleUserCreated({
140 event: { data },
141 container,
142 }: SubscriberArgs<{ id: string }>) {
143 const { result } = await createPriceSetWorkflow(container)
144 .run()
145
146 console.log(result)
147 }
148
149 export const config: SubscriberConfig = {
150 event: "user.created",
151 }
152 ```
153
154 </CodeTab>
155 <CodeTab label="Scheduled Job" value="scheduled-job">
156
157 ```ts title="src/jobs/run-daily.ts" highlights={[["7"], ["8"]]}
158 import { MedusaContainer } from "@medusajs/framework/types"
159 import { createPriceSetWorkflow } from "../workflows/create-price-set"
160
161 export default async function myCustomJob(
162 container: MedusaContainer
163 ) {
164 const { result } = await createPriceSetWorkflow(container)
165 .run()
166
167 console.log(result)
168 }
169
170 export const config = {
171 name: "run-once-a-day",
172 schedule: `0 0 * * *`,
173 }
174 ```
175
176 </CodeTab>
177 </CodeTabs>
178
179 Learn more about workflows in [this documentation](!docs!/learn/fundamentals/workflows).
180
181 ---
182
183 <CommerceModuleSections />