feature plus ux rearrangements

This commit is contained in:
JCEEE
2026-08-22 19:49:46 +01:00
parent f14f4e2ac1
commit 42b9a27ce6
44 changed files with 2020 additions and 538 deletions
+16 -14
View File
@@ -28,17 +28,18 @@ export const PLAN_IDS: Record<'trial' | 'monthly' | 'yearly', string> = {
yearly: String(STRIPE_PRICE_YEARLY) || 'price_dummy_yearly'
};
// Trial codes (app-side). In practice these should live in a PB collection;
// for the dummy flow a static map is enough. Maps code -> trial days.
export const TRIAL_CODES: Record<string, number> = {
FAM3MONTHS: 90,
FAMTRIAL: 30
};
export function resolveTrialDays(code?: string): number | null {
// Trial codes live in PB (`accesscodes` with trialDays > 0, active) so the
// platform admin can manage them. A matching active code maps to Stripe
// trial_period_days at checkout; anything else is not a trial code.
export async function resolveTrialDays(code?: string): Promise<number | null> {
if (!code) return null;
const days = TRIAL_CODES[code.trim().toUpperCase()];
return typeof days === 'number' ? days : null;
const { pbAdmin } = await import('$lib/server/pocketbase');
const recs = (await pbAdmin.getList(
'accesscodes',
`value = '${code.trim().toUpperCase()}' && active = true`
)) as any[];
const days = Number(recs?.[0]?.trialDays) || 0;
return days > 0 ? days : null;
}
export function verifyStripeEvent(rawBody: string, signature: string): Stripe.Event {
@@ -68,7 +69,7 @@ export async function createCheckoutSession(opts: {
mode: 'subscription',
metadata: { famId: opts.famId, plan: opts.plan },
success_url: `${opts.origin}/account?checkout=success`,
cancel_url: `${opts.origin}/subscriptions?checkout=cancelled`
cancel_url: `${opts.origin}/pricing?checkout=cancelled`
};
// Attach customer if we already have a Stripe customer id for this fam.
@@ -93,10 +94,10 @@ export async function createCheckoutSession(opts: {
}
// Stripe Billing portal session for managing/cancelling the subscription.
export async function createBillingPortalSession(customerId: string, origin: string) {
export async function createBillingPortalSession(customerId: string, origin: string, famSlug = '') {
return stripe.billingPortal.sessions.create({
customer: customerId,
return_url: `${origin}/account`
return_url: `${origin}/${famSlug}?checkout=return`
});
}
@@ -108,6 +109,7 @@ export async function createEmbeddedCheckoutSession(opts: {
plan: PlanId | 'price' | 'trial';
priceId?: string;
famId: string;
famSlug: string;
email?: string | null;
customerId?: string | null;
trialDays?: number | null;
@@ -124,7 +126,7 @@ export async function createEmbeddedCheckoutSession(opts: {
mode: 'subscription',
ui_mode: 'embedded_page',
metadata: { famId: opts.famId, plan: opts.plan },
return_url: `${opts.origin}/account?checkout=return`
return_url: `${opts.origin}/${opts.famSlug}?checkout=return`
};
if (opts.customerId) {