feat(payment): implement first recharge offer functionality and UI updates
This commit is contained in:
+32
-32
@@ -1,34 +1,34 @@
|
||||
GET https://proapi.banlv-ai.com/api/payment/plans
|
||||
结果:
|
||||
status=200
|
||||
success=true
|
||||
plans 数量 8
|
||||
VIP 套餐 3 个
|
||||
credits 套餐 5 个
|
||||
snake_keys=[],已经没有 plan_id / amount_cents 这种字段
|
||||
schema 校验通过:proapi_plans_camel_schema_ok true
|
||||
前端按这个结构用:
|
||||
type PaymentPlan = {
|
||||
planId: string;
|
||||
planName: string;
|
||||
orderType: 'vip_monthly' | 'vip_quarterly' | 'vip_annual' | 'dol';
|
||||
vipDays: number | null;
|
||||
dolAmount: number | null;
|
||||
creditBalance: number;
|
||||
amountCents: number;
|
||||
originalAmountCents: number | null;
|
||||
dailyPriceCents: number | null;
|
||||
currency: string;
|
||||
};
|
||||
分组:
|
||||
const plans = res.data.plans;
|
||||
|
||||
const vipPlans = plans.filter(p => p.vipDays !== null);
|
||||
const creditPlans = plans.filter(p => p.dolAmount !== null);
|
||||
下单仍然传 planId:
|
||||
有更新,主要是 /api/payment/plans。
|
||||
前端判断方式:
|
||||
调用:
|
||||
GET /api/payment/plans
|
||||
如果用户已登录,请带上:
|
||||
Authorization: Bearer <token>
|
||||
后端会返回:
|
||||
{
|
||||
"planId": "vip_monthly",
|
||||
"payChannel": "stripe",
|
||||
"autoRenew": true
|
||||
"isFirstRecharge": true,
|
||||
"firstRechargeOffer": {
|
||||
"enabled": true,
|
||||
"type": "first_recharge_half_price",
|
||||
"discountPercent": 50
|
||||
},
|
||||
"plans": [
|
||||
{
|
||||
"planId": "vip_monthly",
|
||||
"amountCents": 995,
|
||||
"originalAmountCents": 1990,
|
||||
"isFirstRechargeOffer": true,
|
||||
"firstRechargeDiscountPercent": 50,
|
||||
"promotionType": "first_recharge_half_price"
|
||||
}
|
||||
]
|
||||
}
|
||||
价格、币种全部以前端拿到的 amountCents / currency 展示,不要写死。当前我这边访问 pro 返回的是 JPY,这是 Cloudflare 根据访问 IP 判的国家币种。
|
||||
前端逻辑很简单:
|
||||
data.isFirstRecharge === true 或 plan.isFirstRechargeOffer === true:展示首充价
|
||||
amountCents:实际支付价,也就是首充半价
|
||||
originalAmountCents:划线原价
|
||||
firstRechargeDiscountPercent:折扣,比如 50
|
||||
不需要前端自己算半价
|
||||
创建订单还是原接口:
|
||||
POST /api/payment/create-order
|
||||
前端只传原来的 planId/payChannel/autoRenew,不用传首充字段。后端会重新判断首充资格,并按半价创建订单,防止前端伪造价格。
|
||||
Reference in New Issue
Block a user