Add cálculo de trial y badge de plan
This commit is contained in:
19
mvp/b2c/src/lib/billing/plan.ts
Normal file
19
mvp/b2c/src/lib/billing/plan.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export function trialDaysRemaining(trialEndsAt: Date | null, now: Date = new Date()): number {
|
||||
if (!trialEndsAt) return 0;
|
||||
const ms = trialEndsAt.getTime() - now.getTime();
|
||||
if (ms <= 0) return 0;
|
||||
return Math.ceil(ms / (24 * 60 * 60 * 1000));
|
||||
}
|
||||
|
||||
export function formatPlanBadge(
|
||||
planNombre: string | null,
|
||||
status: string,
|
||||
trialEndsAt: Date | null,
|
||||
now: Date = new Date()
|
||||
): string {
|
||||
const plan = planNombre ? `Plan ${planNombre}` : 'Sin plan';
|
||||
if (status === 'trial') {
|
||||
return `${plan} · trial, ${trialDaysRemaining(trialEndsAt, now)} días restantes`;
|
||||
}
|
||||
return `${plan} · ${status}`;
|
||||
}
|
||||
Reference in New Issue
Block a user