MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / isOrgBillingEvent

Function isOrgBillingEvent

web/src/app/api/stripe/webhook/_helpers.ts:37–67  ·  view source on GitHub ↗
(event: Stripe.Event)

Source from the content-addressed store, hash-verified

35 * Used to reject org billing events while keeping personal billing working.
36 */
37export async function isOrgBillingEvent(event: Stripe.Event): Promise<boolean> {
38 const eventData = event.data.object as unknown as Record<string, unknown>
39 const metadata = (eventData.metadata || {}) as Record<string, string>
40
41 // Check metadata for organization markers
42 if (metadata.organization_id || metadata.organizationId) {
43 return true
44 }
45 if (metadata.grantType === 'organization_purchase') {
46 return true
47 }
48
49 // For invoice events, check if customer belongs to an org
50 // (metadata.organizationId is already checked above in the generic metadata check)
51 if (event.type.startsWith('invoice.')) {
52 const customerId = eventData.customer
53 if (customerId && typeof customerId === 'string') {
54 return await isOrgCustomer(customerId)
55 }
56 }
57
58 // For subscription events, check if customer is an org
59 if (event.type.startsWith('customer.subscription.')) {
60 const customerId = eventData.customer
61 if (customerId && typeof customerId === 'string') {
62 return await isOrgCustomer(customerId)
63 }
64 }
65
66 return false
67}

Callers 2

webhookHandlerFunction · 0.90

Calls 1

isOrgCustomerFunction · 0.85

Tested by

no test coverage detected