Skip to content

A Django-based e-commerce app integrated with Paymob’s Accept checkout API for payments. Built as part of an introductory task in the Paymob internship.

Notifications You must be signed in to change notification settings

omaarsaaleh/django-paymob-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

Paymob Accept's Checkout API Integration with Django

A Django-based e-commerce app integrated with Paymob Accept's checkout API for payments. Built as part of the Paymob internship technical task.


Endpoints Overview

Auth Endpoints

Method Endpoint Description Permissions
POST /api/v1/token/ Obtain JWT access & refresh tokens AllowAny
POST /api/v1/token/refresh/ Refresh access token AllowAny

User Endpoints

Method Endpoint Description Permissions
POST /api/v1/register/ Register a new user AllowAny
GET /api/v1/profile/ Get current user profile Authenticated
PUT /api/v1/profile/ Update current user profile Authenticated

Products Endpoints

Method Endpoint Description Permissions
GET /api/v1/products/ List all products AllowAny
GET /api/v1/products/<id>/ Retrieve a product AllowAny
POST /api/v1/products/ Create a new product Admin Only
PUT/PATCH /api/v1/products/<id>/ Update a product Admin Only
DELETE /api/v1/products/<id>/ Soft delete a product (set is_deleted = true) Admin Only

Orders Endpoints

Method Endpoint Description Permissions
GET /api/v1/orders/ List all user orders Authenticated
GET /api/v1/orders/<id>/ Retrieve a order Authenticated
POST /api/v1/orders/ Create a new order Authenticated

Webhook Endpoint

Method Endpoint Description Permissions
POST /webhook/ Receives Paymob webhook callbacks for payment status Verifies HMAC

Payment Flow

Endpoint

POST /api/v1/orders/

Body Format

A list of cart items, each specifying the product_id and the desired quantity.

Example

{
  "cart_items": [
    { "product_id": 6, "quantity": 1 },
    { "product_id": 4, "quantity": 4 }
  ]
}

Process Overview

  1. Validation
    • Products must exist, be active (is_deleted = False), and have enough stock.
  2. Reservation
    • Stock is immediately deducted (hard reservation).
  3. Order Creation
    • Order is saved with pending status.

    • A Paymob payment intent is generated (10-minute expiry).

    • Response includes a payment_url:

      {
        "payment_url": "https://accept.paymob.com/unifiedcheckout/?publicKey=<...>&clientSecret=<...>"
      }

Payment Outcomes

  1. Success (Webhook)
    • Payment confirmed → order marked success.
  2. Failure (Webhook)
    • Payment failed → order marked failed, stock restored.
  3. Timeout
    • A scheduled task (via django-q) runs every 10 minutes.
    • Pending orders older than 10 minutes → marked timeout, stock restored.

About

A Django-based e-commerce app integrated with Paymob’s Accept checkout API for payments. Built as part of an introductory task in the Paymob internship.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages