File tree 2 files changed +22
-11
lines changed
packages/trpc/server/routers/publicViewer
2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 1
1
import stripe from "@calcom/app-store/stripepayment/lib/server" ;
2
2
3
3
import type { TStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema" ;
4
+ import { ZStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema" ;
4
5
5
6
type StripeCheckoutSessionOptions = {
6
7
input : TStripeCheckoutSessionInputSchema ;
@@ -9,14 +10,9 @@ type StripeCheckoutSessionOptions = {
9
10
export const stripeCheckoutSessionHandler = async ( { input } : StripeCheckoutSessionOptions ) => {
10
11
const { checkoutSessionId, stripeCustomerId } = input ;
11
12
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 ) ;
16
15
17
- if ( checkoutSessionId && stripeCustomerId ) {
18
- throw new Error ( "Both checkoutSessionId and stripeCustomerId provided" ) ;
19
- }
20
16
let customerId : string ;
21
17
let isPremiumUsername = false ;
22
18
let hasPaymentFailed = false ;
Original file line number Diff line number Diff line change 1
1
import { z } from "zod" ;
2
2
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
+ } ) ;
7
22
8
23
export type TStripeCheckoutSessionInputSchema = z . infer < typeof ZStripeCheckoutSessionInputSchema > ;
You can’t perform that action at this time.
0 commit comments