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} `;
}
function formatAmount(amountCents: number): string {
function formatAmount(amountCents: number | null): string | null {
if (amountCents === null) return null;
return (amountCents / 100).toFixed(2).replace(/\.00$/, "");
}
@@ -91,9 +92,15 @@ function planCaption(
? "Voice package"
: `${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";
const perDay = plan.amountCents / 100 / Math.max(plan.vipDays, 1);
return `${currencySymbol(plan.currency)}${perDay.toFixed(2)}/day`;
const fallbackDailyPrice = plan.amountCents / Math.max(plan.vipDays, 1);
return `${currencySymbol(plan.currency)}${formatAmount(fallbackDailyPrice)}/day`;
}
function toPlanView(
@@ -103,8 +110,8 @@ function toPlanView(
return {
id: plan.planId,
name: plan.planName,
price: formatAmount(plan.amountCents),
originalPrice: null,
price: formatAmount(plan.amountCents) ?? "",
originalPrice: formatAmount(plan.originalAmountCents),
perDay: planCaption(plan, subscriptionType),
currencySymbol: currencySymbol(plan.currency),
};