Document manual billing restore when a client isn't on real Stripe yet

reenable_users() is only ever called from the signed /webhook/stripe/
<slug> route -- there's no separate restore endpoint -- so a trial-timer
test or a client paying by some other means for now has no way to clear
a lockout without calling it directly. billing.py is deliberately built
for exactly this ("No Flask/HTTP objects imported here by design...
testable without a running Flask app"), so this is the documented entry
point with its HTTP wrapper removed, not a workaround.

Verified live against sample: restored every User the lockout snapshot
recorded (dispatcher, store manager, the Setup Wizard admin account, the
Stock Viewer demo account), zero failures.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012pc2x7vyuUofdT3kLuqF3Y
This commit is contained in:
JasonFraser 2026-10-03 23:31:12 -04:00
parent 20c0fd0d45
commit e863fcdb5b
1 changed files with 20 additions and 0 deletions

View File

@ -755,6 +755,26 @@ exists, and locks the client out through the exact same `disable_users()` a real
`invoice.payment_failed` webhook would use, once the tenant's own `trial_start_date`/`trial_days`
(optional fields in `tenants.json`) has elapsed.
**Manually restoring access without a real Stripe webhook** — the normal unlock path is a real
`invoice.payment_succeeded` event hitting `/webhook/stripe/<slug>`, which calls
`billing.reenable_users()`. That's the only HTTP route that ever calls it — there's no separate
"restore" endpoint — so if Stripe isn't wired up yet for this client (trial-timer testing, or a
client who pays by some other means for now), restore has to call that same function directly,
bypassing the Flask/signature layer entirely. `billing.py` is deliberately built this way — its
own module docstring: "No Flask/HTTP objects imported here by design... testable without a
running Flask app" — so this isn't a workaround, it's the documented, tested entry point used
with its HTTP wrapper removed. Run inside the `backend-billing` container itself (not the Frappe
`backend` container — this is plain Python, not `bench console`):
```
printf 'from billing.billing import reenable_users\nfrom billing.state_store import StateStore\nfrom billing.frappe_client import FrappeClient\nfrappe_client = FrappeClient(base_url="<tenant frappe_api_url>", api_key="<tenant frappe_api_key>", api_secret="<tenant frappe_api_secret>")\nstate_store = StateStore(tenant_slug="<slug>", db_path="/data/state.db")\nresult = reenable_users(frappe_client, state_store, "manual-restore-no-stripe")\nprint(result)\n' | docker exec -i <backend-billing-container> python3
```
Substitute this tenant's actual `frappe_api_url`/`frappe_api_key`/`frappe_api_secret`/slug from
`tenants.json`. Prints `{"reenabled": [...], "failed": []}` — every User that was locked out by
the matching `disable_users()` call (trial-expiry or a real `invoice.payment_failed`) gets their
real Roles and Default Workspace restored from the snapshot `StateStore` saved at lockout time.
Verified live: restores exactly the same set of Users the lockout snapshot recorded, zero
failures, Users confirmed able to log in normally afterward.
**"Get Billing Status"** — Script Type `API`, API Method `get_billing_status`, **Allow Guest**
left unchecked (a locked-out User is a "Website User," not a Guest — Server Script's own guest
check only blocks actual Guests, so this still works for them):