Food restaurants remain one of the best lucrative businesses around the world. They get patronage on a daily basis without being much affected by a country's economy because people depend on food for survival.
Creating an avenue for your food restaurant to sell online helps your business reach a wide range of people who won’t be available to buy in your physical shop and increases your daily sales
In this tutorial, you will learn how to build a complete food ecommerce restaurant using Medusa ecommerce engine with Paystack integration.
Visit the Docs to learn more about our system requirements.
What is Medusa
Medusa is a set of commerce modules and tools that allow you to build rich, reliable, and performant commerce applications without reinventing core commerce logic. The modules can be customized and used to build advanced ecommerce stores, marketplaces, or any product that needs foundational commerce primitives. All modules are open-source and freely available on npm.
Medusa provides bespoke commerce infrastructure for developers. Its composable commerce engine addresses the challenges of existing ecommerce platforms which APIs offer bad developer experiences, extension capabilities are insufficient, and results are hacky and hard to maintain.
The solutions ships as a headless backend with a comprehensive feature set covering core elements related to order, product, and customer handling. In addition, it provides advanced features related to promotions, multi-currency handling, RMA flows, customer group handling and much more. For a comprehensive overview of the solutions and integrations, see Medusa’s documentation.
Used by some of the world's largest companies, Next.js enables you to create full-stack web applications by extending the latest React features, and integrating powerful Rust-based JavaScript tooling for the fastest builds.
Visit our Learn Next.js course to get started with Next.js.
Visit the Next.js Showcase to see more sites built with Next.js.
The Next.js community can be found on GitHub Discussions where you can ask questions, voice ideas, and share your projects with other people.
To chat with other community members you can join the Next.js Discord server.
Do note that our Code of Conduct applies to all Next.js community channels. Users are highly encouraged to read and adhere to them to avoid repercussions.
Contributing
Contributions to Next.js are welcome and highly appreciated. However, before you jump right into it, we would like you to review our…
Next.js is a JavaScript open source framework for building superfast and extremely user-friendly frontend websites using React. It is a server-rendered, lightweight, and flexible React framework that requires little or no configuration during usage.
Using Medusa commerce engine to build your online stores gives you the opportunity to work with Medusa Next.js storefront starter, which can be easily installed through CLI commands.
Medusa Next.js storefront is a 100% ready-to-use Medusa storefront template. It comes with all ecommerce storefront features such as product display, featured products, shopping cart, checking out, multiple payment processing, and more.
What is Paystack?
Paystack is the #1 African payment gateway that helps businesses to accept online payments through their ecommerce stores, websites, and applications. Paystack provides other services such as point-of-sale (PoS), payment through an invoice, and more.
The integration between Medusa and Paystack can be achieved using a community plugin, which you’ll learn in this tutorial.
The above code snippet adds Medusa Paystack plugin to your project configurations.
Installing MinIO Medusa Plugin
Managing images in Medusa requires a file service plugin for uploading images of products. Medusa provides different options for handling image upload for products, but this tutorial will focus only on using MinIO file service plugin.
MinIO is a high-performance open source object storage solution that provides S3 storage functionality. You can follow this documentation to learn how to install it and create a bucket.
Install MinIO plugin in the Medusa server directory with the command below:
npm install medusa-file-minio
Next, add the following block of code to your .env:
Note: <ENDPOINT> is the URL of your MinIO server, <BUCKET> is the name of the bucket you created earlier, and <ACCESS_KEY> and <SECRET_KEY> are the keys you generated in the previous section.
Finally, in medusa-config.js, add the following at the end of the pluginsarray:
If you’ve completed the above processes, start your store server with the command below:
medusa develop
You can navigate to localhost:9000/store/products/ to see available products in your store.
Creating Medusa Admin for your Food Restaurant
To set up your Medusa Admin, follow the steps below.
Clone the Medusa Admin repository and change to the newly created folder:
git clone https://github.com/medusajs/admin medusa-admin
cd medusa-admin
Run the command below to install all necessary dependencies:
npm install
Test it:
(Note: Ensure your Medusa store server is running before testing your admin.)
npm start
By default, Medusa Admin runs on port 7000. You can go to localhost:7000 on your browser to access your admin page.
Medusa Server comes with admin login details, which are admin@medusa-test.com as the email address and supersecret as the password. This demo data is a result of --seed added while creating your store server.
You can visit the User Guide to learn more about Medusa Admin.
Adding Paystack Payment Provider to your Regions
Food restaurants could be inter-state or international businesses, which means your store should be focused on selling products to a particular country.
This tutorial will be focused on using the Nigerian currency since it’s one of the Paystack-supported countries.
If you are not selling to Paystack-supported African countries, you can easily integrate Medusa Stripe Payment Plugin in your store.
To add Paystack to your regions, follow the steps below to set your store currency;
Go to Settings ⇒ Currencies.
2. Click on the Edit currencies button in the Store Currencies section.
3. In the new window that opens, click on the Add Currencies button and select all the currencies you want to add.
4. Click on the Save and close button.
Note: Set your default currency to Nigerian Naira after the 4th step.
2. Click on the plus icon at the top right of the Regions section .
3. In the form that opens, enter the Regions details. It is required to enter a title, choose a currency, enter a tax rate, and choose at least one country where your restaurant is based, payment provider (select Paystack), and fulfillment provider.
Once done, click on the Create region button at the top-right side.
Medusa Next.js Storefront Template already has every feature you may need in your storefront in it; this helps to quicken your development process when you choose to work with Medusa as your commerce engine.
The steps below will help you create your food restaurant Storefront:
Run the command below to create a new Next.js starter project:
food-restaurant-storefront represents the name of your project; you can rename it as you wish.
Switch to the newly created directory food-restaurant-storefront and rename the template environment variable file to use environment variables in development:
cd food-restaurant-storefront
mv .env.template .env.local
Customizing Your Storefront
Since you have successfully created your food restaurant storefront, you can customize your storefront to your taste.
You can find all images used for this project in the GitHub repository.
Modify Your Homepage Banner: To do so, locate src/modules/home/components/hero/index.tsx and replace its contents with the code below:
The above code block will change the banner image and change the text.
Secondly, modify your Featured Product section. To do so, locate src/modules/home/components/featured-products/index.tsx and replace its contents with the code below:
The above code snippet will change the default texts to match what you are building the store for.
Third, modify your part of the footer section. To do so, locate your src/modules/**layout**/components/footer-cta/index.tsx and replace its content with the code below:
import UnderlineLink from "@modules/common/components/underline-link"
import Image from "next/image"
const FooterCTA = () => {
return (
<div className="bg-gray-800 w-full">
<div className="content-container flex flex-col-reverse gap-y-8 small:flex-row small:items-center justify-between py-16 relative">
<div>
<h3 className="text-3xl-semi text-white">Flavourful Flame</h3>
<h3 className="text-2xl text-white">Grilled Chicken</h3>
<p className="text-white">Marinated for 24 hours in our herb-infused traditional marinade, the perfectly grilled chicken on your plate is the healthiest and tastiest in town!</p>
<div className="mt-6 text-white">
<UnderlineLink href="/store">Order Now</UnderlineLink>
</div>
</div>
<div className="relative w-full aspect-square small:w-[35%] small:aspect-[28/36]">
<Image
src="/more.jpg"
alt=""
layout="fill"
objectFit="cover"
className="absolute inset-0"
/>
</div>
</div>
</div>
)
}
export default FooterCTA
The above code block will change the background image and text.
Enable Paystack Payment
To enable using Paystack to accept payments from your storefront, you follow the steps below accordingly:
Install the React Paystack library:
npm install react-paystack
Once the library is installed successfully, it will add the react Paystack package to your storefront project.
Add the Paystack public key to your .env.local file:
NEXT_PUBLIC_PAYSTACK_PUBLIC_KEY=pk_test_xxxxxx
On the above, replace pk_test_xxxxxx with the secret key gotten from your Paystack API Key.
Modify your payment buttons by adding the block of code below into your src/modules/checkout/components/payment-button/index.tsx file:
import clsx from "clsx"
import { PaystackButton } from "react-paystack"
The above code will import your Paystack button from react-payment library, and clsx library for Paytsack button styling.
Next, add PaystackPaymentButton among the switch case for the payment session:
case "paystack":
return (
<PaystackPaymentButton notReady={notReady} session={paymentSession} />
)
Finally, add the block of code before your last line of code on this same file:
The above code block will add Paystack button as part of the payment option for your storefront.
PaystackButton triggers the checkout payment button to process the payment whenever it’s clicked on your storefront.
To be sure you got the above two code blocks correctly, you can make a reference here.
Modify your payment container by adding the code block as part of the PaymentInfoMap collection. Here is the file path src/modules/checkout/component/payment-container/index.tsx:
paystack: {
title: "Paystack",
description: "Secure payment with Paystack",
}
The above code makes it possible for Paystack to appear as part of the payment option in your storefront.
To be sure you got the above code block correctly, you can make a reference here.
Test your Storefront
Ensure your Medusa Server is running, then run this command:
npm run dev
If you navigate to localhost:8000, you’ll see your storefront homepage.
If you click on Food Menu you’ll see all foods populated from your Medusa Server.
If you click on any of the food items, you’ll see the single product page and an Add to cart option.
If you click on My Bag after adding an item to the cart, you should see the Shopping Bag page.
If you click on GO TO CHECKOUT, you’ll see your Checkout Page, where you will provide your delivery information.
If you click on “PAY WITH PAYSTACK” you’ll see the Paystack Payment pop-up:
If you select Success and click on the Pay button, your payment will be processed and you’ll see the Order Receipt Page;
You can confirm the orders from your Medusa Admin panel for this project.
Conclusion
In this tutorial, you have learned how to use the Medusa commerce engine as your ecommerce store for food restaurants, working with Medusa’s Next.js Storefront Template and Integrating Paystack payment gateway into Medusa.
You can learn more about building awesome ecommerce stores with Medusa; check out Medusa’s Documentation for more guides.
Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via Discord.