A complete backend for an e-commerce app built with Django and DRF, supporting user auth, product & cart management, and checkout with stock validation.
Features:
- Token-based auth (register/login)
- Product and category CRUD with admin control
- Cart operations (add, update, remove)
- Order checkout with real-time stock update
- Admin panel management
APIs cover auth, products, cart, and orders with clear endpoints.
Easy to set up and extend for your own e-commerce projects.
- 🔐 Token-based authentication (Register & Login)
- 🛍️ Product and category management (CRUD)
- 🛒 Add to cart, update quantity, and remove items
- ✅ Checkout system with real-time stock update
- 🧾 Order creation with tracking
- 🧑💻 Admin panel support for managing all data
- Django
- Django REST Framework
- SQLite (you can switch to PostgreSQL/MySql)
- Token Authentication
Method | Endpoint | Description |
---|---|---|
POST | /api/token/ |
To get the jwt token |
POST | /api/toekn/refresh/ |
to refresh your token |
POST | /api/accounts/login/ |
to login |
POST | /api/accounts/register/ |
to register |
Method | Endpoint | Description |
---|---|---|
GET | /api/product/ |
List all products |
POST | /api/product/ |
Create a product (admin) |
GET | /api/product/{id}/ |
Retrieve product details |
PUT | /api/product/{id}/ |
Update product (admin) |
DELETE | /api/product/{id}/ |
Delete product (admin) |
Method | Endpoint | Description |
---|---|---|
GET | /api/cart/view_cart/ |
View user's cart |
POST | /api/cart/add_product_to_cart/ |
Add product to cart |
POST | /api/cart/update_quantity/ |
Update quantity in cart |
POST | /api/cart/remove_product/ |
Remove product from cart |
Method | Endpoint | Description |
---|---|---|
POST | /api/order/checkout/ |
Place order from cart |
- Clone the repo
- cd ecommere-backend
- Install requirements:
pip install -r requirements.txt
- Migrate DB:
python manage.py migrate
- Create superuser:
python manage.py createsuperuser
- Run server:
python manage.py runserver
How to get Stripe Secret Key
- Go to Stripe Dashboard and log in.
- Navigate to Developers > API keys.
- Copy your Secret Key under Standard keys.
- Keep it secret and use it in your project .env file.
How to get Stripe Webhook Signing Secret
- In Stripe Dashboard, go to Developers > Webhooks.
- Click Add endpoint and enter your webhook URL (e.g.,
https://yourdomain.com/api/stripe/webhook/
). - Select the events you want to listen to, like
checkout.session.completed
. - After saving, click on the webhook and copy the Signing Secret.
- Use this secret in your project to verify incoming webhook requests.
How to use Stripe CLI if you don't have a domain name
- Download and install Stripe CLI from the official site: https://stripe.com/docs/stripe-cli
- Login to Stripe CLI by running:
stripe login
- Forward webhook events to your local server by running:
stripe listen --forward-to localhost:8000/api/order/webhook/
- This will generate a webhook signing secret in the CLI output. Copy it and use it in your project settings.
- This will generate a webhook signing secret in the CLI output. It looks like this:
Ready! Your webhook signing secret is whsec_XXXXXXXXXXXXXXXXXXXXXXXXXXXX
- Now Stripe will forward webhook events to your local machine without needing a public domain.
Feel free to fork, modify and use this project as a base for your own e-commerce ideas!