-
Notifications
You must be signed in to change notification settings - Fork 11.7k
feat: adds user plan info in useHasPaidPlan for intercom
#23790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b8ac087
334776a
fd3c728
80bbb8a
c5deba2
2e22d69
58e511f
af95218
0fd6370
ae1ff8f
06ebb5c
e8f1316
1970c05
36072d6
7d6f050
7e224a2
4f950f2
3184309
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { BillingPlans, ENTERPRISE_SLUGS, PLATFORM_ENTERPRISE_SLUGS } from "@calcom/ee/billing/constants"; | ||
|
||
| import { MembershipRepository } from "@calcom/lib/server/repository/membership"; | ||
|
|
||
| export class BillingPlanService { | ||
| static async getUserPlanByUserId(userId: number) { | ||
| const memberships = await MembershipRepository.findAllMembershipsByUserIdForBilling({ userId }); | ||
|
|
||
volnei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (memberships.length === 0) return BillingPlans.INDIVIDUALS; | ||
|
|
||
| for (const { team, user } of memberships) { | ||
|
||
| if (team.isPlatform || user.isPlatformManaged) { | ||
| if (PLATFORM_ENTERPRISE_SLUGS.includes(team.slug ?? "")) return BillingPlans.PLATFORM_ENTERPRISE; | ||
| if (!team.platformBilling) continue; | ||
|
|
||
| switch (team.platformBilling.plan) { | ||
| case "FREE": | ||
| case "STARTER": | ||
| return BillingPlans.PLATFORM_STARTER; | ||
| case "ESSENTIALS": | ||
| return BillingPlans.PLATFORM_ESSENTIALS; | ||
| case "SCALE": | ||
| return BillingPlans.PLATFORM_SCALE; | ||
| case "ENTERPRISE": | ||
| return BillingPlans.PLATFORM_ENTERPRISE; | ||
| default: | ||
| return team.platformBilling.plan; | ||
volnei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } else { | ||
| if (team.parent && team.parent.isOrganization && team.parentId && !team.parent.isPlatform) { | ||
| return ENTERPRISE_SLUGS.includes(team.parent.slug ?? "") | ||
| ? BillingPlans.ENTERPRISE | ||
| : BillingPlans.ORGANIZATIONS; | ||
| } | ||
|
|
||
| if (team.isOrganization) { | ||
| return ENTERPRISE_SLUGS.includes(team.slug ?? "") | ||
| ? BillingPlans.ENTERPRISE | ||
| : BillingPlans.ORGANIZATIONS; | ||
| } else { | ||
| return BillingPlans.TEAMS; | ||
| } | ||
| } | ||
| } | ||
| return BillingPlans.UNKNOWN; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,15 @@ export const CHECKOUT_SESSION_TYPES = { | |
| } as const; | ||
|
|
||
| export type CheckoutSessionType = (typeof CHECKOUT_SESSION_TYPES)[keyof typeof CHECKOUT_SESSION_TYPES]; | ||
|
|
||
| export enum BillingPlans { | ||
| INDIVIDUALS = "INDIVIDUALS", | ||
| TEAMS = "TEAMS", | ||
| ORGANIZATIONS = "ORGANIZATIONS", | ||
| ENTERPRISE = "ENTERPRISE", | ||
| PLATFORM_STARTER = "PLATFORM_STARTER", | ||
| PLATFORM_ESSENTIALS = "PLATFORM_ESSENTIALS", | ||
| PLATFORM_SCALE = "PLATFORM_SCALE", | ||
| PLATFORM_ENTERPRISE = "PLATFORM_ENTERPRISE", | ||
| UNKNOWN = "Unknown", | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
|
|
||
| import { availabilityUserSelect, prisma, type PrismaTransaction } from "@calcom/prisma"; | ||
| import { MembershipRole } from "@calcom/prisma/enums"; | ||
| import type { Prisma, Membership, PrismaClient } from "@calcom/prisma/client"; | ||
| import { MembershipRole } from "@calcom/prisma/enums"; | ||
| import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential"; | ||
|
|
||
| import logger from "../../logger"; | ||
|
|
@@ -315,6 +314,42 @@ export class MembershipRepository { | |
| }); | ||
| } | ||
|
|
||
| static async findAllMembershipsByUserIdForBilling({ userId }: { userId: number }) { | ||
volnei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return await prisma.membership.findMany({ | ||
|
||
| where: { userId }, | ||
| select: { | ||
| user: { | ||
| select: { | ||
| isPlatformManaged: true, | ||
| }, | ||
| }, | ||
| team: { | ||
| select: { | ||
| id: true, | ||
| slug: true, | ||
| isOrganization: true, | ||
| isPlatform: true, | ||
| parentId: true, | ||
| metadata: true, | ||
| platformBilling: { | ||
| select: { | ||
| plan: true, | ||
| }, | ||
| }, | ||
| parent: { | ||
| select: { | ||
| slug: true, | ||
| isOrganization: true, | ||
| isPlatform: true, | ||
| metadata: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| static async findByTeamIdForAvailability({ teamId }: { teamId: number }) { | ||
| const memberships = await prisma.membership.findMany({ | ||
| where: { teamId }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.