Skip to content

fix(billing): cancel the Stripe subscription on account deletion - #213

Merged
ryuzdev merged 2 commits into
mainfrom
fix/delete-account-cancels-stripe
Dec 1, 2026
Merged

ryuzdev merged 2 commits into
mainfrom
fix/delete-account-cancels-stripe

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Dec 1, 2026

Copy link
Copy Markdown
Member

Security-review fix: deleting an account left a live Stripe Pro subscription billing the customer.

What:

  • accounts::delete_account (the one path self-deletion and the admin delete share) cancels a live subscription via DELETE /v1/subscriptions/{id} before dropping any row, with a per-account Idempotency-Key so a retry is safe. Any other Stripe failure fails closed: no rows deleted, clear message ("We couldn't cancel your Pro subscription, so the account wasn't deleted. Try again or contact support.").
  • StripeClient::cancel_subscription treats 404 resource_missing and canceled bodies as success.
  • Webhooks for a deleted user were already no-ops; pinned with a test (customer.subscription.deleted → recorded 200, no resurrected row).
  • Removed the admin billing_ack stopgap (API field + gate, console checkbox/warning): the shared path now cancels automatically. Delete modals and account-deletion docs note the immediate cancel with no automatic refund (Stripe default).

Why: a deleted account kept billing — fail-open data deletion with live billing.

Checks run (all green):

  • cargo fmt --all --check
  • cargo clippy --all-targets --locked -- -D warnings (only the pre-existing tower-http unused-dep warn)
  • targeted lib tests: billing::, http::console_billing::, http::console_account::, http::console_admin_users::, mcp::tests::delete_account — 127 passed, 0 failed
  • bun run validate (web)

No prod touched, no live Stripe calls. Awaiting independent review before merge.

- delete_account cancels a live subscription via DELETE /v1/subscriptions/{id} before dropping any row, with a per-account Idempotency-Key; any other Stripe failure fails closed with a clear message.
- Already-canceled/missing subscriptions (404 resource_missing, canceled body) count as success so retries are safe; late webhooks for deleted users stay recorded 200 no-ops.
- Removed the admin billing_ack stopgap (UI + API): self-deletion and admin deletion share the same automatic cancel. Docs and delete modals note the immediate cancel with no automatic refund.
- Checks: cargo fmt --check, cargo clippy --all-targets --locked -D warnings, targeted lib tests (billing::, console_billing::, console_account::, console_admin_users::, mcp delete_account), bun run validate.
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a9db750-b505-40aa-8552-5d01c7fb271f
Commits

Reviewing files that changed from the base of the PR and between d0c2cc8 and b6731c9.

Files selected for processing: 11

  • crates/outer/src/accounts.rs
  • crates/outer/src/billing/mod.rs
  • crates/outer/src/billing/stripe.rs
  • crates/outer/src/http/console_account.rs
  • crates/outer/src/http/console_admin_users.rs
  • crates/outer/src/http/console_billing.rs
  • crates/outer/src/mcp/tests.rs
  • web/docs/account/settings.mdx
  • web/docs/security/data-ownership.mdx
  • web/pages/console/_islands/views/account.tsx
  • web/pages/console/_islands/views/admin-users.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Independent-review follow-up on #213.
When the account has a Stripe customer, delete_account now lists the customer's subscriptions (GET /v1/subscriptions?customer, status=all, has_more paginated) plus the stored id, and cancels each billable one with a per-subscription Idempotency-Key delete-account-{account}-{sub}. A failed list or any failed cancel fails closed; an empty list is success.
A deletion step that fails after a successful cancel answers the retry-safe message instead of the generic internal error (per-subscription idempotency keys make a retry free).
Fake Stripe serves settable list pages (second page after starting_after) with list-outage and per-id cancel-failure modes; new tests: two live subs both canceled then deleted, pagination followed, second-cancel failure and list failure keep the account. Stripe-level list tests pin filtering, paging and outage. Mapper unit tests pin the post-cancel message.
Checks: cargo fmt --check, cargo clippy --all-targets --locked -D warnings, targeted lib tests (accounts::, billing::, console_billing::, console_account::, console_admin_users::, mcp delete_account) 136 passed, bun run validate.
@ryuzdev
ryuzdev merged commit ec19a33 into main Dec 1, 2026
5 checks passed
@ryuzdev
ryuzdev deleted the fix/delete-account-cancels-stripe branch December 1, 2026 07:39
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