-
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 11 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 |
|---|---|---|
|
|
@@ -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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { BillingPlans } from "@calcom/ee/billing/constants"; | ||
| import type { Plans } from "@calcom/prisma/enums"; | ||
|
|
||
| export class BillingPlanService { | ||
| async getUserPlanByMemberships( | ||
| memberships: { | ||
| team: { | ||
| plan: Plans | null; | ||
| isOrganization: boolean; | ||
| isPlatform: boolean; | ||
| parent: { | ||
| isOrganization: boolean; | ||
| isPlatform: boolean; | ||
| plan: Plans | null; | ||
| } | null; | ||
| platformBilling: { | ||
| plan: string; | ||
| } | null; | ||
| }; | ||
| user: { | ||
| isPlatformManaged: boolean; | ||
| }; | ||
| }[] | ||
| ) { | ||
| if (memberships.length === 0) return BillingPlans.INDIVIDUALS; | ||
|
|
||
| for (const { team, user } of memberships) { | ||
| if (team.isPlatform || user.isPlatformManaged) { | ||
| 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; | ||
| } | ||
| } else { | ||
| if (team.parent?.plan) return team.parent.plan; | ||
| if (team.plan) return team.plan; | ||
| } | ||
| } | ||
| return BillingPlans.UNKNOWN; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import { LicenseKeySingleton } from "@calcom/ee/common/server/LicenseKeyService" | |
| import * as constants from "@calcom/lib/constants"; | ||
| import { createDomain } from "@calcom/lib/domainManager/organization"; | ||
| import type { OrganizationOnboarding } from "@calcom/prisma/client"; | ||
| import { MembershipRole } from "@calcom/prisma/enums"; | ||
| import { MembershipRole, Plans } from "@calcom/prisma/enums"; | ||
| import { createTeamsHandler } from "@calcom/trpc/server/routers/viewer/organizations/createTeams.handler"; | ||
| import { inviteMembersWithNoInviterPermissionCheck } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler"; | ||
|
|
||
|
|
@@ -66,8 +66,8 @@ const mockOrganizationOnboarding = { | |
| createdById: 1, | ||
| invitedMembers: [{ email: "[email protected]" }, { email: "[email protected]" }], | ||
| teams: [ | ||
| { id: 1, name: "Team To Move", isBeingMigrated: true, slug: "new-team-slug" }, | ||
| { id: 2, name: "New Team", isBeingMigrated: false, slug: null }, | ||
| { id: 1, name: "Team To Move", isBeingMigrated: true, slug: "new-team-slug", plan: Plans.TEAMS }, | ||
| { id: 2, name: "New Team", isBeingMigrated: false, slug: null, plan: Plans.TEAMS }, | ||
| ], | ||
| logo: null, | ||
| bio: null, | ||
|
|
@@ -81,6 +81,7 @@ async function createTestUser(data: { | |
| email: string; | ||
| name?: string; | ||
| username?: string; | ||
| //eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| metadata?: any; | ||
| onboardingCompleted?: boolean; | ||
| emailVerified?: Date | null; | ||
|
|
@@ -101,6 +102,7 @@ async function createTestOrganization(data: { | |
| name: string; | ||
| slug: string; | ||
| isOrganization?: boolean; | ||
| //eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| metadata?: any; | ||
| }) { | ||
| return prismock.team.create({ | ||
|
|
@@ -244,6 +246,19 @@ describe("createOrganizationFromOnboarding", () => { | |
| expect(organization.name).toBe(organizationOnboarding.name); | ||
| expect(organization.slug).toBe(organizationOnboarding.slug); | ||
|
|
||
| //parent team plan and sub teams plan should be updated to organizations | ||
| expect(organization.plan).toBe(Plans.ORGANIZATIONS); | ||
|
|
||
| const teams = await prismock.team.findMany({ | ||
| where: { | ||
| id: { | ||
| in: organizationOnboarding.teams?.map((t) => t.id), | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(teams.every((t) => t.plan === Plans.ORGANIZATIONS)).toBe(true); | ||
|
|
||
| // Verify owner is the existing user | ||
| expect(owner.id).toBe(existingUser.id); | ||
| expect(owner.email).toBe(existingUser.email); | ||
|
|
||
| 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,40 @@ 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: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accepted: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isPlatformManaged: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| team: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slug: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plan: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isOrganization: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isPlatform: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformBilling: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plan: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parent: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plan: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isOrganization: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isPlatform: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static async findAllMembershipsByUserIdForBilling({ userId }: { userId: number }) { | |
| return await prisma.membership.findMany({ | |
| where: { userId }, | |
| select: { | |
| accepted: true, | |
| user: { | |
| select: { | |
| isPlatformManaged: true, | |
| }, | |
| }, | |
| team: { | |
| select: { | |
| slug: true, | |
| plan: true, | |
| isOrganization: true, | |
| isPlatform: true, | |
| platformBilling: { | |
| select: { | |
| plan: true, | |
| }, | |
| }, | |
| parent: { | |
| select: { | |
| plan: true, | |
| isOrganization: true, | |
| isPlatform: true, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }); | |
| } | |
| static async findAllMembershipsByUserIdForBilling({ userId }: { userId: number }) { | |
| return await prisma.membership.findMany({ | |
| where: { userId, accepted: true }, | |
| select: { | |
| accepted: true, | |
| user: { | |
| select: { | |
| isPlatformManaged: true, | |
| }, | |
| }, | |
| team: { | |
| select: { | |
| slug: true, | |
| plan: true, | |
| isOrganization: true, | |
| isPlatform: true, | |
| platformBilling: { | |
| select: { | |
| plan: true, | |
| }, | |
| }, | |
| parent: { | |
| select: { | |
| plan: true, | |
| isOrganization: true, | |
| isPlatform: true, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }); | |
| } |
🤖 Prompt for AI Agents
In packages/lib/server/repository/membership.ts around lines 317 to 349, the
method returns all memberships for a user but should only return accepted
memberships for billing; update the prisma.membership.findMany call to include
accepted: true in the where clause (e.g., where: { userId, accepted: true }) so
pending invites are excluded while keeping the current select projection
unchanged.
Uh oh!
There was an error while loading. Please reload this page.