mirror of
https://github.com/rybbit-io/rybbit.git
synced 2025-05-11 20:35:39 +02:00
parent
0f43f62103
commit
24aa7e54c5
2 changed files with 11 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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()];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue