Skip to content

feat(free): admin reset of one person, Stripe included - #519

Merged
sinameraji merged 1 commit into
mainfrom
feat/admin-reset-person
Nov 29, 2026
Merged

sinameraji merged 1 commit into
mainfrom
feat/admin-reset-person

Conversation

@sinameraji

Copy link
Copy Markdown
Contributor

What

POST /admin/people/:githubId/reset {confirmLogin} resets one test person on dl.new so they look like they never existed, Stripe included. It is meant for demo recordings, where the same GitHub account has to sign up and pay again many times.

For every account of the person (their own people row and the dl.new account their GitHub identity points at), the steps run in this order:

  1. Stripe (new services/free/src/person-reset.ts, inside the Worker with the Worker's secret key). Customers are collected from the account's billing, customers, their claimed paid_checkouts, and the customer of each payments invoice or Checkout Session. Then:

    • every subscription of those customers, plus the known subscription ids, is canceled now;
    • every succeeded charge that isn't fully refunded is refunded for what is left on it (idempotency key reset-refund-<charge>-<amount_refunded>);
    • every customer is deleted.

    An already canceled subscription, charge_already_refunded, and No such customer / 404 all count as done.

  2. Data: the existing delete (auth, account objects, Directory), with no active_subscription refusal. The money rows go too: payments, customers, paid_checkouts, refund_requests, and the card trials of those subscriptions. This reuses deletePerson (app.ts) and DirectoryObject.deletePerson through a new reset / money option. The plain /delete behaves exactly as before.

  3. One config-log line: person_reset:<id>:<login>. It records the Stripe counts and the removed rows.

Response: {reset: true, githubId, login, stripe: {subscriptionsCanceled, refunds, refundedCents, customersDeleted}, removed: {"<object>.<table>": n}}.

Guards

  • Admins only. Same auth and rate limit as the other admin routes.
  • confirmLogin must match, same as delete: 400 invalid_request when it is missing, 400 login_mismatch when it is wrong, 404 when the person doesn't exist.
  • 409 is_admin for anyone in ADMIN_GITHUB_IDS.
  • A real Stripe error stops the reset before any data is deleted. The answer is 502 billing_error with error.stripe showing what was done so far. Running it again finishes the job.
  • If the person has Stripe records but Stripe isn't configured, the answer is 503 and nothing is touched.

Tests

services/free/test/reset-person.test.ts covers:

  • a paid GitHub sign-up gets canceled, refunded and its customer deleted, then no row points at it (payments and customers included);
  • a charge already refunded and a subscription already canceled in Stripe;
  • already refunded and No such customer errors;
  • a Stripe error gives 502, nothing is deleted, and a rerun finishes;
  • admin gives 409, wrong login gives 400;
  • a GitHub sign-in after a reset is a brand-new account with zero usage.

The whole services/free suite passes (1488 tests), and tsc -p services/tsconfig.json is clean.

Note

A legacy dl Pro subscription (metadata.github_id) that gets canceled here can send its customer.subscription.deleted webhook after the rows are gone. That would write back a canceled billing and subscription mirror row. dl.new plan webhooks find their account through customers, which is deleted, so they write nothing.

🤖 Generated with Claude Code

POST /admin/people/:githubId/reset {confirmLogin}: cancels every
subscription of the person's Stripe customers, refunds every succeeded
charge in full, deletes the customers, then deletes the person like
/delete does plus their payments, customers, paid_checkouts,
refund_requests and card trials. A Stripe error stops it before any
data is deleted (502 with what was done); safe to run again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sinameraji
sinameraji merged commit 4f45865 into main Nov 29, 2026
5 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

Development

Successfully merging this pull request may close these issues.

1 participant