* 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>pull/8871/head^2
parent
82d3c4370d
commit
b552bf6956
|
@ -1,6 +1,7 @@
|
|||
import stripe from "@calcom/app-store/stripepayment/lib/server";
|
||||
|
||||
import type { TStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
|
||||
import { ZStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";
|
||||
|
||||
type StripeCheckoutSessionOptions = {
|
||||
input: TStripeCheckoutSessionInputSchema;
|
||||
|
@ -9,14 +10,9 @@ type StripeCheckoutSessionOptions = {
|
|||
export const stripeCheckoutSessionHandler = async ({ input }: StripeCheckoutSessionOptions) => {
|
||||
const { checkoutSessionId, stripeCustomerId } = input;
|
||||
|
||||
// TODO: Move the following data checks to superRefine
|
||||
if (!checkoutSessionId && !stripeCustomerId) {
|
||||
throw new Error("Missing checkoutSessionId or stripeCustomerId");
|
||||
}
|
||||
// Moved the following data checks to superRefine
|
||||
const validationResult = ZStripeCheckoutSessionInputSchema.parse(input);
|
||||
|
||||
if (checkoutSessionId && stripeCustomerId) {
|
||||
throw new Error("Both checkoutSessionId and stripeCustomerId provided");
|
||||
}
|
||||
let customerId: string;
|
||||
let isPremiumUsername = false;
|
||||
let hasPaymentFailed = false;
|
||||
|
|
|
@ -1,8 +1,23 @@
|
|||
import { z } from "zod";
|
||||
|
||||
export const ZStripeCheckoutSessionInputSchema = z.object({
|
||||
export const ZStripeCheckoutSessionInputSchema = z
|
||||
.object({
|
||||
stripeCustomerId: z.string().optional(),
|
||||
checkoutSessionId: z.string().optional(),
|
||||
})
|
||||
.superRefine((arg, ctx) => {
|
||||
if (!arg.checkoutSessionId && !arg.stripeCustomerId) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Missing checkoutSessionId or stripeCustomerId",
|
||||
});
|
||||
}
|
||||
if (arg.checkoutSessionId && arg.stripeCustomerId) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Both checkoutSessionId and stripeCustomerId provided",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export type TStripeCheckoutSessionInputSchema = z.infer<typeof ZStripeCheckoutSessionInputSchema>;
|
||||
|
|
Loading…
Reference in New Issue