refactor: Remove StripeService from @calcom/lib and define it in @calcom/trpc (#23655)
* remove packages/lib/server/stripe * simplify metadata * define business logic directly in trpc handler
This commit is contained in:
1 parent
fe7fd8bc79
commit
03bc8db64a
3 files changed
+13
-22
No files matched your search
@@ -2,8 +2,6 @@ import type { PageProps as _PageProps } from "app/_types";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { z } from "zod";
|
||||
|
||||
import { StripeService } from "@calcom/lib/server/service/stripe";
|
||||
|
||||
import VerifyPage from "~/auth/verify-view";
|
||||
|
||||
const querySchema = z.object({
|
||||
@@ -14,18 +12,10 @@ const querySchema = z.object({
|
||||
|
||||
export const generateMetadata = async ({ params, searchParams }: _PageProps) => {
|
||||
const p = { ...(await params), ...(await searchParams) };
|
||||
const { sessionId, stripeCustomerId } = querySchema.parse(p);
|
||||
|
||||
const data = await StripeService.getCheckoutSession({
|
||||
stripeCustomerId,
|
||||
checkoutSessionId: sessionId,
|
||||
});
|
||||
|
||||
const { hasPaymentFailed } = data;
|
||||
const { sessionId } = querySchema.parse(p);
|
||||
|
||||
return await _generateMetadata(
|
||||
() =>
|
||||
hasPaymentFailed ? "Your payment failed" : sessionId ? "Payment successful!" : `Verify your email`,
|
||||
() => (sessionId ? "Payment Page" : `Verify your email`),
|
||||
() => "",
|
||||
undefined,
|
||||
undefined,
|
||||
|
||||
+6
-8
@@ -1,16 +1,14 @@
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import {
|
||||
ZStripeCheckoutSessionInputSchema,
|
||||
type TStripeCheckoutSessionInputSchema,
|
||||
} from "@calcom/trpc/server/routers/publicViewer/stripeCheckoutSession.schema";
|
||||
|
||||
type StripeCheckoutSessionInput = {
|
||||
checkoutSessionId?: string;
|
||||
stripeCustomerId?: string;
|
||||
};
|
||||
|
||||
export class StripeService {
|
||||
static async getCheckoutSession(input: TStripeCheckoutSessionInputSchema) {
|
||||
static async getCheckoutSession(input: StripeCheckoutSessionInput) {
|
||||
const { checkoutSessionId, stripeCustomerId } = input;
|
||||
|
||||
// Moved the following data checks to superRefine
|
||||
ZStripeCheckoutSessionInputSchema.parse(input);
|
||||
|
||||
let customerId: string;
|
||||
let isPremiumUsername = false;
|
||||
let hasPaymentFailed = false;
|
||||
@@ -1,5 +1,6 @@
|
||||
import { StripeService } from "@calcom/lib/server/service/stripe";
|
||||
import { StripeService } from "@calcom/features/ee/payments/server/stripe-service";
|
||||
|
||||
import { ZStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
|
||||
import type { TStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
|
||||
|
||||
type StripeCheckoutSessionOptions = {
|
||||
@@ -7,7 +8,9 @@ type StripeCheckoutSessionOptions = {
|
||||
};
|
||||
|
||||
export const stripeCheckoutSessionHandler = async ({ input }: StripeCheckoutSessionOptions) => {
|
||||
return await StripeService.getCheckoutSession(input);
|
||||
const parsedInput = ZStripeCheckoutSessionInputSchema.parse(input);
|
||||
|
||||
return await StripeService.getCheckoutSession(parsedInput);
|
||||
};
|
||||
|
||||
export default stripeCheckoutSessionHandler;
|
||||
Reference in new issue
Block a user