fix(payment): support updated plan pricing fields

This commit is contained in:
2026-06-23 15:47:09 +08:00
parent c5eca65303
commit 24e52d6ead
3 changed files with 20 additions and 5 deletions
+12 -5
View File
@@ -78,7 +78,8 @@ function currencySymbol(currency: string): string {
return `${currency} `; return `${currency} `;
} }
function formatAmount(amountCents: number): string { function formatAmount(amountCents: number | null): string | null {
if (amountCents === null) return null;
return (amountCents / 100).toFixed(2).replace(/\.00$/, ""); return (amountCents / 100).toFixed(2).replace(/\.00$/, "");
} }
@@ -91,9 +92,15 @@ function planCaption(
? "Voice package" ? "Voice package"
: `${plan.dolAmount} voice messages`; : `${plan.dolAmount} voice messages`;
} }
if (plan.dailyPriceCents !== null) {
const dailyPrice = formatAmount(plan.dailyPriceCents);
return dailyPrice === null
? "Lifetime"
: `${currencySymbol(plan.currency)}${dailyPrice}/day`;
}
if (plan.vipDays === null) return "Lifetime"; if (plan.vipDays === null) return "Lifetime";
const perDay = plan.amountCents / 100 / Math.max(plan.vipDays, 1); const fallbackDailyPrice = plan.amountCents / Math.max(plan.vipDays, 1);
return `${currencySymbol(plan.currency)}${perDay.toFixed(2)}/day`; return `${currencySymbol(plan.currency)}${formatAmount(fallbackDailyPrice)}/day`;
} }
function toPlanView( function toPlanView(
@@ -103,8 +110,8 @@ function toPlanView(
return { return {
id: plan.planId, id: plan.planId,
name: plan.planName, name: plan.planName,
price: formatAmount(plan.amountCents), price: formatAmount(plan.amountCents) ?? "",
originalPrice: null, originalPrice: formatAmount(plan.originalAmountCents),
perDay: planCaption(plan, subscriptionType), perDay: planCaption(plan, subscriptionType),
currencySymbol: currencySymbol(plan.currency), currencySymbol: currencySymbol(plan.currency),
}; };
+2
View File
@@ -12,6 +12,8 @@ export class PaymentPlan {
declare readonly planName: string; declare readonly planName: string;
declare readonly orderType: string; declare readonly orderType: string;
declare readonly amountCents: number; declare readonly amountCents: number;
declare readonly originalAmountCents: number | null;
declare readonly dailyPriceCents: number | null;
declare readonly currency: string; declare readonly currency: string;
declare readonly vipDays: number | null; declare readonly vipDays: number | null;
declare readonly dolAmount: number | null; declare readonly dolAmount: number | null;
+6
View File
@@ -8,6 +8,8 @@ const PaymentPlanWireSchema = z.object({
plan_name: z.string(), plan_name: z.string(),
order_type: z.string(), order_type: z.string(),
amount_cents: z.number(), amount_cents: z.number(),
original_amount_cents: z.number().nullable().default(null),
daily_price_cents: z.number().nullable().default(null),
currency: z.string(), currency: z.string(),
vip_days: z.number().nullable(), vip_days: z.number().nullable(),
dol_amount: z.number().nullable(), dol_amount: z.number().nullable(),
@@ -23,6 +25,8 @@ export const PaymentPlanSchema = z
plan_name: data.planName, plan_name: data.planName,
order_type: data.orderType, order_type: data.orderType,
amount_cents: data.amountCents, amount_cents: data.amountCents,
original_amount_cents: data.originalAmountCents,
daily_price_cents: data.dailyPriceCents,
currency: data.currency, currency: data.currency,
vip_days: data.vipDays, vip_days: data.vipDays,
dol_amount: data.dolAmount, dol_amount: data.dolAmount,
@@ -35,6 +39,8 @@ export const PaymentPlanSchema = z
planName: data.plan_name, planName: data.plan_name,
orderType: data.order_type, orderType: data.order_type,
amountCents: data.amount_cents, amountCents: data.amount_cents,
originalAmountCents: data.original_amount_cents,
dailyPriceCents: data.daily_price_cents,
currency: data.currency, currency: data.currency,
vipDays: data.vip_days, vipDays: data.vip_days,
dolAmount: data.dol_amount, dolAmount: data.dol_amount,