fix usage checker (#109)

* fix usage checker

* fix

* fix tax
This commit is contained in:
Bill Yang 2025-05-03 23:19:59 -07:00 committed by GitHub
parent 0f43f62103
commit 24aa7e54c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -82,6 +82,10 @@ export async function createCheckoutSession(
allow_promotion_codes: true,
// Enable automatic tax calculation if configured in Stripe Tax settings
automatic_tax: { enabled: true },
// Configure customer address collection for tax calculation
customer_update: {
address: "auto",
},
});
// 5. Return the Checkout Session URL

View file

@ -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 events
return [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 month
return [DEFAULT_EVENT_LIMIT, getStartOfMonth()];
}