INNER CODE UNIT · Python
_generate_order_no
liyupi/free-video-downloader · backend/api_payment.py:40
def _generate_order_no(user_id: int) -> str:
ts = datetime.now(timezone.utc).strftime("%Y%m%d%H%M%S")
short_uuid = uuid.uuid4().hex[:8]
return f"SA{ts}{user_id:04d}{short_uuid}"
@router.post("/create-checkout")
async def create_checkout_session(req: CreateCheckoutRequest, user: dict = Depends(get_current_user)):
secret_key = _get_config("STRIPE_SECRET_KEY")
price_id = _get_config("STRIPE_PRICE_ID_MONTHLY")
frontend_url = _get_config("FRONTEND_URL", "http://localhost:5173")
if not secret_key:
raise HTTPException(status_code=500, detail="支付服务未配置,请设置 STRIPE_SECRET_KEY")
if not price_id:
raise HTTPException(status_code=500, detail="套餐价格未配置,请设置 STRIPE_PRICE_ID_MONTHLY")
plan = PLANS.get(req.plan_type)