Digital Products
This document guides you through the different documentation resources that will help you build digital products with Medusa.
Overview
Digital products are stored privately using a storage service like S3 or another storage mechanism. When the customer buys this type of product, an email is sent to them where they can download the product.
Medusa doesn't have a built-in concept of a digital product since our focus is standardizing features and implementations, then offering the building blocks that enable you to build your use case.
You can create new entities to represent a digital product and link them to existing product-related entities.
Medusa's plugins also allow you to choose the services that play a part in your digital product implementation. Whether you want to use S3, MinIO, or another service to store your digital products, you must install an existing plugin or create your own. The same applies to sending notifications, such as emails, to customers using notification services.
Install a File Service
A file service is used to handle storage functionalities in Medusa. This includes uploading, retrieving, and downloading files, among other features. For digital products, a file service is essential to implement the basic functionalities of digital products.
The Medusa core defines an abstract file service extended by File Service plugins with the actual functionality. This allows you to choose the best storage method for your use case.
When you install a Medusa project, the Local file service plugin is installed by default. This plugin is helpful for development, but it's not recommended for production.
Medusa also provides official file service plugins that you can use in production, such as the S3 plugin or the MinIO plugin. You can also create your own file service, or browse the Plugins Library for plugins created by the community.
Check out available official file service plugins.
Check out available community file service plugins.
Learn how to create a custom file service.
Install a Notification Service
A notification service is used to handle sending notifications to users and customers. For example, when you want to send an order confirmation email or an email with reset-password instructions.
For digital products, a notification service allows you to send the customer an email or another form of notification with a link to download the file they purchased.
The Medusa core defines an abstract Notification service extended by Notification Service plugins with the actual functionality. This allows you to choose the best notification method for your use case.
Medusa provides official notification plugins that you can use, such as the SendGrid plugin. You can also create your own notification service, or browse the Plugins Library for plugins created by the community.
Check out available official notification plugins.
Check out available community notification service plugins.
Learn how to create a custom notification service.
Create Custom Entity
An entity represents a table in the database. The Medusa core defines entities necessary for the commerce features it provides. You can also extend those entities or create your own.
To represent a digital product, it's recommended to create an entity that has a relation to the ProductVariant
entity. The ProductVariant
entity represents the saleable variant of a Product
.
For example, if you're selling the Harry Potter movies, you would have a Product
named “Harry Potter” and, for each movie in the series, a ProductVariant
. Each ProductVariant
would be associated with the custom entity you create that represents the downloadable movie.
Learn how to create an entity in the Medusa backend.
Learn how to extend an entity in the Medusa backend.
Example: Create ProductMedia Entity
Add Custom API Routes
After creating your entity, you need to create custom admin API Routes that allow you to access and manipulate that entity. The API Routes necessary vary based on your case, but generally speaking, you'll need API Routes to perform Create, Read, Update, and Delete (CRUD) functionalities.
The Medusa backend provides the necessary API Routes for the actual file upload. So, you don’t need to create API Routes for that.
You can also create custom storefront API Routes that allow you to show information related to the downloadable digital product if this information isn't stored within the Product
or ProductVariant
entities.
Creating an API Route also requires creating a service, which is a class that typically holds utility methods for an entity. You can implement the CRUD functionalities as methods within the service, then access the service in an API Route and use its methods.
Learn how to create a service in the Medusa backend.
Learn how to create an entity in the Medusa backend.
Example: List and Create API Routes
Customize Admin Dashboard
The Medusa Admin dashboard provides merchants with an easy-to-use interface to manage their store's data and settings. It's also extendable, so you can add widgets, pages, and setting pages relevant to your use case.
To add an interface that allows the admin user to upload digital products, you can create custom widgets or pages that use the routes you created. You can use the Protected Files Upload API Route.
Learn how to create a widget in the Medusa Admin.
Learn how to create a UI route in the Medusa Admin.
Learn about the expected request body and response.
Example: Digital Products Page in Admin
Deliver Digital Products to the Customer
When a customer purchases a digital product, they should receive a link to download it.
To implement that, you first need to listen to the order.placed
event using a Subscriber. Then, in the subscriber handler function, you check for the digital products in the order and obtain the download URLs using the file service's getPresignedDownloadUrl
method.
Following this approach assumes the file service you're using handles creating secure presigned URLs with an expiration mechanism. Alternatively, you can create a new service that handles creating and validating tokens, and an API Route that receives that token to allow customers to download the file.
Finally, you can send a notification, such as an email, to the customer using the Notification Service of your choice. That notification would hold the download links to the products they purchased.
Learn how to create a service in the Medusa backend.
Example: Using SendGrid
Customize or Build Storefront
Customers use your storefront to browse your digital products and purchase them. You can also provide other helpful features such as previewing the digital product before purchase.
Medusa provides a Next.js storefront with standard commerce features including listing products, placing orders, and managing accounts. You can customize the storefront and cater its functionalities to support digital products.
Alternatively, you can follow the Build a Storefront roadmap to build a storefront with your preferred technology stack.
The rest of this section provides some guidelines into how to customize the Next.js storefront to support digital products.
While our team ensures to maintain this section with the changes in the Next.js storefront, some changes may cause the code in this section to be outdated. If you encounter outdated code snippets, please submit an issue.
Preview Digital Product
In the product detail's page, you can add a button that allows customers to download a preview of the digital product.
To implement this, create a storefront API Route that allows you to fetch the digital product, then customize the Next.js storefront to show the preview button if a product is digital.
Example
Update Product Tabs
In the product details page, additional information related to the product and its shipping details are shown at the bottom right side.
You can change this section to show information relevant to the product. For example, how many pages are in an e-book, or how the e-book will be delivered to the customer.
Example
Change Shipping Form in Checkout
When a customer purchases a digital product, the shipping form shown during checkout is not relevant. So, you can change its content to instead only ask for the customer's name and email.
Example
Download Product After Purchase
After the customer purchases the digital product you can show a download button to allow them to immediately download the product.
Example
Additional Development
You can find other resources for your dit development in the Medusa Development section of this documentation.