A secure, full-featured e-commerce application built with Django and Stripe Checkout integration. This project implements a complete online shopping experience with product browsing, shopping cart functionality, user authentication, and secure payment processing.
- Product Catalog: Browse and search products with detailed information
- Shopping Cart: Add, remove, and manage items in your cart
- User Authentication: Secure user registration, login, and profile management
- Order Management: Track order history and status
- Stripe Checkout: Secure payment processing with Stripe's hosted checkout page
- Webhook Integration: Reliable order confirmation using Stripe webhooks
- Admin Dashboard: Manage products, orders, and users through Django admin
- Secure webhook validation to prevent payment fraud
- CSRF protection on all forms
- Environment-based configuration for sensitive data
- Secure session management
ECommerce/
βββ accounts/ # User authentication and profile management
βββ cart/ # Shopping cart functionality
βββ core/ # Project settings and configuration
βββ orders/ # Order processing and Stripe integration
βββ shop/ # Product catalog and shop functionality
βββ templates/ # HTML templates
βββ manage.py # Django management script
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (not in repo)
| File/Directory | Purpose |
|---|---|
manage.py |
Django command-line utility |
.env |
Stores sensitive API keys and secrets (must be in .gitignore) |
orders/models.py |
Order model for database tracking |
orders/views.py |
Stripe checkout and webhook endpoints |
shop/models.py |
Product and category models |
cart/cart.py |
Shopping cart session management |
- Python 3.8 or higher
- pip (Python package manager)
- Stripe account (for payment processing)
- PostgreSQL (for production) or SQLite (for development)
git clone https://github.com/MocLG/ECommerce.git
cd ECommerce# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root with the following variables:
# Django Settings
SECRET_KEY=your-secret-key-here
DEBUG=True
# Stripe API Keys (get from https://dashboard.stripe.com/test/apikeys)
STRIPE_PUBLISHABLE_KEY=pk_test_************************
STRIPE_SECRET_KEY=sk_test_****************************
STRIPE_WEBHOOK_SECRET=whsec_*************************
# Database (optional for production)
DATABASE_URL=postgresql://user:password@localhost/dbnameNote: Never commit your
.envfile to version control!
# Run migrations
python manage.py makemigrations
python manage.py migrate
# Create superuser for admin access
python manage.py createsuperuserpython manage.py runserverVisit http://127.0.0.1:8000/ in your browser.
To test payments locally, you'll need to set up webhook forwarding using the Stripe CLI.
Follow the Stripe CLI installation guide.
In your first terminal:
source venv/bin/activate # or venv\Scripts\activate on Windows
python manage.py runserverIn a second terminal:
# Login to Stripe
stripe login
# Forward webhooks to your local server
stripe listen --forward-to localhost:8000/payment/stripe-webhook/Copy the webhook signing secret (whsec_...) displayed by the CLI and update STRIPE_WEBHOOK_SECRET in your .env file.
- Navigate to
http://127.0.0.1:8000/ - Add items to your cart
- Proceed to checkout
- Use Stripe test card numbers:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Use any future expiration date and any CVC
- Success:
The webhook listener will show the event being received and processed.
This application is ready for deployment on platforms like:
- Heroku: Use the included
Procfileandruntime.txt - Railway: Direct deployment from GitHub
- DigitalOcean App Platform: Configure from the dashboard
- AWS/Google Cloud: Deploy using your preferred method
- Set
DEBUG=Falsein production - Configure
ALLOWED_HOSTSwith your domain - Set up production database (PostgreSQL recommended)
- Configure static file serving (WhiteNoise or CDN)
- Set production webhook secret from Stripe Dashboard
- Enable HTTPS
- Set up environment variables on your platform
- accounts: User registration, authentication, and profiles
- shop: Product catalog, categories, and product details
- cart: Shopping cart session management
- orders: Order creation and Stripe payment processing
Access the Django admin at http://127.0.0.1:8000/admin/ to manage:
- Products and categories
- Orders and order items
- Users and permissions
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or run into issues, please open an issue on GitHub.
Made with β€οΈ by MocLG