Skip to content

Checkout API Documentation

Endpoints Overview

This documentation outlines the available endpoints for managing coupons, coupon claims, applied coupons, purchased products, and cart item purchases.


Coupon Code ViewSet

GET /coupon-codes/

  • Endpoint: api/v1/checkout/coupon/code/
  • Description: Retrieve a list of active coupon codes.
  • Permissions: AllowAny
  • Queryset: Filters active coupons based on the current date.
  • Pagination: CustomPagination

Response:

[
    {
            "id": 67,
            "code": "SHOP100",
            "description": "asdasd",
            "discount_percent": "0.00",
            "money_value_off": "100.00",
            "total_issues": 10,
            "coupon_limit_per_customer": 50,
            "used_count": 10,
            "total_used": 6,
            "start_at": "03-10-2025 03:43:38",
            "end_at": "03-31-2025 03:43:40",
            "min_purchase": "50.00",
            "is_active": true,
            "shop": null,
            "is_global": true,
            "created_at": "2025-03-10 03:43:47",
            "updated_at": "2025-03-10 06:46:14",
            "total_claim_left": 9,
            "is_claimed": true
        }
]


Coupon Claim ViewSet

GET /coupon-claims/

  • Endpoint: api/v1/checkout/coupon/claim/
  • Description: Retrieve all claimed coupons by the user.
  • Permissions: IsAuthenticated
  • Pagination: CustomPagination

POST /coupon-claims/

  • Description: Claim a new coupon.
  • Request Body:
    {
        "code": "SUMMER20"
    }
    
  • Response:
    {
        "id": 10,
        "code": "SUMMER20",
        "user": "user@example.com",
        "is_claimed": true,
        "claimed_at": "2024-12-09T12:34:56Z"
    }
    

Apply Coupon ViewSet

GET /apply-coupons/

  • Endpoint: api/v1/checkout/coupon/apply/
  • Description: Retrieve all applied coupons by the user.
  • Permissions: IsAuthenticated
  • Pagination: CustomPagination

POST /apply-coupons/

  • Description: Apply a claimed coupon to a purchase.
  • Request Body:
    {
        "coupon_code": "SUMMER20",
        "total_purchased": 150
    }
    
  • Response:
    {
        "id": 5,
        "user": "user@example.com",
        "total_purchased": 150,
        "discounted_amount": 30,
        "net_amount": 120,
        "has_applied": true,
        "applied_at": "2024-12-09T12:45:00Z"
    }
    

Product Purchased ViewSet

GET /product-purchases/

  • Endpoint: api/v1/checkout/product/purchased/
  • Description: Retrieve a list of products marked for purchase.
  • Permissions: IsAuthenticated
  • Pagination: CustomPagination

POST /product-purchases/

  • Description: Add a product to the purchased list.
  • Request Body:
    {
        "applied_coupon": 5,
        "total_purchased": 150
    }
    
  • Response:
    {
        "id": 3,
        "user": "user@example.com",
        "total_purchased": 150,
        "discounted_amount": 30,
        "net_amount": 120,
        "has_purchased_succeed": false,
        "purchased_at": null
    }
    

Purchased Cart Item ViewSet

GET /purchased-cart-items/

  • Endpoint: api/v1/checkout/purchased/cart/item/
  • Description: Retrieve purchased cart items.
  • Permissions: IsAuthenticated
  • Pagination: CustomPagination

POST /purchased-cart-items/

  • Description: Mark cart items as purchased.
  • Request Body:
    {
        "purchased_product": 3,
        "cart_items": [1, 2, 3],
        "status": true
    }
    
  • Response:
    {
        "purchased_items": [
            {
                "id": 7,
                "purchased_product": 3,
                "cart_item": 1,
                "status": true
            }
        ],
        "unavailable_items": [
            "Product A"
        ]
    }
    

Notes

  • Ensure that stock levels are checked before marking cart items as purchased.
  • The PurchasedCartItem serializer validates stock availability and assigns the purchase status accordingly.

Error Handling

  • All endpoints return validation errors in the format:
    {
        "detail": "Error message here."
    }