Store Credit Module

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

Note: The Store Credit Module is part of the Loyalty Plugin. It's compatible with Medusa v2.14.0+.
Looking for no-code docs? Refer to the Medusa Admin User Guide to learn how to manage store credit using the dashboard.

Medusa has store-credit related features available through the Store Credit 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 Store Credit Module.

Note: Learn more about why modules are isolated in this documentation.

Features#


How to Use the Store Credit Module#

1. Install the Loyalty Plugin#

The Store Credit Module is part of the Loyalty Plugin. So, install the loyalty plugin:

Then, add it to your medusa-config.js:

medusa-config.js
1module.exports = defineConfig({2  // ... other configurations3  plugins: [4    {5      resolve: `@medusajs/loyalty-plugin`,6      options: {},7    },8    // ... other plugins9  ],10})

2. Run Migrations#

After installing the plugin, run the migrations to create the necessary tables in the database:

3. Use Store Credit Features in Your Application#

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 the Loyalty Plugin's workflows and steps.

For example:

src/workflows/create-store-credit.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7
8const createStoreCreditStep = createStep(9  "create-store-credit-account",10  async ({}, { container }) => {11    const storeCreditModuleService = container.resolve("store_credit")12
13    const storeCreditAccount = await storeCreditModuleService.createStoreCreditAccounts({14      code: "test-code",15      customer_id: "customer_123",16      currency_code: "usd",17    })18
19    return new StepResponse({ storeCreditAccount }, storeCreditAccount.id)20  },21  async (storeCreditAccountId, { container }) => {22    const storeCreditModuleService = container.resolve("store_credit")23
24    await storeCreditModuleService.deleteStoreCreditAccounts([storeCreditAccountId])25  }26)27
28export const createStoreCreditWorkflow = createWorkflow(29  "create-store-credit-account",30  () => {31    const { storeCreditAccount } = createStoreCreditStep()32
33    return new WorkflowResponse({34      storeCreditAccount,35    })36  }37)

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?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break