From 24e52d6ead4fed43daa52451daa33517cbecfb13 Mon Sep 17 00:00:00 2001 From: chenhang Date: Tue, 23 Jun 2026 15:47:09 +0800 Subject: [PATCH] fix(payment): support updated plan pricing fields --- src/app/subscription/subscription-screen.tsx | 17 ++++++++++++----- src/data/dto/payment/payment_plan.ts | 2 ++ src/data/schemas/payment/payment_plan.ts | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/app/subscription/subscription-screen.tsx b/src/app/subscription/subscription-screen.tsx index 67bdf790..ba2179f4 100644 --- a/src/app/subscription/subscription-screen.tsx +++ b/src/app/subscription/subscription-screen.tsx @@ -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), }; diff --git a/src/data/dto/payment/payment_plan.ts b/src/data/dto/payment/payment_plan.ts index d5f933c1..76a62641 100644 --- a/src/data/dto/payment/payment_plan.ts +++ b/src/data/dto/payment/payment_plan.ts @@ -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; diff --git a/src/data/schemas/payment/payment_plan.ts b/src/data/schemas/payment/payment_plan.ts index 249e51f3..6bbd2c72 100644 --- a/src/data/schemas/payment/payment_plan.ts +++ b/src/data/schemas/payment/payment_plan.ts @@ -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,