ifixkart-backend/app/api/v1/routers/CheckoutRouter.py
adithiyan 10bfba7d58 feat: add warranties, refunds, notifications, CRM calendar, system config & delivery modules
- New models: WarrantyModel, WalletModel, SystemConfigModel
- New schemas: WarrantySchema, RefundSchema, SystemConfig, CrmTaskCalendar, NotificationTemplate, NotificationGateway, RepairErp, ReviewModeration, InventoryPos, MultiDashboard, BillingFinance
- New services: WarrantyService, RefundService, CrmService, CrmTaskCalendarService, DeliveryService, EmailTemplateService, InventoryPosService, MultiDashboardService, NotificationGatewayService, RepairErpService, ReviewModerationService, SystemConfigService, TemplateService, CreditService
- Updated routers: AdminOrder, BillingFinance, Cart, Catalog, Checkout, Crm, InventoryPos, NotificationGateway, RolePermission, ServiceJob, Settings, Storefront, UserCreation
- Updated models: Inventory, Notification, Order, Product, Service, Setting, SystemConfig, User
- Updated core: database init, invoice generator, main app
- Added WarrantyRouter with full CRUD and claim flow
2026-10-13 22:05:16 +05:30

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
)