apps/server/docs/ai-context/stripe-pricing.md
Stripe 是 Flux 充值定价的单一真相源。服务端不再在 Redis 维护 FLUX_PACKAGES,所有 package 信息直接从 Stripe API 获取。
之前的设计在 Redis ConfigKV 中维护 FLUX_PACKAGES(含 amount、label、price 等),导致:
现在只需在 Stripe Dashboard 操作 Product/Price,服务端自动同步。
unit_amount + currency(如 300 USD = $3)currency_options(可选)— 支持多币种展示,如 cny: { unit_amount: 2200 }metadata.fluxAmount — 购买此 Price 获得的 Flux 数量metadata.recommended — (可选)设为 'true' 时前端会高亮展示为推荐套餐Product ID 存储在 ConfigKV STRIPE_FLUX_PRODUCT_ID 中(运营配置,非环境变量)。
通过 Stripe Price 的 currency_options 实现。一个 USD Price 可以同时支持 CNY 结算:
currency_options 自动提取),用户通过 SelectTab 切换{ stripePriceId, currency } 给服务端currency 参数,Stripe 自动用对应 currency_options 的金额创建带多币种的 Price:
curl https://api.stripe.com/v1/prices \
-u "$STRIPE_API_KEY:" \
-d "product=prod_xxx" \
-d "unit_amount=300" \
-d "currency=usd" \
-d "metadata[fluxAmount]=500" \
-d "currency_options[cny][unit_amount]=2200"
注意:Stripe CLI 的
prices create对嵌套参数支持不好,currency_options需要用curl直接调 API。
STRIPE_PAYMENT_METHODS 在 ConfigKV 中为可选配置:
payment_method_types,Stripe 根据 Dashboard 设置和货币自动决定["card", "wechat_pay", "alipay"]如果手动指定了 wechat_pay,还需设 STRIPE_PAYMENT_METHOD_OPTIONS 为 {"wechat_pay":{"client":"web"}}。
Stripe Price 列表通过 Redis 缓存(key: cache:stripe:prices,TTL 5 分钟),所有实例共享。
prices.list (含 expand: ['data.currency_options']),按 unit_amount 升序排列后写入缓存prices.retrieve 并 invalidate 缓存STRIPE_FLUX_PRODUCT_ID{
"stripePriceId": "price_xxx",
"label": "500 Flux",
"defaultCurrency": "usd",
"currencies": { "usd": "$3.00", "cny": "¥22.00" },
"recommended": false
}
{ stripePriceId, currency? }fluxAmount metadatacurrency 参数(如有)让 Stripe 用 currency_options 中的金额payment_method_types 根据 ConfigKV 是否配置决定传或不传checkout.session.completed 后从 metadata 读取 fluxAmount 充值用 curl 创建带多币种的 Price(Stripe CLI 不支持嵌套参数):
curl https://api.stripe.com/v1/prices \
-u "$STRIPE_API_KEY:" \
-d "product=prod_xxx" \
-d "unit_amount=1200" \
-d "currency=usd" \
-d "metadata[fluxAmount]=2000" \
-d "metadata[recommended]=true" \
-d "currency_options[cny][unit_amount]=8800"
无需修改代码或 Redis,/packages 端点在缓存过期后自动返回新 Price。
在 Stripe Dashboard 将 Price 设为 inactive,缓存过期后 /packages 自动不再返回。
redis-cli SET "config:STRIPE_FLUX_PRODUCT_ID" '"prod_new_id"'
redis-cli DEL "cache:stripe:prices"
| Key | 类型 | 默认 | 说明 |
|---|---|---|---|
STRIPE_FLUX_PRODUCT_ID | string? | 无 | Stripe Product ID,未设置时 top-up 不可用 |
STRIPE_PAYMENT_METHODS | string[]? | 无 | 不设则 Stripe 自动决定;设了则覆盖 |
STRIPE_PAYMENT_METHOD_OPTIONS | Record? | {} | 支付方式选项,如 {"wechat_pay":{"client":"web"}} |