This directory holds the code for the Subscription recipe example.
You can either:
- install and use it as a Medusa application;
- or copy its source files into an existing Medusa application.
This recipe uses Stripe for payments, specifically capturing payment for renewed subscriptions. So, you must have a Stripe account and secret API key.
- 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
If you have an existing Medusa application, copy the content of the following directories:
src/modules/subscription
src/links
src/workflows
src/api
src/jobs
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
- OpenAPI Spec file: Can be imported into tools like Postman to view and send requests to this project's API routes.
- Medusa Documentation