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