A full-stack e-commerce store built with Next.js 13, featuring Stripe payment integration, Tailwind CSS for styling, and Zustand for state management.
- Modern Next.js 13: Built with the App Router and Server Components
- Stripe Integration: Secure payment processing with subscription support
- Responsive Design: Mobile-first design using Tailwind CSS
- State Management: Efficient cart management with Zustand
- TypeScript Support: Type-safe development
- Server-Side Rendering: Optimized performance and SEO
- Frontend: Next.js 13, React, Tailwind CSS
- Backend: Next.js API Routes
- Payments: Stripe API
- State Management: Zustand
- Styling: Tailwind CSS
- Deployment: Vercel (recommended)
- Node.js 18+
- npm or yarn
- Stripe account with test keys
-
Clone the repository
git clone https://github.com/Andre-tech671/ShopHub.git cd shophub -
Install dependencies
npm install
-
Environment Setup Create a
.env.localfile in the root directory:STRIPE_SECRET=sk_test_your_stripe_secret_key_here
-
Stripe Setup
- Create products and prices in your Stripe dashboard
- Ensure prices are set as recurring subscriptions (monthly)
- Copy the price IDs for your products
-
Run the development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
shophub/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ └── checkout/ # Stripe checkout endpoint
│ ├── (store)/ # Route groups
│ │ └── store.js # Zustand store
│ ├── product/ # Product detail page
│ ├── success/ # Checkout success page
│ ├── cancel/ # Checkout cancel page
│ ├── layout.js # Root layout
│ ├── page.js # Home page
│ ├── Header.js # Navigation header
│ ├── Modal.js # Shopping cart modal
│ └── ProductCard.js # Product display component
├── public/ # Static assets
├── .env.local # Environment variables
└── README.md # This file
- Products are fetched from Stripe on the server-side
- Each product card displays name, price, description, and image
- Clicking a product navigates to its detail page
- Zustand store manages cart state globally
- Add items to cart from product detail page
- Cart modal shows all items with quantities
- Cart persists across page navigations
- Cart items are sent to
/api/checkoutendpoint - Stripe creates a subscription checkout session
- User is redirected to Stripe's hosted checkout page
- After payment, user returns to success or cancel page
User clicks "Add to Cart" → Cart Modal → "Checkout" → API Call → Stripe Session → Redirect to Stripe → Payment → Success/Cancel Page
The cart system uses Zustand for state management:
- addItemToCart: Adds products to cart with price_id, name, and cost
- removeItemFromCart: Removes items by index
- setOpenModal: Toggles cart modal visibility
- emptyCart: Clears all items
- Receives lineItems from frontend
- Creates Stripe checkout session with subscription mode
- Returns session URL for redirect
- Includes error handling and logging
- Maps cart items to Stripe lineItems format
- Sends POST request to checkout API
- Handles success/error responses
- Redirects to Stripe checkout
- Tailwind CSS: Utility-first CSS framework
- Responsive Design: Mobile-first approach
- Custom Components: Reusable UI components
- Font Awesome: Icons for cart and social links
- Push your code to GitHub
- Connect your repo to Vercel
- Add environment variables in Vercel dashboard
- Deploy!
- Ensure your hosting supports Next.js 13
- Set environment variables for Stripe keys
- Configure build commands if needed
"Stripe session creation failed"
- Check your Stripe secret key in
.env.local - Ensure prices are set as recurring subscriptions
- Verify API version is compatible
Cart not updating
- Check Zustand store implementation
- Verify component re-renders on state changes
Payment not processing
- Test with Stripe test cards
- Check webhook endpoints if using webhooks
- Verify success/cancel URLs
Not used - checkout is handled via POST
Creates a Stripe checkout session
Request Body:
{
"lineItems": [
{
"price": "price_1ABC...",
"quantity": 1
}
]
}Response:
{
"session": {
"url": "https://checkout.stripe.com/..."
}
}- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is open source and available under the MIT License.
For issues or questions:
- Open an issue on GitHub
- Check Stripe documentation for payment-related questions
- Review Next.js docs for framework questions