@@ -138,68 +138,28 @@ export const stripePaymentService = {
138138 console . log ( '- success_url:' , successUrl ) ;
139139 console . log ( '- cancel_url:' , cancelUrl ) ;
140140
141- // Try to create a real Stripe checkout session first
142- let session ;
143- try {
144- // Set a timeout for the Stripe API call
145- const timeoutPromise = new Promise ( ( _ , reject ) => {
146- setTimeout ( ( ) => reject ( new Error ( 'Stripe API call timed out after 5 seconds' ) ) , 5000 ) ;
147- } ) ;
148-
149- // Create the checkout session with Stripe
150- const sessionPromise = stripe . checkout . sessions . create ( {
151- customer_email : email ,
152- client_reference_id : userId ,
153- payment_method_types : [ 'card' ] ,
154- line_items : [
155- {
156- price : priceId ,
157- quantity : 1 ,
158- } ,
159- ] ,
160- mode : 'subscription' ,
161- success_url : successUrl ,
162- cancel_url : cancelUrl ,
163- metadata : {
164- user_id : userId ,
165- email,
166- plan
167- }
168- } ) ;
169-
170- // Race the checkout session creation against the timeout
171- session = await Promise . race ( [ sessionPromise , timeoutPromise ] ) ;
172- console . log ( `Stripe payment service: Created real checkout session ${ session . id } ` ) ;
173- } catch ( stripeError ) {
174- // If Stripe API call fails or times out, create a mock session instead
175- console . error ( 'Stripe payment service: Error creating Stripe checkout session:' , stripeError ) ;
176- console . log ( 'Stripe payment service: Falling back to mock checkout session' ) ;
177-
178- // Create a mock session ID
179- const sessionId = `cs_mock_${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) } ` ;
180-
181- // Add query parameters to the success URL
182- const separator = successUrl . includes ( '?' ) ? '&' : '?' ;
183- const checkoutUrl = `${ successUrl } ${ separator } session_id=${ sessionId } &mock=true` ;
184-
185- console . log ( `Stripe payment service: Created mock checkout session ${ sessionId } ` ) ;
186- console . log ( `Stripe payment service: Checkout URL: ${ checkoutUrl } ` ) ;
187-
188- // Create a mock session object
189- session = {
190- id : sessionId ,
191- url : checkoutUrl ,
192- object : 'checkout.session' ,
193- client_reference_id : userId ,
194- customer_email : email ,
195- metadata : {
196- user_id : userId ,
197- email,
198- plan,
199- mock : 'true'
200- }
201- } ;
202- }
141+ // Create the checkout session with Stripe
142+ const session = await stripe . checkout . sessions . create ( {
143+ customer_email : email ,
144+ client_reference_id : userId ,
145+ payment_method_types : [ 'card' ] ,
146+ line_items : [
147+ {
148+ price : priceId ,
149+ quantity : 1 ,
150+ } ,
151+ ] ,
152+ mode : 'subscription' ,
153+ success_url : successUrl ,
154+ cancel_url : cancelUrl ,
155+ metadata : {
156+ user_id : userId ,
157+ email,
158+ plan
159+ }
160+ } ) ;
161+
162+ console . log ( `Stripe payment service: Created checkout session ${ session . id } ` ) ;
203163
204164 // Store the checkout session in Supabase
205165 const { error : sessionError } = await supabase
0 commit comments