🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
fix usage checker (#109)
Bill Yang24aa7e54c5ee
diff --git a/server/src/api/stripe/createCheckoutSession.ts b/server/src/api/stripe/createCheckoutSession.tsindex abec249fa..03d7a113c 100644--- a/server/src/api/stripe/createCheckoutSession.ts+++ b/server/src/api/stripe/createCheckoutSession.ts@@ -82,6 +82,10 @@ export async function createCheckoutSession(allow_promotion_codes: true,// Enable automatic tax calculation if configured in Stripe Tax settingsautomatic_tax: { enabled: true },+ // Configure customer address collection for tax calculation+ customer_update: {+ address: "auto",+ },});// 5. Return the Checkout Session URLdiff --git a/server/src/cron/monthly-usage-checker.ts b/server/src/cron/monthly-usage-checker.tsindex 3643a6d49..99f093d93 100644--- a/server/src/cron/monthly-usage-checker.ts+++ b/server/src/cron/monthly-usage-checker.ts@@ -64,13 +64,11 @@ async function getUserSubscriptionInfo(userData: {createdAt: string;email: string;}): Promise<[number, string | null]> {- if (!userData.stripeCustomerId) {- const createdAtDate = DateTime.fromSQL(userData.createdAt);- const daysSinceCreation = Math.abs(createdAtDate.diffNow("days").days);+ const createdAtDate = DateTime.fromSQL(userData.createdAt);+ const daysSinceCreation = Math.abs(createdAtDate.diffNow("days").days);- // If the user was created in the last 14 days, use the trial limit+ if (!userData.stripeCustomerId) {if (daysSinceCreation < 14) {- // For trial users, use their account creation date as the starting point for counting eventsreturn [TRIAL_EVENT_LIMIT, createdAtDate.toISODate() as string];}@@ -87,6 +85,10 @@ async function getUserSubscriptionInfo(userData: {});if (subscriptions.data.length === 0) {+ // If the user was created in the last 14 days, use the trial limit+ if (daysSinceCreation < 14) {+ return [TRIAL_EVENT_LIMIT, createdAtDate.toISODate() as string];+ }// No active subscription, use default limit and start of current monthreturn [DEFAULT_EVENT_LIMIT, getStartOfMonth()];}