Welcome to my experiment where I'm integrating Next.js 15 with Stripe, the popular payment platform. This project is a playground to explore how to handle payments, subscriptions, and billing functionalities using Stripe in a modern Next.js environment.
Start by cloning the repository to your local machine:
git clone https://github.com/your-username/nextjs-stripe-integration.git
cd nextjs-stripe-integration
Make sure you have Node.js installed. Then, run the following command to install all the necessary packages:
npm install
If you don't already have a Stripe account, sign up here. Once you have your account, you'll need to create API keys.
Create a .env.local
file in the root of your project, and add the following Stripe keys (you can find them in the Stripe dashboard):
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=your-publishable-key-here
STRIPE_SECRET_KEY=your-secret-key-here
Important: Make sure you don’t commit your secret key into version control! 🌱
To start the development server, use the following command:
npm run dev
This will launch the app on http://localhost:3000
. You can start testing the payment flow right away!
- Stripe Checkout Integration: A simple way to integrate Stripe’s hosted payment page.
- Payment Intents: Implementing Stripe's Payment Intent API for handling secure transactions.
- Client-Side & Server-Side Communication: Next.js API routes handle server-side logic to interact with the Stripe API.
- Webhooks: Experiment with Stripe webhooks to process events like payment success or failure.
- Next.js 15 – A powerful React framework for building fast websites and apps.
- Stripe – A payment processing platform.
- React – To build the frontend UI.
- Serverless Functions (Actions) – Async functions executed on the server.
app/checkout/*
: Pages to trigger the checkout and to success message (when payment is concluded).
app/actions/create-stripe-session.ts
: Async function to generate Stripe sessions for checkout.
In test mode, you can use the following card numbers to simulate different scenarios:
- Successful payment:
4242 4242 4242 4242
- Card declined:
4000 0000 0000 0002
- Card requiring authentication:
4000 0025 0000 3155
To test Stripe webhooks locally, you can use Stripe CLI to forward events to your local server.
- This project is intended for experimentation and learning purposes.
- It is production-ready, but you can use it as a base for your own Stripe integration.
- Don’t forget to replace the test keys with live keys when you're ready to go live! 🎉
This project is licensed under the MIT License.
Feel free to reach out if you need any help or encounter issues! Happy experimenting! 😄