Skip to content

Commit 03bc8db

Browse files
authored
refactor: Remove StripeService from @calcom/lib and define it in @calcom/trpc (calcom#23655)
* remove packages/lib/server/stripe * simplify metadata * define business logic directly in trpc handler
1 parent fe7fd8b commit 03bc8db

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

apps/web/app/(use-page-wrapper)/auth/verify/page.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import type { PageProps as _PageProps } from "app/_types";
22
import { _generateMetadata } from "app/_utils";
33
import { z } from "zod";
44

5-
import { StripeService } from "@calcom/lib/server/service/stripe";
6-
75
import VerifyPage from "~/auth/verify-view";
86

97
const querySchema = z.object({
@@ -14,18 +12,10 @@ const querySchema = z.object({
1412

1513
export const generateMetadata = async ({ params, searchParams }: _PageProps) => {
1614
const p = { ...(await params), ...(await searchParams) };
17-
const { sessionId, stripeCustomerId } = querySchema.parse(p);
18-
19-
const data = await StripeService.getCheckoutSession({
20-
stripeCustomerId,
21-
checkoutSessionId: sessionId,
22-
});
23-
24-
const { hasPaymentFailed } = data;
15+
const { sessionId } = querySchema.parse(p);
2516

2617
return await _generateMetadata(
27-
() =>
28-
hasPaymentFailed ? "Your payment failed" : sessionId ? "Payment successful!" : `Verify your email`,
18+
() => (sessionId ? "Payment Page" : `Verify your email`),
2919
() => "",
3020
undefined,
3121
undefined,

packages/lib/server/service/stripe.ts renamed to packages/features/ee/payments/server/stripe-service.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import stripe from "@calcom/features/ee/payments/server/stripe";
2-
import {
3-
ZStripeCheckoutSessionInputSchema,
4-
type TStripeCheckoutSessionInputSchema,
5-
} from "@calcom/trpc/server/routers/publicViewer/stripeCheckoutSession.schema";
2+
3+
type StripeCheckoutSessionInput = {
4+
checkoutSessionId?: string;
5+
stripeCustomerId?: string;
6+
};
67

78
export class StripeService {
8-
static async getCheckoutSession(input: TStripeCheckoutSessionInputSchema) {
9+
static async getCheckoutSession(input: StripeCheckoutSessionInput) {
910
const { checkoutSessionId, stripeCustomerId } = input;
1011

11-
// Moved the following data checks to superRefine
12-
ZStripeCheckoutSessionInputSchema.parse(input);
13-
1412
let customerId: string;
1513
let isPremiumUsername = false;
1614
let hasPaymentFailed = false;
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { StripeService } from "@calcom/lib/server/service/stripe";
1+
import { StripeService } from "@calcom/features/ee/payments/server/stripe-service";
22

3+
import { ZStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
34
import type { TStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
45

56
type StripeCheckoutSessionOptions = {
67
input: TStripeCheckoutSessionInputSchema;
78
};
89

910
export const stripeCheckoutSessionHandler = async ({ input }: StripeCheckoutSessionOptions) => {
10-
return await StripeService.getCheckoutSession(input);
11+
const parsedInput = ZStripeCheckoutSessionInputSchema.parse(input);
12+
13+
return await StripeService.getCheckoutSession(parsedInput);
1114
};
1215

1316
export default stripeCheckoutSessionHandler;

0 commit comments

Comments
 (0)