diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index 4e7896b91d..fadedd32a4 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -38,7 +38,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.358", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.359", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", "@calcom/prisma": "*", diff --git a/apps/api/v2/src/modules/atoms/controllers/atoms.verification.controller.ts b/apps/api/v2/src/modules/atoms/controllers/atoms.verification.controller.ts index 77829716d4..9d17044cde 100644 --- a/apps/api/v2/src/modules/atoms/controllers/atoms.verification.controller.ts +++ b/apps/api/v2/src/modules/atoms/controllers/atoms.verification.controller.ts @@ -79,13 +79,13 @@ export class AtomsVerificationController { @Version(VERSION_NEUTRAL) @HttpCode(HttpStatus.OK) async verifyEmailCode(@Body() body: VerifyEmailCodeInput): Promise { - const verified = await this.verificationService.verifyEmailCodeUnAuthenticated({ + await this.verificationService.verifyEmailCodeUnAuthenticated({ email: body.email, code: body.code, }); return { - data: { verified }, + data: { verified: true }, status: SUCCESS_STATUS, }; } diff --git a/apps/web/app/(use-page-wrapper)/payment/[uid]/PaymentPage.tsx b/apps/web/app/(use-page-wrapper)/payment/[uid]/PaymentPage.tsx index 56b3e4b96e..f2000cd208 100644 --- a/apps/web/app/(use-page-wrapper)/payment/[uid]/PaymentPage.tsx +++ b/apps/web/app/(use-page-wrapper)/payment/[uid]/PaymentPage.tsx @@ -5,6 +5,7 @@ import dynamic from "next/dynamic"; import type { FC } from "react"; import { useEffect, useState } from "react"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { getSuccessPageLocationMessage } from "@calcom/app-store/locations"; import dayjs from "@calcom/dayjs"; import { sdkActionManager, useIsEmbed } from "@calcom/embed-core/embed-iframe"; @@ -12,7 +13,6 @@ import { PayIcon } from "@calcom/features/bookings/components/event-meta/PayIcon import { Price } from "@calcom/features/bookings/components/event-meta/Price"; import type { PaymentPageProps } from "@calcom/features/ee/payments/pages/payment"; import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import useTheme from "@calcom/lib/hooks/useTheme"; import { getIs24hClockFromLocalStorage, isBrowserLocale24h } from "@calcom/lib/timeFormat"; diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index dea75e057c..44079e90c4 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -2,6 +2,7 @@ import Link from "next/link"; import { useState } from "react"; import { Controller, useFieldArray, useForm } from "react-hook-form"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import type { getEventLocationValue } from "@calcom/app-store/locations"; import { getSuccessPageLocationMessage, guessEventLocationType } from "@calcom/app-store/locations"; import dayjs from "@calcom/dayjs"; @@ -11,7 +12,6 @@ import { Dialog } from "@calcom/features/components/controlled-dialog"; import { MeetingSessionDetailsDialog } from "@calcom/features/ee/video/MeetingSessionDetailsDialog"; import ViewRecordingsDialog from "@calcom/features/ee/video/ViewRecordingsDialog"; import { formatTime } from "@calcom/lib/dayjs"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useCopy } from "@calcom/lib/hooks/useCopy"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useGetTheme } from "@calcom/lib/hooks/useTheme"; diff --git a/apps/web/components/booking/CancelBooking.tsx b/apps/web/components/booking/CancelBooking.tsx index e53a0e7349..0376f3291e 100644 --- a/apps/web/components/booking/CancelBooking.tsx +++ b/apps/web/components/booking/CancelBooking.tsx @@ -3,10 +3,10 @@ import { useCallback, useState } from "react"; import { sdkActionManager } from "@calcom/embed-core/embed-iframe"; +import { shouldChargeNoShowCancellationFee } from "@calcom/features/bookings/lib/payment/shouldChargeNoShowCancellationFee"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useRefreshData } from "@calcom/lib/hooks/useRefreshData"; import { useTelemetry } from "@calcom/lib/hooks/useTelemetry"; -import { shouldChargeNoShowCancellationFee } from "@calcom/lib/payment/shouldChargeNoShowCancellationFee"; import { collectPageParameters, telemetryEventTypes } from "@calcom/lib/telemetry"; import type { RecurringEvent } from "@calcom/types/Calendar"; import { Button } from "@calcom/ui/components/button"; diff --git a/apps/web/components/booking/__tests__/CancelBooking.cancellationFee.test.tsx b/apps/web/components/booking/__tests__/CancelBooking.cancellationFee.test.tsx index 39f09e4bef..00c57c279b 100644 --- a/apps/web/components/booking/__tests__/CancelBooking.cancellationFee.test.tsx +++ b/apps/web/components/booking/__tests__/CancelBooking.cancellationFee.test.tsx @@ -2,7 +2,7 @@ import { render, screen } from "@testing-library/react"; import * as React from "react"; import { describe, expect, it, vi, beforeAll } from "vitest"; -import * as shouldChargeModule from "@calcom/lib/payment/shouldChargeNoShowCancellationFee"; +import * as shouldChargeModule from "@calcom/features/bookings/lib/payment/shouldChargeNoShowCancellationFee"; import CancelBooking from "../CancelBooking"; @@ -76,7 +76,7 @@ vi.mock("next/router", () => ({ }), })); -vi.mock("@calcom/lib/payment/shouldChargeNoShowCancellationFee", () => ({ +vi.mock("@calcom/features/bookings/lib/payment/shouldChargeNoShowCancellationFee", () => ({ shouldChargeNoShowCancellationFee: vi.fn(), })); diff --git a/packages/app-store/_utils/getConnectedApps.ts b/packages/app-store/_utils/getConnectedApps.ts index a0f841e73d..fdbe187bfa 100644 --- a/packages/app-store/_utils/getConnectedApps.ts +++ b/packages/app-store/_utils/getConnectedApps.ts @@ -1,5 +1,4 @@ import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner"; -import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials"; import getInstallCountPerApp from "@calcom/lib/apps/getInstallCountPerApp"; import { buildNonDelegationCredentials } from "@calcom/lib/delegationCredential/clientAndServer"; import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials"; @@ -11,6 +10,7 @@ import type { TDependencyData } from "../_appRegistry"; import { PaymentServiceMap } from "../payment.services.generated"; import type { CredentialOwner } from "../types"; import { getAppFromSlug } from "../utils"; +import getEnabledAppsFromCredentials from "./getEnabledAppsFromCredentials"; export type ConnectedApps = Awaited>; type InputSchema = { diff --git a/packages/lib/apps/getEnabledAppsFromCredentials.ts b/packages/app-store/_utils/getEnabledAppsFromCredentials.ts similarity index 95% rename from packages/lib/apps/getEnabledAppsFromCredentials.ts rename to packages/app-store/_utils/getEnabledAppsFromCredentials.ts index 0d7c940add..5148b47eff 100644 --- a/packages/lib/apps/getEnabledAppsFromCredentials.ts +++ b/packages/app-store/_utils/getEnabledAppsFromCredentials.ts @@ -1,9 +1,9 @@ import type { CredentialDataWithTeamName } from "@calcom/app-store/utils"; -import getApps from "@calcom/app-store/utils"; +import { isDelegationCredential } from "@calcom/lib/delegationCredential/clientAndServer"; import { prisma } from "@calcom/prisma"; import type { Prisma } from "@calcom/prisma/client"; -import { isDelegationCredential } from "../delegationCredential/clientAndServer"; +import getApps from "../utils"; type EnabledApp = ReturnType[number] & { enabled: boolean }; diff --git a/packages/lib/getPaymentAppData.ts b/packages/app-store/_utils/payments/getPaymentAppData.ts similarity index 84% rename from packages/lib/getPaymentAppData.ts rename to packages/app-store/_utils/payments/getPaymentAppData.ts index 30e135efc1..5b515d238b 100644 --- a/packages/lib/getPaymentAppData.ts +++ b/packages/app-store/_utils/payments/getPaymentAppData.ts @@ -1,13 +1,14 @@ import type { z } from "zod"; -import { getEventTypeAppData } from "@calcom/app-store/_utils/getEventTypeAppData"; -import type { appDataSchemas } from "@calcom/app-store/apps.schemas.generated"; -import type { appDataSchema, paymentOptionEnum } from "@calcom/app-store/stripepayment/zod"; -import type { EventTypeAppsList } from "@calcom/app-store/utils"; -import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils"; import type { BookerEvent } from "@calcom/features/bookings/types"; import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; +import type { appDataSchemas } from "../../apps.schemas.generated"; +import type { appDataSchema, paymentOptionEnum } from "../../stripepayment/zod"; +import type { EventTypeAppsList } from "../../utils"; +import { eventTypeMetaDataSchemaWithTypedApps } from "../../zod-utils"; +import { getEventTypeAppData } from "../getEventTypeAppData"; + export function getPaymentAppData( _eventType: Pick & { metadata: z.infer; diff --git a/packages/app-store/_utils/payments/handlePaymentSuccess.ts b/packages/app-store/_utils/payments/handlePaymentSuccess.ts index ee6075dcca..ef8ef72672 100644 --- a/packages/app-store/_utils/payments/handlePaymentSuccess.ts +++ b/packages/app-store/_utils/payments/handlePaymentSuccess.ts @@ -4,12 +4,12 @@ import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/do import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials"; import { handleBookingRequested } from "@calcom/features/bookings/lib/handleBookingRequested"; import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation"; +import { getBooking } from "@calcom/features/bookings/lib/payment/getBooking"; import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-platform-params"; import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository"; import EventManager, { placeholderCreatedEvent } from "@calcom/lib/EventManager"; import { HttpError as HttpCode } from "@calcom/lib/http-error"; import logger from "@calcom/lib/logger"; -import { getBooking } from "@calcom/lib/payment/getBooking"; import prisma from "@calcom/prisma"; import type { Prisma } from "@calcom/prisma/client"; import { BookingStatus } from "@calcom/prisma/enums"; diff --git a/packages/app-store/server.ts b/packages/app-store/server.ts index 4142accc00..a9467a93ac 100644 --- a/packages/app-store/server.ts +++ b/packages/app-store/server.ts @@ -1,7 +1,6 @@ import type { TFunction } from "i18next"; import { defaultVideoAppCategories } from "@calcom/app-store/utils"; -import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials"; import { buildNonDelegationCredentials, enrichUserWithDelegationConferencingCredentialsWithoutOrgId, @@ -11,6 +10,7 @@ import type { Prisma } from "@calcom/prisma/client"; import { AppCategories } from "@calcom/prisma/enums"; import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential"; +import getEnabledAppsFromCredentials from "./_utils/getEnabledAppsFromCredentials"; import { defaultLocations } from "./locations"; export async function getLocationGroupedOptions( diff --git a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx index d3834b3d06..c0c9699c8a 100644 --- a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx +++ b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx @@ -3,13 +3,13 @@ import Link from "next/link"; import { useMemo, useState } from "react"; import type { FieldError } from "react-hook-form"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { useIsPlatformBookerEmbed } from "@calcom/atoms/hooks/useIsPlatformBookerEmbed"; import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider"; import type { BookerEvent } from "@calcom/features/bookings/types"; import ServerTrans from "@calcom/lib/components/ServerTrans"; import { WEBSITE_PRIVACY_POLICY_URL, WEBSITE_TERMS_URL } from "@calcom/lib/constants"; import { ErrorCode } from "@calcom/lib/errorCodes"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { TimeFormat } from "@calcom/lib/timeFormat"; import { Alert } from "@calcom/ui/components/alert"; diff --git a/packages/features/bookings/components/AvailableTimes.tsx b/packages/features/bookings/components/AvailableTimes.tsx index 89d7436f2a..c9a1c97cc8 100644 --- a/packages/features/bookings/components/AvailableTimes.tsx +++ b/packages/features/bookings/components/AvailableTimes.tsx @@ -3,6 +3,7 @@ import * as HoverCard from "@radix-ui/react-hover-card"; import { AnimatePresence, m } from "framer-motion"; import { useMemo } from "react"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { useIsPlatform } from "@calcom/atoms/hooks/useIsPlatform"; import dayjs from "@calcom/dayjs"; import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider"; @@ -10,7 +11,6 @@ import { OutOfOfficeInSlots } from "@calcom/features/bookings/Booker/components/ import type { IUseBookingLoadingStates } from "@calcom/features/bookings/Booker/components/hooks/useBookings"; import type { BookerEvent } from "@calcom/features/bookings/types"; import type { Slot } from "@calcom/features/schedules/lib/use-schedule/types"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import type { IOutOfOfficeData } from "@calcom/lib/getUserAvailability"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { localStorage } from "@calcom/lib/webstorage"; diff --git a/packages/features/bookings/components/event-meta/Details.tsx b/packages/features/bookings/components/event-meta/Details.tsx index 1a0be5ef77..ccce8cc9c0 100644 --- a/packages/features/bookings/components/event-meta/Details.tsx +++ b/packages/features/bookings/components/event-meta/Details.tsx @@ -1,9 +1,9 @@ import React, { Fragment } from "react"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { useBookerStore } from "@calcom/features/bookings/Booker/store"; import { PriceIcon } from "@calcom/features/bookings/components/event-meta/PriceIcon"; import type { BookerEvent } from "@calcom/features/bookings/types"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import classNames from "@calcom/ui/classNames"; import { Icon } from "@calcom/ui/components/icon"; diff --git a/packages/features/bookings/lib/handleCancelBooking.ts b/packages/features/bookings/lib/handleCancelBooking.ts index 92dc9f4c0e..79e76e31ac 100644 --- a/packages/features/bookings/lib/handleCancelBooking.ts +++ b/packages/features/bookings/lib/handleCancelBooking.ts @@ -6,6 +6,8 @@ import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-util import dayjs from "@calcom/dayjs"; import { sendCancelledEmailsAndSMS } from "@calcom/emails"; import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses"; +import { processNoShowFeeOnCancellation } from "@calcom/features/bookings/lib/payment/processNoShowFeeOnCancellation"; +import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund"; import { sendCancelledReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler"; import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks"; import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks"; @@ -23,8 +25,6 @@ import { HttpError } from "@calcom/lib/http-error"; import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj"; import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; import logger from "@calcom/lib/logger"; -import { processNoShowFeeOnCancellation } from "@calcom/lib/payment/processNoShowFeeOnCancellation"; -import { processPaymentRefund } from "@calcom/lib/payment/processPaymentRefund"; import { safeStringify } from "@calcom/lib/safeStringify"; import { getTranslation } from "@calcom/lib/server/i18n"; import { WorkflowRepository } from "@calcom/lib/server/repository/workflow"; diff --git a/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts b/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts index 0ad54ff65d..a99278e8de 100644 --- a/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts +++ b/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts @@ -18,11 +18,11 @@ import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAn import { describe, expect, vi } from "vitest"; -import { processPaymentRefund } from "@calcom/lib/payment/processPaymentRefund"; +import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund"; import { BookingStatus } from "@calcom/prisma/enums"; import { test } from "@calcom/web/test/fixtures/fixtures"; -vi.mock("@calcom/lib/payment/processPaymentRefund", () => ({ +vi.mock("@calcom/features/bookings/lib/payment/processPaymentRefund", () => ({ processPaymentRefund: vi.fn(), })); diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 97ee75a97d..f8aadd9f46 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -54,7 +54,7 @@ import { getErrorFromUnknown } from "@calcom/lib/errors"; import { extractBaseEmail } from "@calcom/lib/extract-base-email"; import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server"; import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType"; import { HttpError } from "@calcom/lib/http-error"; import type { CheckBookingLimitsService } from "@calcom/lib/intervalLimits/server/checkBookingLimits"; diff --git a/packages/features/bookings/lib/handleNewBooking/types.ts b/packages/features/bookings/lib/handleNewBooking/types.ts index 26d2a4e6c2..2cc05361c1 100644 --- a/packages/features/bookings/lib/handleNewBooking/types.ts +++ b/packages/features/bookings/lib/handleNewBooking/types.ts @@ -1,7 +1,7 @@ import type { TFunction } from "i18next"; +import type { PaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import type { EventTypeAppsList } from "@calcom/app-store/utils"; -import type { PaymentAppData } from "@calcom/lib/getPaymentAppData"; import type { GetUserAvailabilityResult } from "@calcom/lib/getUserAvailability"; import type { userSelect } from "@calcom/prisma"; import type { App } from "@calcom/prisma/client"; diff --git a/packages/lib/payment/deletePayment.ts b/packages/features/bookings/lib/payment/deletePayment.ts similarity index 100% rename from packages/lib/payment/deletePayment.ts rename to packages/features/bookings/lib/payment/deletePayment.ts diff --git a/packages/lib/payment/getBooking.ts b/packages/features/bookings/lib/payment/getBooking.ts similarity index 97% rename from packages/lib/payment/getBooking.ts rename to packages/features/bookings/lib/payment/getBooking.ts index 877c848d0f..9a81952b39 100644 --- a/packages/lib/payment/getBooking.ts +++ b/packages/features/bookings/lib/payment/getBooking.ts @@ -1,5 +1,7 @@ import { workflowSelect } from "@calcom/ee/workflows/lib/getAllWorkflows"; import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses"; +import { enrichUserWithDelegationCredentials } from "@calcom/lib/delegationCredential/server"; +import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server"; import { HttpError as HttpCode } from "@calcom/lib/http-error"; import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj"; import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; @@ -10,9 +12,6 @@ import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/crede import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; import type { CalendarEvent } from "@calcom/types/Calendar"; -import { enrichUserWithDelegationCredentials } from "../delegationCredential/server"; -import { getBookerBaseUrl } from "../getBookerUrl/server"; - async function getEventType(id: number) { return prisma.eventType.findUnique({ where: { diff --git a/packages/lib/payment/handleNoShowFee.test.ts b/packages/features/bookings/lib/payment/handleNoShowFee.test.ts similarity index 100% rename from packages/lib/payment/handleNoShowFee.test.ts rename to packages/features/bookings/lib/payment/handleNoShowFee.test.ts diff --git a/packages/lib/payment/handleNoShowFee.ts b/packages/features/bookings/lib/payment/handleNoShowFee.ts similarity index 100% rename from packages/lib/payment/handleNoShowFee.ts rename to packages/features/bookings/lib/payment/handleNoShowFee.ts diff --git a/packages/lib/payment/handlePaymentRefund.ts b/packages/features/bookings/lib/payment/handlePaymentRefund.ts similarity index 100% rename from packages/lib/payment/handlePaymentRefund.ts rename to packages/features/bookings/lib/payment/handlePaymentRefund.ts diff --git a/packages/lib/payment/handleRefundError.ts b/packages/features/bookings/lib/payment/handleRefundError.ts similarity index 100% rename from packages/lib/payment/handleRefundError.ts rename to packages/features/bookings/lib/payment/handleRefundError.ts diff --git a/packages/lib/payment/processNoShowFeeOnCancellation.test.ts b/packages/features/bookings/lib/payment/processNoShowFeeOnCancellation.test.ts similarity index 100% rename from packages/lib/payment/processNoShowFeeOnCancellation.test.ts rename to packages/features/bookings/lib/payment/processNoShowFeeOnCancellation.test.ts diff --git a/packages/lib/payment/processNoShowFeeOnCancellation.ts b/packages/features/bookings/lib/payment/processNoShowFeeOnCancellation.ts similarity index 100% rename from packages/lib/payment/processNoShowFeeOnCancellation.ts rename to packages/features/bookings/lib/payment/processNoShowFeeOnCancellation.ts diff --git a/packages/lib/payment/processPaymentRefund.test.ts b/packages/features/bookings/lib/payment/processPaymentRefund.test.ts similarity index 62% rename from packages/lib/payment/processPaymentRefund.test.ts rename to packages/features/bookings/lib/payment/processPaymentRefund.test.ts index e0800bcac3..ce59e666a7 100644 --- a/packages/lib/payment/processPaymentRefund.test.ts +++ b/packages/features/bookings/lib/payment/processPaymentRefund.test.ts @@ -1,22 +1,24 @@ -import prismaMock from "../../../tests/libs/__mocks__/prismaMock"; +import prismock from "../../../../../tests/libs/__mocks__/prisma"; import { describe, it, expect, vi, beforeEach } from "vitest"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import dayjs from "@calcom/dayjs"; +import { RefundPolicy } from "@calcom/lib/payment/types"; -import { getPaymentAppData } from "../getPaymentAppData"; import { handlePaymentRefund } from "./handlePaymentRefund"; import { processPaymentRefund } from "./processPaymentRefund"; -import { RefundPolicy } from "./types"; -vi.mock("@calcom/lib/getPaymentAppData", () => ({ +vi.mock("@calcom/app-store/_utils/payments/getPaymentAppData", () => ({ getPaymentAppData: vi.fn(), })); -vi.mock("@calcom/lib/payment/handlePaymentRefund", () => ({ +vi.mock("./handlePaymentRefund", () => ({ handlePaymentRefund: vi.fn(), })); +const mockedGetPaymentAppData = vi.mocked(getPaymentAppData); + describe("processPaymentRefund", () => { const mockStartTime = new Date("2025-01-01T10:00:00Z"); @@ -53,19 +55,29 @@ describe("processPaymentRefund", () => { refundDaysCount: 3, }; - const mockPaymentAppCredentials = [ - { - key: "key1", - appId: "123", - app: { - categories: ["category1"], - dirName: "app1", - }, - }, - ]; + const mockApp = { + id: "123", + slug: "stripe", + dirName: "app1", + categories: ["payment"], + keys: {}, + enabled: true, + }; - beforeEach(() => { + const mockCredential = { + id: 1, + key: "key1", + appId: "123", + userId: 1, + teamId: null, + type: "stripe_payment", + invalid: false, + }; + + beforeEach(async () => { vi.clearAllMocks(); + await prismock.credential.deleteMany(); + await prismock.app.deleteMany(); }); it("should not process refund if no teamId or eventType owner", async () => { @@ -80,14 +92,15 @@ describe("processPaymentRefund", () => { }); it("should not process refund if refund policy is NEVER", async () => { - (getPaymentAppData as any).mockReturnValueOnce({ ...mockAppData, refundPolicy: RefundPolicy.NEVER }); + mockedGetPaymentAppData.mockReturnValueOnce({ ...mockAppData, refundPolicy: RefundPolicy.NEVER }); await processPaymentRefund({ booking: mockBooking, teamId: 1 }); expect(handlePaymentRefund).not.toHaveBeenCalled(); }); it("should process refund if refund policy is DAYS and within refund window", async () => { - (getPaymentAppData as any).mockReturnValueOnce(mockAppData); - prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials); + mockedGetPaymentAppData.mockReturnValueOnce(mockAppData); + await prismock.app.create({ data: mockApp }); + await prismock.credential.create({ data: mockCredential }); const mockNow = dayjs(mockStartTime).subtract(8, "days").toDate(); vi.useFakeTimers(); @@ -95,12 +108,19 @@ describe("processPaymentRefund", () => { await processPaymentRefund({ booking: mockBooking, teamId: 1 }); - expect(handlePaymentRefund).toHaveBeenCalledWith(1, mockPaymentAppCredentials[0]); + expect(handlePaymentRefund).toHaveBeenCalledWith( + 1, + expect.objectContaining({ + key: "key1", + appId: "123", + }) + ); }); it("should not process refund if past the refund deadline", async () => { - (getPaymentAppData as any).mockReturnValueOnce(mockAppData); - prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials); + mockedGetPaymentAppData.mockReturnValueOnce(mockAppData); + await prismock.app.create({ data: mockApp }); + await prismock.credential.create({ data: mockCredential }); const mockNow = dayjs(mockStartTime).subtract(2, "days").toDate(); @@ -113,8 +133,9 @@ describe("processPaymentRefund", () => { }); it("should process refund if business days are considered and before deadline", async () => { - (getPaymentAppData as any).mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false }); - prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials); + mockedGetPaymentAppData.mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false }); + await prismock.app.create({ data: mockApp }); + await prismock.credential.create({ data: mockCredential }); // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore @@ -125,12 +146,19 @@ describe("processPaymentRefund", () => { await processPaymentRefund({ booking: mockBooking, teamId: 1 }); - expect(handlePaymentRefund).toHaveBeenCalledWith(1, mockPaymentAppCredentials[0]); + expect(handlePaymentRefund).toHaveBeenCalledWith( + 1, + expect.objectContaining({ + key: "key1", + appId: "123", + }) + ); }); it("should not process refund if business days are considered and after deadline", async () => { - (getPaymentAppData as any).mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false }); - prismaMock.credential.findMany.mockResolvedValueOnce(mockPaymentAppCredentials); + mockedGetPaymentAppData.mockReturnValueOnce({ ...mockAppData, refundCountCalendarDays: false }); + await prismock.app.create({ data: mockApp }); + await prismock.credential.create({ data: mockCredential }); const mockNow = dayjs(mockStartTime).subtract(3, "days").toDate(); @@ -143,8 +171,7 @@ describe("processPaymentRefund", () => { }); it("should not process refund if paymentAppCredential is not found", async () => { - (getPaymentAppData as any).mockReturnValueOnce(mockAppData); - prismaMock.credential.findMany.mockResolvedValueOnce([]); + mockedGetPaymentAppData.mockReturnValueOnce(mockAppData); await processPaymentRefund({ booking: mockBooking, teamId: 1 }); expect(handlePaymentRefund).not.toHaveBeenCalled(); diff --git a/packages/lib/payment/processPaymentRefund.ts b/packages/features/bookings/lib/payment/processPaymentRefund.ts similarity index 91% rename from packages/lib/payment/processPaymentRefund.ts rename to packages/features/bookings/lib/payment/processPaymentRefund.ts index 095cca042c..cb7d1935c3 100644 --- a/packages/lib/payment/processPaymentRefund.ts +++ b/packages/features/bookings/lib/payment/processPaymentRefund.ts @@ -1,12 +1,11 @@ +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import dayjs from "@calcom/dayjs"; +import { handlePaymentRefund } from "@calcom/features/bookings/lib/payment/handlePaymentRefund"; +import { RefundPolicy } from "@calcom/lib/payment/types"; import prisma from "@calcom/prisma"; import type { Payment, Prisma } from "@calcom/prisma/client"; import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; -import { getPaymentAppData } from "../getPaymentAppData"; -import { handlePaymentRefund } from "./handlePaymentRefund"; -import { RefundPolicy } from "./types"; - export const processPaymentRefund = async ({ booking, teamId, diff --git a/packages/lib/payment/shouldChargeNoShowCancellationFee.test.ts b/packages/features/bookings/lib/payment/shouldChargeNoShowCancellationFee.test.ts similarity index 100% rename from packages/lib/payment/shouldChargeNoShowCancellationFee.test.ts rename to packages/features/bookings/lib/payment/shouldChargeNoShowCancellationFee.test.ts diff --git a/packages/lib/payment/shouldChargeNoShowCancellationFee.ts b/packages/features/bookings/lib/payment/shouldChargeNoShowCancellationFee.ts similarity index 100% rename from packages/lib/payment/shouldChargeNoShowCancellationFee.ts rename to packages/features/bookings/lib/payment/shouldChargeNoShowCancellationFee.ts diff --git a/packages/features/credentials/handleDeleteCredential.ts b/packages/features/credentials/handleDeleteCredential.ts index 6111aaced3..66963ba245 100644 --- a/packages/features/credentials/handleDeleteCredential.ts +++ b/packages/features/credentials/handleDeleteCredential.ts @@ -9,12 +9,12 @@ import { import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils"; import { sendCancelledEmailsAndSMS } from "@calcom/emails"; import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses"; +import { deletePayment } from "@calcom/features/bookings/lib/payment/deletePayment"; import { deleteWebhookScheduledTriggers } from "@calcom/features/webhooks/lib/scheduleTrigger"; import { buildNonDelegationCredential } from "@calcom/lib/delegationCredential/server"; import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj"; import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; import { DailyLocationType } from "@calcom/lib/location"; -import { deletePayment } from "@calcom/lib/payment/deletePayment"; import { getTranslation } from "@calcom/lib/server/i18n"; import { bookingMinimalSelect, prisma } from "@calcom/prisma"; import type { Prisma } from "@calcom/prisma/client"; diff --git a/packages/features/ee/payments/api/webhook.ts b/packages/features/ee/payments/api/webhook.ts index 40ef94a325..65aec9de05 100644 --- a/packages/features/ee/payments/api/webhook.ts +++ b/packages/features/ee/payments/api/webhook.ts @@ -8,6 +8,7 @@ import { sendAttendeeRequestEmailAndSMS, sendOrganizerRequestEmail } from "@calc import { doesBookingRequireConfirmation } from "@calcom/features/bookings/lib/doesBookingRequireConfirmation"; import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials"; import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation"; +import { getBooking } from "@calcom/features/bookings/lib/payment/getBooking"; import stripe from "@calcom/features/ee/payments/server/stripe"; import { getPlatformParams } from "@calcom/features/platform-oauth-client/get-platform-params"; import { PlatformOAuthClientRepository } from "@calcom/features/platform-oauth-client/platform-oauth-client.repository"; @@ -16,7 +17,6 @@ import { IS_PRODUCTION } from "@calcom/lib/constants"; import { getErrorFromUnknown } from "@calcom/lib/errors"; import { HttpError as HttpCode } from "@calcom/lib/http-error"; import logger from "@calcom/lib/logger"; -import { getBooking } from "@calcom/lib/payment/getBooking"; import { safeStringify } from "@calcom/lib/safeStringify"; import { prisma } from "@calcom/prisma"; import type { Prisma } from "@calcom/prisma/client"; diff --git a/packages/features/eventtypes/components/EventTypeDescription.tsx b/packages/features/eventtypes/components/EventTypeDescription.tsx index e01835b38a..1e64591740 100644 --- a/packages/features/eventtypes/components/EventTypeDescription.tsx +++ b/packages/features/eventtypes/components/EventTypeDescription.tsx @@ -1,9 +1,9 @@ import { useMemo } from "react"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils"; import { Price } from "@calcom/features/bookings/components/event-meta/Price"; import { PriceIcon } from "@calcom/features/bookings/components/event-meta/PriceIcon"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML"; diff --git a/packages/features/eventtypes/components/tabs/instant/EventInstantTab.tsx b/packages/features/eventtypes/components/tabs/instant/EventInstantTab.tsx index 99318ab73a..18550c8be7 100644 --- a/packages/features/eventtypes/components/tabs/instant/EventInstantTab.tsx +++ b/packages/features/eventtypes/components/tabs/instant/EventInstantTab.tsx @@ -1,6 +1,6 @@ +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils"; import type { EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import InstantEventController from "./InstantEventController"; diff --git a/packages/features/eventtypes/components/tabs/recurring/EventRecurringTab.tsx b/packages/features/eventtypes/components/tabs/recurring/EventRecurringTab.tsx index b13d1387cf..1bd636945c 100644 --- a/packages/features/eventtypes/components/tabs/recurring/EventRecurringTab.tsx +++ b/packages/features/eventtypes/components/tabs/recurring/EventRecurringTab.tsx @@ -1,5 +1,5 @@ +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import type { RecurringEventControllerProps } from "./RecurringEventController"; import RecurringEventController from "./RecurringEventController"; diff --git a/packages/platform/atoms/event-types/hooks/usePlatformTabsNavigations.tsx b/packages/platform/atoms/event-types/hooks/usePlatformTabsNavigations.tsx index 28498d022a..e323bf4eef 100644 --- a/packages/platform/atoms/event-types/hooks/usePlatformTabsNavigations.tsx +++ b/packages/platform/atoms/event-types/hooks/usePlatformTabsNavigations.tsx @@ -6,9 +6,9 @@ import type { TFunction } from "i18next"; import { useMemo, useState, useEffect } from "react"; import type { UseFormReturn } from "react-hook-form"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager"; import type { EventTypeSetupProps, FormValues } from "@calcom/features/eventtypes/lib/types"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { VerticalTabItemProps } from "@calcom/ui/components/navigation"; diff --git a/packages/platform/atoms/event-types/hooks/useTabsNavigations.tsx b/packages/platform/atoms/event-types/hooks/useTabsNavigations.tsx index 6dec69eeee..c36cbaaefc 100644 --- a/packages/platform/atoms/event-types/hooks/useTabsNavigations.tsx +++ b/packages/platform/atoms/event-types/hooks/useTabsNavigations.tsx @@ -5,6 +5,7 @@ import type { TFunction } from "i18next"; import { useMemo } from "react"; import type { UseFormReturn } from "react-hook-form"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils"; import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager"; import type { Workflow } from "@calcom/features/ee/workflows/lib/types"; @@ -14,7 +15,6 @@ import type { FormValues, EventTypeApps, } from "@calcom/features/eventtypes/lib/types"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { VerticalTabItemProps } from "@calcom/ui/components/navigation"; diff --git a/packages/platform/atoms/event-types/payments/PaymentForm.tsx b/packages/platform/atoms/event-types/payments/PaymentForm.tsx index e1ede70621..78fb19f265 100644 --- a/packages/platform/atoms/event-types/payments/PaymentForm.tsx +++ b/packages/platform/atoms/event-types/payments/PaymentForm.tsx @@ -1,12 +1,12 @@ import React, { Suspense } from "react"; +import { getPaymentAppData } from "@calcom/app-store/_utils/payments/getPaymentAppData"; import { getSuccessPageLocationMessage } from "@calcom/app-store/locations"; import dayjs from "@calcom/dayjs"; import { PayIcon } from "@calcom/features/bookings/components/event-meta/PayIcon"; import { Price } from "@calcom/features/bookings/components/event-meta/Price"; import type { PaymentPageProps } from "@calcom/features/ee/payments/pages/payment"; import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants"; -import { getPaymentAppData } from "@calcom/lib/getPaymentAppData"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { isBrowserLocale24h } from "@calcom/lib/timeFormat"; import { CURRENT_TIMEZONE } from "@calcom/lib/timezoneConstants"; diff --git a/packages/platform/libraries/app-store.ts b/packages/platform/libraries/app-store.ts index 7912bd1f12..71e8764c8f 100644 --- a/packages/platform/libraries/app-store.ts +++ b/packages/platform/libraries/app-store.ts @@ -1,6 +1,6 @@ +import getEnabledAppsFromCredentials from "@calcom/app-store/_utils/getEnabledAppsFromCredentials"; import getApps from "@calcom/app-store/utils"; import handleDeleteCredential from "@calcom/features/credentials/handleDeleteCredential"; -import getEnabledAppsFromCredentials from "@calcom/lib/apps/getEnabledAppsFromCredentials"; import addDelegationCredential from "@calcom/trpc/server/routers/viewer/delegationCredential/add.handler"; export type { TDependencyData } from "@calcom/app-store/_appRegistry"; diff --git a/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts b/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts index 86228e6e50..fe32c113f6 100644 --- a/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts @@ -5,6 +5,7 @@ import { getAllCredentialsIncludeServiceAccountKey } from "@calcom/features/book import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses"; import { handleConfirmation } from "@calcom/features/bookings/lib/handleConfirmation"; import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger"; +import { processPaymentRefund } from "@calcom/features/bookings/lib/payment/processPaymentRefund"; import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows"; import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks"; import type { EventPayloadType, EventTypeInfo } from "@calcom/features/webhooks/lib/sendPayload"; @@ -13,7 +14,6 @@ import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId"; import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType"; import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj"; import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; -import { processPaymentRefund } from "@calcom/lib/payment/processPaymentRefund"; import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/lib/server/getUsersCredentials"; import { getTranslation } from "@calcom/lib/server/i18n"; import { WorkflowService } from "@calcom/lib/server/service/workflows"; diff --git a/packages/trpc/server/routers/viewer/payments/chargeCard.handler.ts b/packages/trpc/server/routers/viewer/payments/chargeCard.handler.ts index 2f2bb1d005..f221cd0d9a 100644 --- a/packages/trpc/server/routers/viewer/payments/chargeCard.handler.ts +++ b/packages/trpc/server/routers/viewer/payments/chargeCard.handler.ts @@ -1,4 +1,4 @@ -import { handleNoShowFee } from "@calcom/lib/payment/handleNoShowFee"; +import { handleNoShowFee } from "@calcom/features/bookings/lib/payment/handleNoShowFee"; import { BookingRepository } from "@calcom/lib/server/repository/booking"; import type { PrismaClient } from "@calcom/prisma"; diff --git a/yarn.lock b/yarn.lock index 1db0bafde6..8e20d4e43f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2715,7 +2715,7 @@ __metadata: "@axiomhq/winston": ^1.2.0 "@calcom/platform-constants": "*" "@calcom/platform-enums": "*" - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.358" + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.359" "@calcom/platform-types": "*" "@calcom/platform-utils": "*" "@calcom/prisma": "*" @@ -3775,13 +3775,13 @@ __metadata: languageName: unknown linkType: soft -"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.358": - version: 0.0.358 - resolution: "@calcom/platform-libraries@npm:0.0.358" +"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.359": + version: 0.0.359 + resolution: "@calcom/platform-libraries@npm:0.0.359" dependencies: "@calcom/features": "*" "@calcom/lib": "*" - checksum: 2a3436a24c62c38aa1299237cc2c650826a3cfc9cbffa5cc2f37244abed13dc0f55dbd314037e16af3168b9e7bfa4b62abf20aee00654e8aa24ab4bc7e76c642 + checksum: 265d73c95334e34d076406d943ba6e80cff0037b4cf4620ed86519d41ac8e24e643000b84773c1f17cece28c4f50bd1cd70a0306764908248a55af49b44f054f languageName: node linkType: hard