Skip to content

About

legends-stripe: Stripe billing, orphan-free B2B hosted invoicing, overdue receivables radar, webhook audit & hash-locked checkout CLI for coding agents

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

legends-stripe

release checks python stripe license

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.

Agent Handoff

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`.

Three Pillars: B2B invoicing & A/R radar, Hash-locked catalog & fee drag, Webhooks & Empire vault pack

Why legends-stripe exists

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:

  1. Orphaned B2B invoice items and unmonitored overdue receivables: In Stripe's API, creating an InvoiceItem without explicitly binding invoice=draft.id leaves pending items floating on the customer record to leak into the next subscription renewal, while custom_fields exceeding Stripe's field count or length limits fail at runtime and Customer-Scheduled Invoice Payments fire zero scheduling webhook events.
  2. Test vs. Live .env price-ID drift and silent catalog traps: An sk_live_... secret key gets paired with a pk_test_... publishable key or a price_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 Prices active: true as orphans.
  3. Hidden Stripe fee drag and fragile webhook signature handlers: Standard dashboard charts celebrate gross volume while $0.30 fixed transaction fees on $10 charges, international card surcharges, and 0.7% Stripe Billing usage fees quietly eat 4% to 7.4% of revenue. Meanwhile, web middleware parses JSON before verifying Stripe-Signature (breaking raw-body HMAC-SHA256 digests) or subscribes only to checkout.session.completed while 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).

Ask in plain english

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:

Say the job in plain words

Architecture: hash-locked Stripe plans and B2B invoice guards

How hash-locked Stripe plans and B2B invoice guards work

1. Orphan-free B2B Hosted Invoicing (send_invoice) and overdue A/R radar

B2B wire, ACH, and corporate card settlements require strict separation from automated subscription billing:

  • 4-step bound B2B invoice lifecycle (invoice-create & invoice-void): Enforces Customer -> Draft send_invoice -> Bound InvoiceItem (invoice=draft.id) -> Finalize + Readback locked by preview-first plan_sha256 confirmation and per-step idempotency keys. Validates custom_fields offline (maximum 4 fields, 40-char names and 140-char values), 500-character descriptions/footers, and days_until_due (1..365), returning the finalized hosted_invoice_url and invoice_pdf.
  • Overdue receivables aging radar (invoice-radar): Separates standalone B2B send_invoice receivables 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.

2. Complete CLI and Python capability surface

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.

3. Drop-in server blueprints and legends-empire knowledge vault

  • 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 with sk_/rk_ validation), astro-b2b-invoice (timing-safe token-gated B2B Hosted Invoice issuance), and python-webhook (multi-v1 secret rotation support).
  • Attachable legends-empire knowledge pack (knowledge/stripe/pack.json): Ships a legends.knowledge-pack/v1 operational 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.

Ad-hoc Stripe scripts vs legends-stripe

Comparison: Ad-hoc scripts & dashboard clicks vs Hash-locked billing engine // legends-stripe

Quick start

# 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 --raw

Reference

Knowledge 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.

Agent setup (via cto-legends) and standalone installation

Agent setup (via cto-legends)

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 resources

Secret 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), .env auditor (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.py

legends-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.

Contributing, security, and license

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.

Start here

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.

Want this way of working applied to your own stack? Message Avalon Reset at cto-legends.com/dm

GitHub Star List: The complete cto-legends collection on one page. Bookmark or star the router and every module from a single GitHub list.

Specification & benchmarks on cto-legends.com:

About

legends-stripe: Stripe billing, orphan-free B2B hosted invoicing, overdue receivables radar, webhook audit & hash-locked checkout CLI for coding agents

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages