(event: Stripe.Event)
| 35 | * Used to reject org billing events while keeping personal billing working. |
| 36 | */ |
| 37 | export 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 | } |
no test coverage detected