on GitHub" data-tooltip-id=":R1blcldb:">v2.5.1·Edited Oct 3·
This recipe provides the general steps to build subscription-based purchase with Medusa.
Subscription-based purchase allows customers to purchase products for a specified period, and the payment and fulfillment is processed within a regular interval in that period.
For example, a customer can purchase a book subscription box for a period of three months. Each month, the payment is captured for that order and, if the payment is successful, the fulfillment is processed.
Subscriptions have details related to the subscription interval, subscription period, and more.
To store the subscription details, create a data model in a new subscription module. The module's main service provides data management feature of the data model.
You can link the subscription data model to models of other modules, such as the Order Module's Order
data model.
Define a module link that links a data model from your subscription module with a data model from another module.
For example, you can link the subscription data model to the Order Module's Order
data model.
If you want to create subscriptions on the product level, you can link the subscription data model to the Product Module's Product
data model.
There are different ways to implement subscriptions in your Medusa application. This recipe covers two options.
By implementing the subscription logic within your application, you have full control over the subscription logic. You'll also be independent of payment providers, providing customers with more than one payment provider.
Implementing the logic depends on your use case, but you'll mainly implement the following:
Stripe provides a subscription payments feature that allows you to authorize payment on a subscription basis within Stripe. Stripe then handles checking for recurring payments and capturing payment at the specified interval.
This approach allows you to delegate the complications of implementing the subscription logic to Stripe, but doesn't support using other payment providers.
Although Medusa provides a Stripe module provider, it doesn't handle subscriptions. You can create a custom Stripe Subscription module provider.
You can extend the admin to provide an interface to manage your custom features, such as view the subscriptions.
Extend the Medusa Admin to add widgets to existing pages or add new pages.
Medusa provides a Next.js Starter. Since you've customized your Medusa project, you must either customize the existing Next.js Starter, or create a custom storefront.