Zero-dependency Stripe billing, orphan-free B2B Hosted Invoicing (send_invoice), overdue receivables radar, hash-locked catalog and checkout CLI (legends-stripe) for coding agents: audit .env test/live price-ID parity, issue 4-step bound B2B invoices with Endive custom_fields validation, sync price ladders behind SHA-256 plan locks, reconcile cent-exact Stripe fee drag and net retained cash, verify raw-body HMAC snapshot and v2 thin-event webhooks, and attach source-cited billing runbooks to legends-empire.
Install or update legends-stripe via cto-legends (https://github.com/avalonreset/cto-legends): run `cto-legends install legends-stripe --apply`, then `cto-legends handoff legends-stripe` and follow the returned JSON recipe to verify `legends-stripe doctor`.
Developers and founders shipping on Astro, Next.js, or Python hit the same high-cost Stripe failure modes when relying on ad-hoc scripts or dashboard clicks:
- Orphaned B2B invoice items and unmonitored overdue receivables: In Stripe's API, creating an
InvoiceItemwithout explicitly bindinginvoice=draft.idleaves pending items floating on the customer record to leak into the next subscription renewal, whilecustom_fieldsexceeding Stripe's field count or length limits fail at runtime and Customer-Scheduled Invoice Payments fire zero scheduling webhook events. - Test vs. Live
.envprice-ID drift and silent catalog traps: Ansk_live_...secret key gets paired with apk_test_...publishable key or aprice_1...ID from the wrong mode; product descriptions over 500 characters truncate; statement descriptors over 22 characters or containing< > \ ' " *get rejected; and archiving a Product leaves its child Pricesactive: trueas orphans. - Hidden Stripe fee drag and fragile webhook signature handlers: Standard dashboard charts celebrate gross volume while
$0.30fixed transaction fees on$10charges, international card surcharges, and0.7%Stripe Billing usage fees quietly eat 4% to 7.4% of revenue. Meanwhile, web middleware parses JSON before verifyingStripe-Signature(breaking raw-body HMAC-SHA256 digests) or subscribes only tocheckout.session.completedwhile missing the renewal, dunning, and cancellation events required for a clean subscription lifecycle.
legends-stripe solves all of these with a zero-dependency Python 3.11+ standard-library CLI (urllib.request, hmac, hashlib) that pairs naturally with legends-astro, legends-gohighlevel, and legends-empire. Every write operation (invoice-create, invoice-void, catalog-sync, product-upsert, webhook-upsert, and checkout-canary) defaults to a read-only preview and locks execution behind a deterministic SHA-256 plan_sha256 hash (--apply --confirm-plan <sha256>, plus --live for live keys).
Once cto-legends is installed, you ask your coding agent in plain english. It previews the SHA-256 plan hash first, enforces test/live key and idempotency guards, and reconciles balances to the exact cent:
B2B wire, ACH, and corporate card settlements require strict separation from automated subscription billing:
- 4-step bound B2B invoice lifecycle (
invoice-create&invoice-void): EnforcesCustomer -> Draft send_invoice -> Bound InvoiceItem (invoice=draft.id) -> Finalize + Readbacklocked by preview-firstplan_sha256confirmation and per-step idempotency keys. Validatescustom_fieldsoffline (maximum 4 fields, 40-char names and 140-char values), 500-character descriptions/footers, anddays_until_due(1..365), returning the finalizedhosted_invoice_urlandinvoice_pdf. - Overdue receivables aging radar (
invoice-radar): Separates standalone B2Bsend_invoicereceivables from subscription invoices, computes overdue days and open/draft totals by currency, redacts customer PII (--redact-pii), and surfaces Customer-Scheduled Invoice Payments governance notes.
Every workflow in legends-stripe separates offline validation and zero-write plan previews from hash-confirmed execution:
| Surface | legends-stripe Subcommands / Python API |
What It Does |
|---|---|---|
| Environment & Price-ID Audit | env-audit, price-map / audit_env_file(), build_price_map() |
Cross-checks .env STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY, price_1..., and prod_... tokens against Test or Live Stripe mode and exports .env, JSON, or TypeScript as const lookup maps. |
| B2B Hosted Invoicing & A/R Radar | invoice-radar, invoice-create, invoice-void / scan_invoice_radar(), create_b2b_invoice(), void_b2b_invoice() |
Scans open B2B send_invoice receivables and overdue aging, issues orphan-free 4-step Hosted Invoices (hosted_invoice_url, invoice_pdf), and voids open invoices with SHA-256 plan confirmation. |
| Catalog Lint & Price Ladders | catalog-audit, catalog-export, product-upsert, ladder-plan, catalog-diff, catalog-sync / audit_catalog() |
Flags 500-char description truncation, 22-char statement descriptor violations, and orphaned active Prices; cascades child-price deactivation on --inactive; and syncs price ladders with plan_sha256 locks. |
| Fee Drag & Net Cash Telemetry | telemetry / build_treasury_telemetry(), render_telemetry_markdown() |
Reconciles /v1/balance, /v1/balance_transactions, and /v1/charges (filtering out zero-fee 3DS card verifications) to compute Gross Revenue, Stripe Drag fee percentage, Refunds, Disputes, and Net Retained Cash to the cent. |
| Subscription MRR & Checkout Canary | subscription-radar, checkout-canary / scan_subscription_radar(), run_checkout_canary() |
Computes active MRR/ARR, past_due dunning recovery queues, cancel_at_period_end churn, and duplicate-billed customer alerts, and runs preview-first disposable Checkout Session canaries. |
| Webhooks, Domains & Blueprints | verify-webhook, sign-webhook, webhook-probe, webhook-audit, webhook-upsert, custom-domain-check, blueprint |
Constant-time Stripe-Signature (t=...,v1=...) HMAC-SHA256 verification for both v1 snapshot and v2 thin event_notification payloads (refusing raw whsec_ secrets on CLI argv), 5-event Soft-Land Subscription Lifecycle audits, SSRF-hardened endpoint and custom-domain probes, and drop-in Astro/Python blueprints. |
- 5 production server blueprints (
legends-stripe blueprint): Ships ready-to-drop TypeScript and Python endpoints:astro-webhook(raw-body HMAC verification),astro-checkout(Checkout Session creation),astro-portal(same-origin Customer Billing Portal withsk_/rk_validation),astro-b2b-invoice(timing-safe token-gated B2B Hosted Invoice issuance), andpython-webhook(multi-v1secret rotation support). - Attachable
legends-empireknowledge pack (knowledge/stripe/pack.json): Ships alegends.knowledge-pack/v1operational library and wiki/index.md covering Test/Live mode parity, price ladder design, B2B Hosted Invoicing settlement, fee drag reduction, soft-land webhook lifecycles, and private operation receipt templates.
# 1. Verify offline runtime health, audit .env price IDs, and export TypeScript price maps
legends-stripe doctor
legends-stripe env-audit --target-env .env --live
legends-stripe price-map --format ts
# 2. Scan B2B receivables and preview/issue an orphan-free 4-step Hosted Invoice
legends-stripe invoice-radar --redact-pii
legends-stripe invoice-create --customer-email [email protected] --company-name "Acme Corp" \
--amount-cents 102400 --title "Architecture Advisory Sprint" \
--invoice-number-ref "INV-2026-11-001" --custom-field "Client VAT / Tax ID=DE123456789"
# 3. Reconcile cent-exact Stripe fee drag, net retained cash, and subscription MRR/dunning
legends-stripe telemetry --redact-pii
legends-stripe subscription-radar --redact-pii
# 4. Lint products/prices, plan a price ladder, and preview a disposable Checkout canary
legends-stripe catalog-audit
legends-stripe ladder-plan --prefix "SaaS Pro" --amounts "19,49,99" --intervals "month,year" \
--statement-descriptor "SAAS PRO" --output spec.json
legends-stripe catalog-diff --spec spec.json
legends-stripe checkout-canary --price-id price_1Example123
# 5. Audit 5-event subscription webhooks, verify raw-body HMAC signatures, and export blueprints
legends-stripe webhook-audit --expected-url https://app.example.com/api/stripe/webhook
legends-stripe verify-webhook --payload @event.json --signature "t=1700000000,v1=..." --secret @webhook-secret.txt
legends-stripe blueprint --list
legends-stripe blueprint --name astro-b2b-invoice --rawKnowledge vault, billing runbooks, and legends-empire integration
Start at wiki/index.md or attach the versioned knowledge pack at knowledge/stripe/pack.json (legends.knowledge-pack/v1). See docs/KNOWLEDGE-PACK.md for attachment instructions.
- Operational runbooks: Overview, Authentication & modes, Catalog & price ladders, Checkout & custom domains, Invoicing & B2B settlement, Subscriptions & dunning, Treasury & Stripe drag, Webhooks & soft-land lifecycle, Troubleshooting, and Primary sources & citations.
- Private operating templates: Use templates/private-operation-receipt.md, templates/treasury-telemetry.md, and templates/webhook-fortification-receipt.md to archive sanitized billing and telemetry receipts in your private vault.
Agent setup (via cto-legends) and standalone installation
Part of the cto-legends ecosystem. cto-legends is the only registered skill; this repository vendors a pinned copy at skills/cto-legends/SKILL.md. The product, repository, Python distribution, and catalog ID are legends-stripe.
Run cto-legends handoff legends-stripe and follow the module recipe (docs/AGENT-RECIPE.md). Do not register this module as its own standalone skill. For a standalone local checkout:
git clone https://github.com/avalonreset/legends-stripe.git
cd legends-stripe
python -m pip install -e .
legends-stripe doctor
legends-stripe resourcesSecret keys (sk_live_, sk_test_, rk_) and webhook secrets (whsec_) are scrubbed from CLI outputs, error messages, and Markdown reports. Raw whsec_ literals are refused on CLI argv (use STRIPE_WEBHOOK_SECRET, --secret @<file>, --secret-file <file>, or --secret-stdin).
Repository layout, verification, and safety boundaries
Operator / Agent
-> legends-stripe CLI (env-audit, invoice-create, catalog-sync, telemetry, subscription-radar, webhook-audit)
-> Offline validator & preview builder (22-char descriptors, Endive custom_fields limits, SHA-256 plan_sha256)
-> Explicit confirmation (--apply --confirm-plan <sha256> [--live]) + per-step Idempotency-Key
-> Pinned Stripe API execution (ProxyHandler({}), SSRF/CGNAT refusal, pinned-IP TLS) + immediate readback
legends_stripe/: Zero-dependency Python 3.11+ CLI (cli.py), pinned Stripe API form encoder and SSRF-hardened client (api.py), B2B invoicing engine (invoices.py), catalog & ladder sync (catalog.py),.envauditor (env_tools.py), treasury telemetry (telemetry.py), subscription radar (subscriptions.py), snapshot + v2 thin-event webhook verifier (webhooks.py), and server blueprints (blueprints.py).routes.json: Machine-readable catalog of CLI commands, HTTP endpoints, mutation/preview/confirm safety classes, and$0/read vs live-write risk tags.docs/: Agent operating recipe, Knowledge pack guide, and Release procedure.
python -m unittest discover -s tests -v
python scripts/check_release.pylegends-stripe never handles raw credit card PAN numbers or PCI-DSS cardholder data, never mutates Live Mode without --apply --confirm-plan <plan_sha256> --live, and never follows HTTP redirects with Authorization headers attached or probes loopback, private RFC1918, or CGNAT (100.64.0.0/10) addresses.
See CONTRIBUTING.md, SUPPORT.md, CODE_OF_CONDUCT.md, SECURITY.md, and CHANGELOG.md.
MIT License. See LICENSE, NOTICE.md, and THIRD_PARTY_NOTICES.md.
Paste the agent handoff block at the top of this page into your coding agent, let it wire the cto-legends router skill, and speak your task in plain English.
Running a company and not a terminal? Founders and operators who want this way of working applied directly to their own business stack have one route: message Avalon Reset at cto-legends.com/dm or start with a 48-hour diagnostic at cto-legends.com/home#home-offer. The desk is async, so the conversation starts the moment you write and nobody forces you onto a sales call.
Specification & benchmarks on cto-legends.com:
- Module specification & architecture matrix: cto-legends.com/modules/legends-stripe
- Related engineering dispatches: How to Vet an AI Implementation Consultant in 15 Minutes · How to Choose MCP vs CLI Tools Without Context Bloat · Routing Cursor vs Claude Code by Blast Radius and Cost
- Ecosystem hub: cto-legends.com/home
