Skip to content

Fix manual invoicing bugs#673

Merged
allanlasser merged 6 commits into
masterfrom
fix/invoice-webhook-and-overdue-bugs
May 7, 2026
Merged

Fix manual invoicing bugs#673
allanlasser merged 6 commits into
masterfrom
fix/invoice-webhook-and-overdue-bugs

Conversation

@allanlasser
Copy link
Copy Markdown
Member

@allanlasser allanlasser commented May 5, 2026

Summary

Fixes a chain of bugs that caused a customer to receive an erroneous subscription cancellation email. A manually-created Stripe invoice was saved with amount=0 (captured before line items were added), subsequent updates were never synced to our system, and overdue processing could (in theory) cancel the customer's unrelated subscription.

Co-authored with Claude Opus 4.6

allanlasser and others added 5 commits May 5, 2026 16:20
Invoices created outside of our subscription flow (manual Stripe invoices,
quote-based invoices) were being saved to our database with no subscription
link, then picked up by overdue processing causing erroneous emails and
subscription cancellations.

handle_invoice_created now returns early if no subscription can be resolved
from the webhook data, preventing orphaned invoice records.

Closes #670

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Invoice webhook handlers for finalized and paid events only updated
individual fields (status, due_date) but not amount. There was also no
handler for invoice.updated events. This meant amount changes (e.g. line
items added after creation) were never captured in our system.

- Add handle_invoice_updated task and wire invoice.updated webhook
- Refactor handle_invoice_finalized and handle_invoice_paid to use
  Invoice.create_or_update_from_stripe() for full state sync
- Preserve payment_failed flag clearing in the paid handler

Closes #669

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
$0 invoices were being processed by the overdue invoice system, triggering
warning emails and eventually cancelling subscriptions over invoices where
no payment is actually owed.

- Add amount__gt=0 filter to check_overdue_invoices query
- Add early return in process_overdue_invoice for $0 invoices

Closes #671

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
process_overdue_invoice was calling organization.subscription_cancelled()
which always cancels the org's current subscription. When an overdue invoice
was linked to a different subscription (or had no subscription at all), this
cancelled the wrong subscription entirely.

- Change process_overdue_invoice to pass invoice.subscription explicitly
- Add optional subscription parameter to Organization.subscription_cancelled
- Skip cancellation when invoice has no linked subscription

Closes #672

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@allanlasser allanlasser changed the title Fix invoice webhook sync and overdue processing bugs Fix manual invoicing bugs May 5, 2026
@allanlasser allanlasser temporarily deployed to squarelet-pi-fix-invoic-xjrrsj May 5, 2026 21:39 Inactive
@allanlasser allanlasser temporarily deployed to squarelet-pi-fix-invoic-xjrrsj May 5, 2026 22:37 Inactive
@allanlasser allanlasser merged commit 650b919 into master May 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants