23a31f7c00
- Add silent WeChat login for MP/browser environments - Fix Python 3.6 compatibility (remove typing.Annotated usage) - Marketing page: tab-based content generation with category support - Translate page: add auto-detect language default - Homepage: add TTS playback, announcement ticker, remove redundant quick-actions - Fix FAB button overlap with custom tabbar on customers/quotation pages - Make openai/anthropic imports lazy for Python 3.6 compat
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from pydantic import BaseModel
|
|
from app.database import get_db
|
|
from app.services.payment import PaymentService
|
|
from app.api.v1.deps import get_current_user_id
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class CreateOrderRequest(BaseModel):
|
|
plan: str
|
|
|
|
|
|
class PaymentCallbackRequest(BaseModel):
|
|
payment_id: str
|
|
success: bool
|
|
|
|
|
|
@router.get("/plans")
|
|
async def get_plans():
|
|
svc = PaymentService(None)
|
|
return await svc.get_plans()
|
|
|
|
|
|
@router.get("/subscription")
|
|
async def get_subscription(
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
svc = PaymentService(db)
|
|
return await svc.get_current_subscription(user_id)
|
|
|
|
|
|
@router.post("/create-order")
|
|
async def create_order(
|
|
data: CreateOrderRequest,
|
|
user_id: str = Depends(get_current_user_id),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
svc = PaymentService(db)
|
|
try:
|
|
return await svc.create_order(user_id, data.plan)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
|
|
@router.post("/callback")
|
|
async def payment_callback(
|
|
data: PaymentCallbackRequest,
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
svc = PaymentService(db)
|
|
success = await svc.handle_payment_callback(data.payment_id, data.success)
|
|
if not success:
|
|
raise HTTPException(status_code=404, detail="Order not found")
|
|
return {"status": "ok"} |