Skip to content

Using django/django rest framework to design an API for an e-commerce store πŸ›’ with payment gateway integration πŸ’³

License

Notifications You must be signed in to change notification settings

Klvxn/ecommerce-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

e-commerce API

A RESTful API for an e-commerce platform that allows customers browse through products, add products to their shopping cart, place orders for those products and purchase them. The API comes with endpoints for managing orders, product reviews, authentication and authorization. It also supports pagination, filtering, etc.

Some features include

  1. JWT Authentication and authorization
  2. Optimized database queries
  3. Interactive Swagger documentation
  4. Braintree payment integration
  5. Debug toolbar and more...

Stack

  1. Python 3.10
  2. Django 4.1.2
  3. Django Rest Framework 3.14.0
  4. PostgreSQL 12

Setup

Clone the repository using the git command

git clone https://github.com/klvxn/ecommerce-API

Navigate into the project's root directory

cd ecommerce-API

Build the docker images

docker-compose build

Run the docker containers

docker-compose up

The API will be ready at: http://localhost:8000/

Access the documentation at: http://localhost:8000/swagger/

API Endpoints Overview

Here are some of the endpoints.
Assuming the local server is running at http://localhost:8000


Authentication

Create a user account

POST http://localhost:8000/api/v1/customers/

REQUEST BODY
    {
        "email": "[email protected]",
        "first_name": "Django",
        "last_name": "Admin",
        "date_of_birth": "2022-10-15",
        "password": "djangorest",
        "password2": "djangorest"
    }

Create access token

POST http://localhost:8000/auth/token/

REQUEST BODY 
    {
        "email": "[email protected]",
        "password": "djangorest"
    }

Logout user

POST http://localhost:8000/auth/logout/

Refresh access token

POST http://localhost:8000/auth/token/refresh/

REQUEST BODY 

    {"refresh": "your_refresh_token"}

Products Endpoints

Retrieve all products or a single product

GET http://localhost:8000/api/v1/products/


GET http://localhost:8000/api/v1/products/{id}

Add a product with Id to cart

POST http://localhost:8000/api/v1/products/{Id}/add/

REQUEST BODY

    {"quantity": 3}

Remove a product from cart

DELETE http://localhost:8000/api/v1/products/{Id}/delete/

Shopping Cart Endpoints

Retrieve items in shopping cart

GET http://localhost:8000/api/v1/shopping-cart/

Create an order from user's cart items

POST http://localhost:8000/api/v1/shopping-cart/

REQUEST BODY

    {"action": "create_order"}

Update an item in cart

PUT http://localhost:8000/api/v1/shopping-cart/

REQUEST BODY 

    {"product_name": 7}

Remove an item from cart
if request body is empty, cart will be cleared.

DELETE http://localhost:8000/api/v1/cart/

REQUEST BODY    

    {"product_name": ""}

Orders Endpoints

Retrieve all orders or a single order

GET http://localhost:8000/api/v1/orders/

GET http://localhost:8000/api/v1/orders/{id}

Update an order with a new address

PUT http://localhost:8000/api/v1/orders/{id}/

REQUEST BODY
    {
        "street_address": "Somewhere you live",
        "postal_code": 012345,
        "city": "New Genius",
        "state": "Your state",
        "country": "Your country",
    }

Delete an order

DELETE http://localhost:8000/api/v1/orders/{id}/

Payment Endpoints

Retrieve the template to input payment method details

GET http://localhost:8000/api/v1/checkout/order/{id}/

Process payment for an order

POST http://localhost:8000/api/v1/checkout/order/{id}/make-payment/

REQUEST BODY
    {  
        5555 5555 5555 4444 
        02/24
    }

Paid orders are exported to a csv file. If you get an error (e.g. processor declined) while testing payments, check the Braintree docs

(Un)Successful payments in Braintree dashboard


Schema

http://localhost:8000/api/v1/openapi/

Docs

The documentation for the API and the rest of it's endpoints are available at:

http://localhost:8000/swagger/

Swagger Documentation


License

This project is licensed under the MIT License - see the LICENSE file for details.


Support

If you have any questions or issues with the API, please contact me at [email protected].

About

Using django/django rest framework to design an API for an e-commerce store πŸ›’ with payment gateway integration πŸ’³

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages