From a5788a3d70a89b0a8a8a624977b779ac83bea1ff Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 11 Mar 2025 15:22:22 +0000 Subject: [PATCH] feat: Update endpoint checkout --- app/api/endpoints/checkout.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/api/endpoints/checkout.py b/app/api/endpoints/checkout.py index c42f42c..4f3f74d 100644 --- a/app/api/endpoints/checkout.py +++ b/app/api/endpoints/checkout.py @@ -1 +1,32 @@ -new route \ No newline at end of file +from fastapi import APIRouter, Depends +from sqlalchemy.orm import Session +from typing import Optional + +from app.db import get_db +from app.models import Payment +from app.schemas import PaymentCreate, PaymentResponse + +router = APIRouter() + +@router.post("/payment", response_model=PaymentResponse) +async def create_payment( + payment: PaymentCreate, + db: Session = Depends(get_db), + user_id: Optional[int] = None, +): + """ + Create a new payment record. + + Args: + payment (PaymentCreate): The payment data to create. + db (Session, optional): The database session. Defaults to Depends(get_db). + user_id (Optional[int], optional): The user ID associated with the payment. Defaults to None. + + Returns: + PaymentResponse: The created payment record. + """ + db_payment = Payment(**payment.dict(), user_id=user_id) + db.add(db_payment) + db.commit() + db.refresh(db_payment) + return db_payment \ No newline at end of file