@@ -14,7 +14,7 @@ import { encrypt } from "@sourcebot/crypto"
14
14
import { getConnection } from "./data/connection" ;
15
15
import { ConnectionSyncStatus , Prisma , Invite } from "@sourcebot/db" ;
16
16
import { headers } from "next/headers"
17
- import { stripe } from "@/lib/stripe"
17
+ import { getStripe } from "@/lib/stripe"
18
18
import { getUser } from "@/data/user" ;
19
19
import { Session } from "next-auth" ;
20
20
import { STRIPE_PRODUCT_ID } from "@/lib/environment" ;
@@ -339,6 +339,7 @@ export const redeemInvite = async (invite: Invite, userId: string): Promise<{ su
339
339
const existingSeatCount = subscription . items . data [ 0 ] . quantity ;
340
340
const newSeatCount = ( existingSeatCount || 1 ) + 1
341
341
342
+ const stripe = getStripe ( ) ;
342
343
await stripe . subscriptionItems . update (
343
344
subscription . items . data [ 0 ] . id ,
344
345
{
@@ -424,6 +425,7 @@ export const setupInitialStripeCustomer = async (name: string, domain: string) =
424
425
return "" ;
425
426
}
426
427
428
+ const stripe = getStripe ( ) ;
427
429
const origin = ( await headers ( ) ) . get ( 'origin' )
428
430
429
431
// @nocheckin
@@ -489,6 +491,7 @@ export const getSubscriptionCheckoutRedirect = async (domain: string) =>
489
491
} ) ;
490
492
const numOrgMembers = orgMembers . length ;
491
493
494
+ const stripe = getStripe ( ) ;
492
495
const origin = ( await headers ( ) ) . get ( 'origin' )
493
496
const prices = await stripe . prices . list ( {
494
497
product : STRIPE_PRODUCT_ID ,
@@ -520,6 +523,7 @@ export const getSubscriptionCheckoutRedirect = async (domain: string) =>
520
523
)
521
524
522
525
export async function fetchStripeSession ( sessionId : string ) {
526
+ const stripe = getStripe ( ) ;
523
527
const stripeSession = await stripe . checkout . sessions . retrieve ( sessionId ) ;
524
528
return stripeSession ;
525
529
}
@@ -537,6 +541,7 @@ export const getCustomerPortalSessionLink = async (domain: string): Promise<stri
537
541
return notFound ( ) ;
538
542
}
539
543
544
+ const stripe = getStripe ( ) ;
540
545
const origin = ( await headers ( ) ) . get ( 'origin' )
541
546
const portalSession = await stripe . billingPortal . sessions . create ( {
542
547
customer : org . stripeCustomerId as string ,
@@ -558,6 +563,7 @@ export const fetchSubscription = (domain: string): Promise<Stripe.Subscription |
558
563
return notFound ( ) ;
559
564
}
560
565
566
+ const stripe = getStripe ( ) ;
561
567
const subscriptions = await stripe . subscriptions . list ( {
562
568
customer : org . stripeCustomerId
563
569
} ) ;
@@ -624,6 +630,7 @@ export const removeMember = async (memberId: string, domain: string): Promise<{
624
630
const existingSeatCount = subscription . items . data [ 0 ] . quantity ;
625
631
const newSeatCount = ( existingSeatCount || 1 ) - 1 ;
626
632
633
+ const stripe = getStripe ( ) ;
627
634
await stripe . subscriptionItems . update (
628
635
subscription . items . data [ 0 ] . id ,
629
636
{
0 commit comments