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

Function handleInvoicePaid

web/src/app/api/stripe/webhook/route.ts:302–331  ·  view source on GitHub ↗
(invoice: Stripe.Invoice)

Source from the content-addressed store, hash-verified

300}
301
302async function handleInvoicePaid(invoice: Stripe.Invoice) {
303 // For regular (non-auto-topup) invoices, verify credit note exists
304 const creditNotes = await stripeServer.creditNotes.list({
305 invoice: invoice.id,
306 })
307
308 let customerId: string | null = null
309 if (invoice.customer) {
310 customerId = getStripeId(invoice.customer)
311 }
312
313 if (creditNotes.data.length > 0) {
314 logger.info(
315 {
316 invoiceId: invoice.id,
317 creditNoteIds: creditNotes.data.map((cn) => cn.id),
318 customerId,
319 },
320 'Invoice paid with existing credit notes - no action needed',
321 )
322 } else {
323 logger.warn(
324 {
325 invoiceId: invoice.id,
326 customerId,
327 },
328 'Invoice paid but no credit notes found - this may indicate a missing credit note from draft stage',
329 )
330 }
331}
332
333const webhookHandler = async (req: NextRequest): Promise<NextResponse> => {
334 let event: Stripe.Event

Callers 1

webhookHandlerFunction · 0.85

Calls 1

getStripeIdFunction · 0.90

Tested by

no test coverage detected