( invoice: Stripe.Invoice, stripeSubscriptionId: string )
| 35 | const logger = createLogger('StripeInvoiceWebhooks') |
| 36 | |
| 37 | function getSubscriptionLinePeriod( |
| 38 | invoice: Stripe.Invoice, |
| 39 | stripeSubscriptionId: string |
| 40 | ): { periodStart: Date; periodEnd: Date } | null { |
| 41 | const subscriptionLine = invoice.lines?.data?.find( |
| 42 | (line) => |
| 43 | line.parent?.type === 'subscription_item_details' && |
| 44 | line.parent.subscription_item_details?.subscription === stripeSubscriptionId |
| 45 | ) |
| 46 | |
| 47 | if (!subscriptionLine?.period?.start || !subscriptionLine.period.end) { |
| 48 | return null |
| 49 | } |
| 50 | |
| 51 | return { |
| 52 | periodStart: new Date(subscriptionLine.period.start * 1000), |
| 53 | periodEnd: new Date(subscriptionLine.period.end * 1000), |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | const METADATA_SUBSCRIPTION_INVOICE_TYPES = new Set<string>([ |
| 58 | 'overage_billing', |
no outgoing calls
no test coverage detected