feat: 新增后端支付模块,支持微信和支付宝
- 新增api/payment/支付服务(微信、支付宝) - 新增api/routers/payment.py支付路由 - 更新database/models.py支付相关模型 - 新增数据库迁移文件(订单表、用户订阅字段) - 更新main.py、requirements.txt、.env.production Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
85
api/payment/schemas.py
Normal file
85
api/payment/schemas.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
支付模块 Pydantic 模型定义
|
||||
"""
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
class PaymentResult(BaseModel):
|
||||
"""创建支付订单的返回结果"""
|
||||
success: bool
|
||||
payment_method: str # wechat / alipay
|
||||
out_trade_no: str # 内部订单号
|
||||
|
||||
# 微信支付参数(APP 调起支付所需)
|
||||
wechat_params: Optional[Dict[str, str]] = None
|
||||
# 支付宝 order_string(APP 调起支付所需)
|
||||
alipay_order_string: Optional[str] = None
|
||||
|
||||
error_message: Optional[str] = None
|
||||
|
||||
|
||||
class NotifyResult(BaseModel):
|
||||
"""支付回调通知处理结果"""
|
||||
success: bool
|
||||
out_trade_no: Optional[str] = None # 内部订单号
|
||||
trade_no: Optional[str] = None # 第三方交易号
|
||||
total_amount: Optional[int] = None # 金额(分)
|
||||
trade_status: Optional[str] = None # 交易状态
|
||||
error_message: Optional[str] = None
|
||||
|
||||
|
||||
class PaymentStatus(BaseModel):
|
||||
"""查询支付状态的返回结果"""
|
||||
success: bool
|
||||
out_trade_no: str
|
||||
trade_no: Optional[str] = None
|
||||
trade_status: str # SUCCESS / NOTPAY / CLOSED / REFUND / PAYERROR
|
||||
total_amount: Optional[int] = None
|
||||
error_message: Optional[str] = None
|
||||
|
||||
|
||||
# === API 请求/响应模型 ===
|
||||
|
||||
class CreateOrderRequest(BaseModel):
|
||||
"""创建订单请求"""
|
||||
plan_id: str # 套餐 ID
|
||||
payment_method: str # wechat / alipay
|
||||
|
||||
|
||||
class CreateOrderResponse(BaseModel):
|
||||
"""创建订单响应"""
|
||||
order_id: str # 内部订单号
|
||||
payment_method: str # 支付方式
|
||||
|
||||
# 微信支付调起参数
|
||||
wechat_params: Optional[Dict[str, str]] = None
|
||||
# 支付宝 order string
|
||||
alipay_order_string: Optional[str] = None
|
||||
|
||||
|
||||
class OrderStatusResponse(BaseModel):
|
||||
"""订单状态查询响应"""
|
||||
order_id: str
|
||||
plan_id: str
|
||||
plan_name: str
|
||||
amount: int # 金额(分)
|
||||
currency: str
|
||||
payment_method: str
|
||||
status: str # pending / paid / failed / cancelled / refunded
|
||||
trade_no: Optional[str] = None
|
||||
created_at: str
|
||||
paid_at: Optional[str] = None
|
||||
|
||||
|
||||
class OrderListResponse(BaseModel):
|
||||
"""订单列表项"""
|
||||
id: str
|
||||
plan_id: str
|
||||
plan_name: str
|
||||
amount: int
|
||||
currency: str
|
||||
status: str
|
||||
payment_method: str
|
||||
created_at: str
|
||||
paid_at: Optional[str] = None
|
||||
Reference in New Issue
Block a user