INNER CODE UNIT · Python
create_checkout_session
liyupi/free-video-downloader · backend/api_payment.py:47
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)
if not plan:
raise HTTPException(status_code=400, detail="无效的套餐类型")
stripe.api_key = secret_key
order_no = _generate_order_no(user["id"])
create_order(