diff --git a/apps/api/src/utils/plans.ts b/apps/api/src/utils/plans.ts index 4adb018..065e57a 100644 --- a/apps/api/src/utils/plans.ts +++ b/apps/api/src/utils/plans.ts @@ -1,4 +1,4 @@ -export type Plan = "free" | "pro" | "lifetime"; +export type Plan = "free" | "pro" | "pro4x" | "lifetime"; export interface PlanLimits { maxMonitors: number; @@ -17,6 +17,11 @@ const PLANS: Record = { minIntervalS: 2, maxRegions: 99, }, + pro4x: { + maxMonitors: 800, + minIntervalS: 2, + maxRegions: 99, + }, lifetime: { maxMonitors: 200, minIntervalS: 2, diff --git a/apps/pay/src/monitor.ts b/apps/pay/src/monitor.ts index d70a236..9c32f86 100644 --- a/apps/pay/src/monitor.ts +++ b/apps/pay/src/monitor.ts @@ -219,10 +219,11 @@ async function applyPlan(payment: any) { const [acc] = await sql`SELECT plan, plan_expires_at FROM accounts WHERE id = ${payment.account_id}`; const now = new Date(); const expiry = acc.plan_expires_at ? new Date(acc.plan_expires_at) : null; - const base = (acc.plan === "pro" && expiry && expiry > now) ? expiry : now; + const samePlan = acc.plan === payment.plan && expiry && expiry > now; + const base = samePlan ? expiry : now; const newExpiry = new Date(base); newExpiry.setMonth(newExpiry.getMonth() + payment.months); - await sql`UPDATE accounts SET plan = 'pro', plan_expires_at = ${newExpiry.toISOString()} WHERE id = ${payment.account_id}`; + await sql`UPDATE accounts SET plan = ${payment.plan}, plan_expires_at = ${newExpiry.toISOString()} WHERE id = ${payment.account_id}`; } console.log(`Payment ${payment.id} activated: ${payment.plan} for account ${payment.account_id}`); } diff --git a/apps/pay/src/plans.ts b/apps/pay/src/plans.ts index 4a166d1..f4a0f9c 100644 --- a/apps/pay/src/plans.ts +++ b/apps/pay/src/plans.ts @@ -3,6 +3,10 @@ export const PLANS = { label: "Pro", monthlyUsd: 12, }, + pro4x: { + label: "Pro 4x", + monthlyUsd: 48, + }, lifetime: { label: "Lifetime", priceUsd: 140, diff --git a/apps/pay/src/routes.ts b/apps/pay/src/routes.ts index f81eb6a..67b48ba 100644 --- a/apps/pay/src/routes.ts +++ b/apps/pay/src/routes.ts @@ -72,7 +72,8 @@ export const routes = new Elysia() if (!available.includes(coin)) { set.status = 400; return { error: `${coin} is temporarily unavailable` }; } // Calculate amount - const amountUsd = plan === "lifetime" ? PLANS.lifetime.priceUsd : PLANS.pro.monthlyUsd * (months ?? 1); + const planPricing = plan === "lifetime" ? null : (plan === "pro4x" ? PLANS.pro4x : PLANS.pro); + const amountUsd = plan === "lifetime" ? PLANS.lifetime.priceUsd : planPricing!.monthlyUsd * (months ?? 1); const rates = await getExchangeRates(); const rate = rates[coin]; if (!rate) { set.status = 500; return { error: "Could not fetch exchange rate" }; } diff --git a/apps/web/src/views/checkout.ejs b/apps/web/src/views/checkout.ejs index 2489a06..ca1f021 100644 --- a/apps/web/src/views/checkout.ejs +++ b/apps/web/src/views/checkout.ejs @@ -9,10 +9,12 @@ %>