Attach invoice line items so Stripe does not finalize at $0 paid #34

Merged
westfarn merged 1 commits from fix/33-invoice-zero-amount-paid into master 2026-10-06 18:24:03 -07:00
Owner

Summary

  • Closes One-off invoice finalizes at $0 and is marked paid (#33)
  • Create the draft invoice first, then attach the line item to that invoice id before finalize. Stripe's current API defaults pending_invoice_items_behavior to exclude, so the old pending-item-then-create-invoice order produced an empty invoice. Finalizing a $0 invoice auto-marks it paid.
  • If the finalized total does not match amount_cents, void the Stripe invoice and do not store paid. Ignore invoice.paid webhooks whose Stripe total is $0 when the local amount is non-zero.

Test plan

  • Create a one-off invoice for $2040.00 for a test customer
  • Confirm the local invoice status is Open and the amount is $2040.00
  • Open the Stripe hosted invoice and confirm the total is $2040.00 and status is Open, not Paid
  • Confirm a real invoice.paid webhook still marks a non-zero invoice paid after the customer pays
## Summary - Closes #33 - Create the draft invoice first, then attach the line item to that invoice id before finalize. Stripe's current API defaults `pending_invoice_items_behavior` to `exclude`, so the old pending-item-then-create-invoice order produced an empty invoice. Finalizing a $0 invoice auto-marks it paid. - If the finalized total does not match `amount_cents`, void the Stripe invoice and do not store `paid`. Ignore `invoice.paid` webhooks whose Stripe total is $0 when the local amount is non-zero. ## Test plan - [ ] Create a one-off invoice for $2040.00 for a test customer - [ ] Confirm the local invoice status is Open and the amount is $2040.00 - [ ] Open the Stripe hosted invoice and confirm the total is $2040.00 and status is Open, not Paid - [ ] Confirm a real `invoice.paid` webhook still marks a non-zero invoice paid after the customer pays
westfarn added 1 commit 2026-10-06 18:21:26 -07:00
Attach invoice line items before finalize.
CI / test (pull_request) Successful in 13s
Unit Tests / test (pull_request) Successful in 13s
576675b435
Closes #33. Stripe excludes pending invoice items by default, so the old
create path finalized an empty invoice and Stripe marked that $0 invoice paid.
westfarn merged commit d0c43425f5 into master 2026-10-06 18:24:03 -07:00
westfarn deleted branch fix/33-invoice-zero-amount-paid 2026-10-06 18:24:03 -07:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ai_ml_operations/company_site#34