fix(payment): support updated plan pricing fields
This commit is contained in:
@@ -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),
|
||||
};
|
||||
|
||||
@@ -12,6 +12,8 @@ export class PaymentPlan {
|
||||
declare readonly planName: string;
|
||||
declare readonly orderType: string;
|
||||
declare readonly amountCents: number;
|
||||
declare readonly originalAmountCents: number | null;
|
||||
declare readonly dailyPriceCents: number | null;
|
||||
declare readonly currency: string;
|
||||
declare readonly vipDays: number | null;
|
||||
declare readonly dolAmount: number | null;
|
||||
|
||||
@@ -8,6 +8,8 @@ const PaymentPlanWireSchema = z.object({
|
||||
plan_name: z.string(),
|
||||
order_type: z.string(),
|
||||
amount_cents: z.number(),
|
||||
original_amount_cents: z.number().nullable().default(null),
|
||||
daily_price_cents: z.number().nullable().default(null),
|
||||
currency: z.string(),
|
||||
vip_days: z.number().nullable(),
|
||||
dol_amount: z.number().nullable(),
|
||||
@@ -23,6 +25,8 @@ export const PaymentPlanSchema = z
|
||||
plan_name: data.planName,
|
||||
order_type: data.orderType,
|
||||
amount_cents: data.amountCents,
|
||||
original_amount_cents: data.originalAmountCents,
|
||||
daily_price_cents: data.dailyPriceCents,
|
||||
currency: data.currency,
|
||||
vip_days: data.vipDays,
|
||||
dol_amount: data.dolAmount,
|
||||
@@ -35,6 +39,8 @@ export const PaymentPlanSchema = z
|
||||
planName: data.plan_name,
|
||||
orderType: data.order_type,
|
||||
amountCents: data.amount_cents,
|
||||
originalAmountCents: data.original_amount_cents,
|
||||
dailyPriceCents: data.daily_price_cents,
|
||||
currency: data.currency,
|
||||
vipDays: data.vip_days,
|
||||
dolAmount: data.dol_amount,
|
||||
|
||||
Reference in New Issue
Block a user