- Backend: FastAPI app with all models, services, schemas, routes - Admin Panel: Next.js dashboard with all modules (CRM, POS, repairs, warranties, billing, notifications, etc.) - Ecommerce: storefront (submodule) + product catalog - AI Agents: .agents/ skill library for Antigravity IDE - Docs: architecture, billing, notification gateway markdown - Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""
|
|
@router CheckoutRouter (Backend/app/api/v1/routers/CheckoutRouter.py)
|
|
@purpose Database-driven customer checkout pipeline delegating to unified OrderService.
|
|
"""
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from pydantic import BaseModel
|
|
from typing import Optional
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database.db_session import get_db
|
|
from app.api.v1.routers.CustomerProfileRouter import get_current_customer
|
|
from app.models.EcomCustomerModel import EcomCustomer
|
|
from app.services.OrderService import OrderService
|
|
|
|
router = APIRouter(prefix="/api/v1/checkout", tags=["Checkout Engine"])
|
|
|
|
class CheckoutCreateRequest(BaseModel):
|
|
address_id: str
|
|
payment_method: str = "RAZORPAY"
|
|
coupon_code: Optional[str] = None
|
|
use_wallet_credits: bool = False
|
|
|
|
@router.post("/create")
|
|
def create_checkout_order(
|
|
payload: CheckoutCreateRequest,
|
|
customer: EcomCustomer = Depends(get_current_customer),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
"""
|
|
Validate cart item stock, register checkout order reservation, and empty the customer's cart.
|
|
Enforces online payments (rejects COD).
|
|
"""
|
|
if payload.payment_method and payload.payment_method.strip().upper() == "COD":
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="Cash on Delivery (COD) is not supported. Please complete your payment online."
|
|
)
|
|
|
|
return OrderService.create_ecommerce_order(
|
|
db=db,
|
|
customer=customer,
|
|
address_id=payload.address_id,
|
|
payment_method=payload.payment_method or "RAZORPAY",
|
|
use_wallet_credits=payload.use_wallet_credits
|
|
)
|