feat: skip platform billing for non-platform-managed users (#27521)
* feat: skip platform billing for non-platform-managed users - Add isPlatformManaged to user select in saveBooking and findBookingQuery - Update 2024-04-15 booking controller to check isPlatformManaged before billing - Update 2024-08-13 bookings service billBooking methods to check isPlatformManaged - Update buildDryRunBooking to include isPlatformManaged in user object Co-Authored-By: [email protected] <[email protected]> * test: update buildDryRunBooking test to include uuid and isPlatformManaged fields Co-Authored-By: [email protected] <[email protected]> * refactor: simplify to only check isPlatformManaged in normal booking flow Co-Authored-By: [email protected] <[email protected]> * test: add E2E tests for billing behavior based on isPlatformManaged flag Co-Authored-By: [email protected] <[email protected]> * chore: only trigger platform billing for platform user bookingd * test: add E2E tests for cancel and recurring booking billing behavior Co-Authored-By: [email protected] <[email protected]> * fix: correct expected status code for cancel booking endpoint (201 instead of 200) Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
9 files changed
+632
-114
No files matched your search
@@ -32,4 +32,5 @@ export type HandleCancelBookingResponse = {
|
||||
onlyRemovedAttendee: boolean;
|
||||
bookingId: number;
|
||||
bookingUid: string;
|
||||
isPlatformManagedUserBooking: boolean;
|
||||
};
|
||||
@@ -23,6 +23,7 @@ export async function getBookingToDelete(id: number | undefined, uid: string | u
|
||||
name: true,
|
||||
destinationCalendar: true,
|
||||
locale: true,
|
||||
isPlatformManaged: true,
|
||||
profiles: {
|
||||
select: {
|
||||
organizationId: true,
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import type { z } from "zod";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { DailyLocationType } from "@calcom/app-store/constants";
|
||||
import { FAKE_DAILY_CREDENTIAL } from "@calcom/app-store/dailyvideo/lib/VideoApiAdapter";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { sendCancelledEmailsAndSMS } from "@calcom/emails/email-manager";
|
||||
import type { Actor } from "@calcom/features/booking-audit/lib/dto/types";
|
||||
import {
|
||||
buildActorEmail,
|
||||
getUniqueIdentifier,
|
||||
makeGuestActor,
|
||||
makeUserActor,
|
||||
} from "@calcom/features/booking-audit/lib/makeActor";
|
||||
import type { ActionSource } from "@calcom/features/booking-audit/lib/types/actionSource";
|
||||
import { BookingReferenceRepository } from "@calcom/features/bookingReference/repositories/BookingReferenceRepository";
|
||||
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
|
||||
import EventManager from "@calcom/features/bookings/lib/EventManager";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
@@ -23,8 +28,8 @@ import { UserRepository } from "@calcom/features/users/repositories/UserReposito
|
||||
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
import {
|
||||
deleteWebhookScheduledTriggers,
|
||||
cancelNoShowTasksForBooking,
|
||||
deleteWebhookScheduledTriggers,
|
||||
} from "@calcom/features/webhooks/lib/scheduleTrigger";
|
||||
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
|
||||
import type { EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
@@ -36,22 +41,21 @@ import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import { BookingReferenceRepository } from "@calcom/features/bookingReference/repositories/BookingReferenceRepository";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
// TODO: Prisma import would be used from DI in a followup PR when we remove `handler` export
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { WorkflowMethods } from "@calcom/prisma/enums";
|
||||
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
import type { WebhookTriggerEvents, WorkflowMethods } from "@calcom/prisma/enums";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import { bookingMetadataSchema, bookingCancelInput } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
|
||||
import { bookingCancelInput, bookingMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import type { z } from "zod";
|
||||
import { BookingRepository } from "../repositories/BookingRepository";
|
||||
import { PrismaBookingAttendeeRepository } from "../repositories/PrismaBookingAttendeeRepository";
|
||||
import type {
|
||||
CancelRegularBookingData,
|
||||
CancelBookingMeta,
|
||||
CancelRegularBookingData,
|
||||
HandleCancelBookingResponse,
|
||||
} from "./dto/BookingCancel";
|
||||
import { getAllCredentialsIncludeServiceAccountKey } from "./getAllCredentialsForUsersOnEvent/getAllCredentials";
|
||||
@@ -59,13 +63,6 @@ import { getBookingToDelete } from "./getBookingToDelete";
|
||||
import { handleInternalNote } from "./handleInternalNote";
|
||||
import cancelAttendeeSeat from "./handleSeats/cancel/cancelAttendeeSeat";
|
||||
import type { IBookingCancelService } from "./interfaces/IBookingCancelService";
|
||||
import {
|
||||
buildActorEmail,
|
||||
getUniqueIdentifier,
|
||||
makeGuestActor,
|
||||
makeUserActor,
|
||||
} from "@calcom/features/booking-audit/lib/makeActor";
|
||||
import type { Actor } from "@calcom/features/booking-audit/lib/dto/types";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["handleCancelBooking"] });
|
||||
|
||||
@@ -218,7 +215,7 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
|
||||
}
|
||||
|
||||
const isCancellationUserHost =
|
||||
bookingToDelete.userId == userId || bookingToDelete.user.email === cancelledBy;
|
||||
bookingToDelete.userId === userId || bookingToDelete.user.email === cancelledBy;
|
||||
|
||||
if (
|
||||
!platformClientId &&
|
||||
@@ -385,12 +382,12 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
|
||||
cancellationReason: cancellationReason,
|
||||
...(teamMembers &&
|
||||
teamId && {
|
||||
team: {
|
||||
name: bookingToDelete?.eventType?.team?.name || "Nameless",
|
||||
members: teamMembers,
|
||||
id: teamId,
|
||||
},
|
||||
}),
|
||||
team: {
|
||||
name: bookingToDelete?.eventType?.team?.name || "Nameless",
|
||||
members: teamMembers,
|
||||
id: teamId,
|
||||
},
|
||||
}),
|
||||
seatsPerTimeSlot: bookingToDelete.eventType?.seatsPerTimeSlot,
|
||||
seatsShowAttendees: bookingToDelete.eventType?.seatsShowAttendees,
|
||||
iCalUID: bookingToDelete.iCalUID,
|
||||
@@ -423,6 +420,7 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
|
||||
bookingId: bookingToDelete.id,
|
||||
bookingUid: bookingToDelete.uid,
|
||||
message: "Attendee successfully removed.",
|
||||
isPlatformManagedUserBooking: bookingToDelete.user.isPlatformManaged,
|
||||
} satisfies HandleCancelBookingResponse;
|
||||
|
||||
const promises = webhooks.map((webhook) =>
|
||||
@@ -698,6 +696,7 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
|
||||
onlyRemovedAttendee: false,
|
||||
bookingId: bookingToDelete.id,
|
||||
bookingUid: bookingToDelete.uid,
|
||||
isPlatformManagedUserBooking: bookingToDelete.user.isPlatformManaged,
|
||||
} satisfies HandleCancelBookingResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ async function saveBooking(
|
||||
const createBookingObj = {
|
||||
include: {
|
||||
user: {
|
||||
select: { uuid: true, email: true, name: true, timeZone: true, username: true },
|
||||
select: { uuid: true, email: true, name: true, timeZone: true, username: true, isPlatformManaged: true },
|
||||
},
|
||||
attendees: true,
|
||||
payment: true,
|
||||
|
||||
@@ -24,6 +24,7 @@ const _findBookingQuery = async (bookingId: number) => {
|
||||
email: true,
|
||||
timeZone: true,
|
||||
username: true,
|
||||
isPlatformManaged: true,
|
||||
},
|
||||
},
|
||||
eventType: {
|
||||
|
||||
@@ -12,6 +12,7 @@ vi.mock("@calcom/prisma", () => ({
|
||||
describe("buildDryRunBooking", () => {
|
||||
const baseOrganizerUser = {
|
||||
id: 1,
|
||||
uuid: "test-uuid-123",
|
||||
name: "Test User",
|
||||
username: "testuser",
|
||||
email: "[email protected]",
|
||||
@@ -41,10 +42,12 @@ describe("buildDryRunBooking", () => {
|
||||
const { user, ...bookingExceptUser } = booking;
|
||||
expect(user).toEqual({
|
||||
id: baseOrganizerUser.id,
|
||||
uuid: baseOrganizerUser.uuid,
|
||||
name: baseOrganizerUser.name,
|
||||
username: baseOrganizerUser.username,
|
||||
email: baseOrganizerUser.email,
|
||||
timeZone: baseOrganizerUser.timeZone,
|
||||
isPlatformManaged: false,
|
||||
});
|
||||
|
||||
expect(bookingExceptUser).toEqual({
|
||||
@@ -54,6 +57,7 @@ describe("buildDryRunBooking", () => {
|
||||
status: BookingStatus.ACCEPTED,
|
||||
eventTypeId: baseInputs.eventTypeId,
|
||||
userId: baseOrganizerUser.id,
|
||||
userUuid: baseOrganizerUser.uuid,
|
||||
title: baseInputs.eventName,
|
||||
startTime: new Date(baseInputs.startTime),
|
||||
endTime: new Date(baseInputs.endTime),
|
||||
|
||||
@@ -188,6 +188,7 @@ export const buildDryRunBooking = ({
|
||||
username: string | null;
|
||||
email: string;
|
||||
timeZone: string;
|
||||
isPlatformManaged?: boolean;
|
||||
};
|
||||
eventName: string;
|
||||
startTime: string;
|
||||
@@ -204,6 +205,7 @@ export const buildDryRunBooking = ({
|
||||
username: organizerUser.username,
|
||||
email: organizerUser.email,
|
||||
timeZone: organizerUser.timeZone,
|
||||
isPlatformManaged: organizerUser.isPlatformManaged ?? false,
|
||||
};
|
||||
const booking = {
|
||||
id: -101,
|
||||
|
||||
Reference in new issue
Block a user