Skip to content

Latest commit

 

History

History
105 lines (76 loc) · 2.47 KB

README.md

File metadata and controls

105 lines (76 loc) · 2.47 KB

Medusa v2 Example: Subscription

This directory holds the code for the Subscription recipe example.

You can either:

Prerequisites

This recipe uses Stripe for payments, specifically capturing payment for renewed subscriptions. So, you must have a Stripe account and secret API key.

Installation

  1. Clone the repository and change to the subscription directory:
git clone https://github.com/medusajs/examples.git
cd examples/subscription

2. Rename the .env.template file to .env.

3. If necessary, change the PostgreSQL username, password, and host in the DATABASE_URL environment variable.

4. Add the Stripe secret API key in .env:

STRIPE_API_KEY=

5. Install dependencies:

yarn # or npm install

6. Setup and seed the database:

npx medusa db:setup
yarn seed # or npm run seed

7. Start the Medusa application:

yarn dev # or npm run dev

Copy into Existing Medusa Application

If you have an existing Medusa application, copy the content of the following directories:

  1. src/modules/subscription
  2. src/links
  3. src/workflows
  4. src/api
  5. src/jobs
  6. src/admin

Then, add the Subscription Module and Stripe Module Provider to medusa-config.js:

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "./modules/subscription",
    },
    {
      resolve: "@medusajs/medusa/payment",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/payment-stripe",
            id: "stripe",
            options: {
              apiKey: process.env.STRIPE_API_KEY,
            },
          },
        ],
      },
    },
  ]
})

And set the Stripe API key as an environment variable:

STRIPE_API_KEY=

Finally, run the migrations and sync links before starting the Medusa application:

npx medusa db:migrate

More Resources