Skip to content

fix(billing): block a failed payer only while the invoice is still owed - #10601

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/billing-block-followups
Dec 1, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/billing-block-followups

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Follow-ups from an audit of #10530 and #10579:

  • handleInvoicePaymentFailed reads the invoice back from Stripe before blocking. Webhooks can land late or be redelivered, so a failure that arrives after the invoice was paid or voided no longer blocks a payer nothing will unblock
  • A failure Stripe counted no attempt for (a charge outside its retry schedule, usually one waiting on the customer's authentication) blocks only once Stripe has put the plan past due or unpaid. An active plan keeps access while the customer completes the charge, so a 3DS-required plan or seat change no longer locks out a person or a whole team; past-due plans with an uncounted failure are still blocked
  • Ending a trial early: amount_too_large is permanent for that card, so it now asks for a different card and logs at error (it can signal a pricing misconfiguration); rate limits keep the "try again later" message
  • The threshold overage auto-pay failure log no longer claims Stripe retries the invoice (it's created with auto_advance: false)

Type of Change

  • Bug fix

Testing

  • lib/billing/webhooks/invoices.integration.ts (real Postgres): no block when the invoice is already paid or voided; no block for an uncounted failure on an active plan; a never-attempted open invoice doesn't hold the block. lib/billing/free-plan.integration.ts: a too-large charge asks for a different card. The four new guard tests fail on staging and pass here; 33/33 green
  • lib/billing/webhooks/ unit tests 18/18; biome on the changed files; type-check, audits and the full suite in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Read the invoice back from Stripe before blocking, so a failure event that
arrives after the invoice was paid or voided blocks nobody. A failure Stripe
counted no attempt for blocks only once the plan is past due, so an active
plan keeps access while the customer completes an authentication-required
charge. Answer a charge too large for the card with a different-card message
logged as an error, and correct the overage-invoice log that claimed Stripe
retries it.
@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Dec 1, 2026 10:04pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The latest change appears safe to merge; no new actionable issue was found.

Summary

The latest change keeps failed invoices marked uncollectible eligible to block their payer.

  • Invoice webhooks block access only while the related debt is still owed.
  • Trial-ending charges that exceed a card's limit ask for a different card.
  • The overage-payment warning says the payer must pay the open invoice.

Reviews (3) · Last reviewed commit: "fix(billing): keep blocking on an invoic..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

This PR changes payment, billing, or quota logic. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit d182b49 into staging Dec 1, 2026
84 checks passed

This branch was previously deployed

1 inactive deployment
Preview — af8b582c Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant