Skip to content

Flask-based RESTful E-commerce API with Stripe payment integration. Built using Flask, SQLAlchemy, and JWT authentication, featuring user registration, product browsing, cart management, secure checkout, and an admin panel for inventory and product control.

Notifications You must be signed in to change notification settings

Simply-Blessing/Ecommerce-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask E-Commerce API

This project is a RESTful e-commerce backend built with Flask, SQLAlchemy, JWT, and Stripe.

It supports:

  • User authentication
  • Product browsing and search
  • Shopping cart management
  • Stripe checkout and payment handling
  • Admin-only product and inventory management

Features

User Features

  • Register and log in
  • View and search products
  • Add products to cart
  • Remove products from cart
  • View final cart summary
  • Checkout and pay using Stripe

Admin Features

(Admin access controlled via is_admin flag and JWT)

  • Add products
  • Update product details
  • Delete products
  • View inventory
  • View low-stock products

Tech Stack

  • Python 3.10+
  • Flask
  • Flask-SQLAlchemy
  • Flask-JWT-Extended
  • Stripe API
  • SQLite (development)
  • Pytest (testing)

Environment Variables

  • Clone the repository:
git clone https://github.com/Simply-Blessing/Ecommerce-API.git
cd Blogging-API
  • Create a .env file:
SECRET_KEY=sk_test_xxx

Running the App

python main.py

The server runs on:

http://127.0.0.1:5000

Running Tests

Install dependencies:

pip install pytest pytest-flask

Install packages:

requirements

Run test:

Run test:

pytest

API Endpoints

Admin registration

  • Admin is manually added once in python shell
python
from main import app, Users
with app.app_context():
    print(Users.query.filter_by(username="yourusername").first().is_admin)
# output
# True
exit()
  • Admin login
curl -X POST http://127.0.0.1:5000/login \
-H "Content-Type: application/json" \
-d '{
  "username": "yourusername",
  "password": "yourpassword"
}'
  • Save the admin token
ADMIN_TOKEN = "Admin_token"
  • Add products
curl -X POST http://127.0.0.1:5000/admin/products \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"product_name":"Laptop","amount":10,"price":999.99,"currency":"USD"}'
  • View inventory
curl -X GET http://127.0.0.1:5000/admin/products \
-H "Authorization: Bearer $ADMIN_TOKEN"

User panel

  • Register, login and save token
  • View and search products
# view
curl http://127.0.0.1:5000/products
# search
curl "http://127.0.0.1:5000/products?search=laptop"
  • Add products to cart
curl -X POST http://127.0.0.1:5000/cart \
-H "Authorization: Bearer $USER_TOKEN" \
-H "Content-Type: application/json" \
-d '{"product_id":1,"quantity":1}'
  • View the cart before checkout
curl -X GET http://127.0.0.1:5000/carts/final \
-H "Authorization: Bearer $USER_TOKEN"
  • Checkout using Stripe
curl -X POST http://127.0.0.1:5000/checkout \
-H "Authorization: Bearer $USER_TOKEN"
# you will get a Stripe Checkout URL that you can follow to complete the purchase

Authentication

  • JWT tokens are returned on login/register.

  • Use them in requests:

Authorization: Bearer <access_token>

Admin Access

  • To make a user admin:

    • Set is_admin = True in the database for that user
  • Admin routes are prefixed with /admin/*.


Notes

  • Stripe payments are finalized via webhooks
  • Inventory is updated only after successful payment
  • This project uses SQLite for simplicity

Project Inspiration

E-commerce API

About

Flask-based RESTful E-commerce API with Stripe payment integration. Built using Flask, SQLAlchemy, and JWT authentication, featuring user registration, product browsing, cart management, secure checkout, and an admin panel for inventory and product control.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages