From e863fcdb5b841c6abd57b344eca06b7ab4f37314 Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Sat, 3 Oct 2026 23:31:12 -0400 Subject: [PATCH] Document manual billing restore when a client isn't on real Stripe yet reenable_users() is only ever called from the signed /webhook/stripe/ 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 Claude-Session: https://claude.ai/code/session_012pc2x7vyuUofdT3kLuqF3Y --- playbook/DEVELOPER_GUIDE.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/playbook/DEVELOPER_GUIDE.md b/playbook/DEVELOPER_GUIDE.md index 2ba4200..27923b1 100644 --- a/playbook/DEVELOPER_GUIDE.md +++ b/playbook/DEVELOPER_GUIDE.md @@ -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/`, 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="", api_key="", api_secret="")\nstate_store = StateStore(tenant_slug="", db_path="/data/state.db")\nresult = reenable_users(frappe_client, state_store, "manual-restore-no-stripe")\nprint(result)\n' | docker exec -i 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):