File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { MAXIMUM_TOP_UP_AMOUNT, MINIMUM_TOP_UP_AMOUNT } from '@/lib/constants';
66import { isValidReturnUrl } from '@/lib/payment-return-url' ;
77import { captureException } from '@sentry/nextjs' ;
88import { getOrCreateStripeCustomerIdForOrganization } from '@/lib/organizations/organization-billing' ;
9+ import { getAuthorizedOrgContext } from '@/lib/organizations/organization-auth' ;
910
1011/**
1112 * NOTE: Crypto payment support (Coinbase Commerce) was removed in January 2026.
@@ -63,10 +64,16 @@ export async function POST(request: NextRequest): Promise<NextResponse<unknown>>
6364 return NextResponse . json ( { error : 'Invalid org id' } , { status : 400 } ) ;
6465 }
6566
66- const stripeCustomerId = organizationId
67- ? // TODO(bmc): should we check user permission to organization here?
68- await getOrCreateStripeCustomerIdForOrganization ( organizationId )
69- : currentUser . stripe_customer_id ;
67+ let stripeCustomerId : string | null | undefined ;
68+ if ( organizationId ) {
69+ const orgContext = await getAuthorizedOrgContext ( organizationId ) ;
70+ if ( ! orgContext . success ) {
71+ return orgContext . nextResponse ;
72+ }
73+ stripeCustomerId = await getOrCreateStripeCustomerIdForOrganization ( organizationId ) ;
74+ } else {
75+ stripeCustomerId = currentUser . stripe_customer_id ;
76+ }
7077
7178 const cancelPathRaw = searchParams . get ( 'cancel-path' ) ;
7279 const cancelPath = cancelPathRaw && isValidReturnUrl ( cancelPathRaw ) ? cancelPathRaw : null ;
You can’t perform that action at this time.
0 commit comments