Skip to content

Commit b552bf6

Browse files
Fix: #8528 Moved the data checks to superRefine (#8749)
* Fix: #8528 Moved the data checks to superRefine * Resolved lint isseu * Updated to parse from safeParse * added new line --------- Co-authored-by: Omar López <zomars@me.com>
1 parent 82d3c43 commit b552bf6

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

packages/trpc/server/routers/publicViewer/stripeCheckoutSession.handler.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import stripe from "@calcom/app-store/stripepayment/lib/server";
22

33
import type { TStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
4+
import { ZStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
45

56
type StripeCheckoutSessionOptions = {
67
input: TStripeCheckoutSessionInputSchema;
@@ -9,14 +10,9 @@ type StripeCheckoutSessionOptions = {
910
export const stripeCheckoutSessionHandler = async ({ input }: StripeCheckoutSessionOptions) => {
1011
const { checkoutSessionId, stripeCustomerId } = input;
1112

12-
// TODO: Move the following data checks to superRefine
13-
if (!checkoutSessionId && !stripeCustomerId) {
14-
throw new Error("Missing checkoutSessionId or stripeCustomerId");
15-
}
13+
// Moved the following data checks to superRefine
14+
const validationResult = ZStripeCheckoutSessionInputSchema.parse(input);
1615

17-
if (checkoutSessionId && stripeCustomerId) {
18-
throw new Error("Both checkoutSessionId and stripeCustomerId provided");
19-
}
2016
let customerId: string;
2117
let isPremiumUsername = false;
2218
let hasPaymentFailed = false;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
import { z } from "zod";
22

3-
export const ZStripeCheckoutSessionInputSchema = z.object({
4-
stripeCustomerId: z.string().optional(),
5-
checkoutSessionId: z.string().optional(),
6-
});
3+
export const ZStripeCheckoutSessionInputSchema = z
4+
.object({
5+
stripeCustomerId: z.string().optional(),
6+
checkoutSessionId: z.string().optional(),
7+
})
8+
.superRefine((arg, ctx) => {
9+
if (!arg.checkoutSessionId && !arg.stripeCustomerId) {
10+
ctx.addIssue({
11+
code: z.ZodIssueCode.custom,
12+
message: "Missing checkoutSessionId or stripeCustomerId",
13+
});
14+
}
15+
if (arg.checkoutSessionId && arg.stripeCustomerId) {
16+
ctx.addIssue({
17+
code: z.ZodIssueCode.custom,
18+
message: "Both checkoutSessionId and stripeCustomerId provided",
19+
});
20+
}
21+
});
722

823
export type TStripeCheckoutSessionInputSchema = z.infer<typeof ZStripeCheckoutSessionInputSchema>;

0 commit comments

Comments
 (0)