Skip to content

refactor: extract lit-billing-core from lit-api-server stripe.rs#358

Open
clawdbot-glitch003 wants to merge 3 commits into
nextfrom
glitch003/lit-billing-core
Open

refactor: extract lit-billing-core from lit-api-server stripe.rs#358
clawdbot-glitch003 wants to merge 3 commits into
nextfrom
glitch003/lit-billing-core

Conversation

@clawdbot-glitch003
Copy link
Copy Markdown
Collaborator

Summary

  • New lit-billing-core crate owns the Stripe HTTP client, customer-by-wallet lookup, balance reads, reporting helpers, and pure formatters. lit-payments (coming separately) will depend on it so the customer-identity invariant — metadata.wallet_address keys the Stripe customer — is single-source-of-truth.
  • lit-api-server/src/stripe.rs keeps its public API unchanged (caches, charge flows, PaymentIntent flow, resolve_wallet_address) and now delegates HTTP + customer/balance primitives to lit-billing-core.
  • Pure refactor: zero behavior change. cargo check, cargo test --lib (211 passing), cargo test --bin stripe_report (14 passing), and cargo clippy -D warnings are all clean.

See plans/lit-payments-app.md (PR #354) for the bigger picture.

Test plan

  • cargo check clean in both crates
  • cargo test --lib — 211 lit-api-server tests pass
  • cargo test --bin stripe_report — 14 tests pass
  • cargo test in lit-billing-core — 15 tests pass (moved from stripe.rs)
  • cargo clippy --all-targets -- -D warnings clean in both crates
  • cargo fmt --check clean

Move Stripe HTTP client, customer-identity primitives, balance read,
and reporting helpers into a new lit-billing-core crate. lit-payments
(separate non-TEE service, coming in a follow-up PR) will depend on
the same crate so the customer-identity invariant
(metadata.wallet_address keys the Stripe customer) is shared.

What moves to lit-billing-core:
  - StripeClient (creds + reqwest, no caching)
  - parse_stripe_response + StripeResponse
  - customer::find_or_create_by_wallet, set_email
  - balance::fetch
  - reporting::list_all_customers / list_balance_transactions_since /
    aggregate_report_rows / Report{Customer,BalanceTx,Row}
  - format::cents_to_display / unix_to_utc_date

What stays in lit-api-server/src/stripe.rs:
  - StripeState (caches + publishable key)
  - resolve_wallet_address (depends on on-chain accounts module)
  - Cached wrappers: get_customer_by_wallet, get_credit_balance
  - Charge flows: charge / charge_management / charge_lit_action_time
  - PaymentIntent flow: create_payment_intent / confirm_payment_and_credit
  - register_customer_email, invalidate_wallet_cache
  - Reporting wrappers that take &StripeState

Pure refactor: no behavior change. lit-api-server's public stripe API
is unchanged; callers in lit_api_server::stripe::* still compile and
pass tests as before. cargo check + cargo test --lib (211 tests) +
cargo test --bin stripe_report (14 tests) + clippy -D warnings all
clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@clawdbot-glitch003 clawdbot-glitch003 requested a review from a team May 19, 2026 22:42
glitch003 and others added 2 commits May 19, 2026 16:06
StripeClient already redacts its own secret_key in its manual Debug
impl, so StripeState can derive Debug directly instead of carrying a
manual impl whose only job was to skip the (already-safe) inner field.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add lit-billing-core to the rust-ci.yml crate matrix so its 15 unit
  tests (moved from lit-api-server/src/stripe.rs) actually run in CI.
- Add lit-billing-core/ to deploy-staging.yml DEPLOY_PATHS so future
  changes scoped to the shared billing crate don't get skipped.
- Pin lit-billing-core's toolchain to 1.91 to match siblings and
  commit Cargo.lock so the new crate's CI build is reproducible.
clawdbot-glitch003 pushed a commit that referenced this pull request May 19, 2026
New ops-facing billing service. Deploys to Railway, outside the TEE.
This PR ships the crate skeleton + magic-link auth + login UI; the
admin credit portal endpoints come in a follow-up PR.

What's here:
  - Rocket binary crate at lit-payments/, sibling to lit-billing-core.
  - Postgres migrations for operators + sessions tables.
  - Seed migration with chris@litprotocol.com (admin) +
    Salamiademola73@gmail.com (mod).
  - HMAC-signed magic-link tokens (15-min expiry), verified at
    /auth/verify with constant-time signature compare.
  - Resend integration for sending magic-link emails.
  - Session cookies (private/HttpOnly/Secure/SameSite=Lax, 7-day).
  - Operator request guard so future protected routes just take
    `operator: Operator`.
  - Vanilla HTML/JS login page + signed-in landing page.
  - Multi-stage Dockerfile for Railway (build context = repo root).
  - README covering local dev + Railway deploy + Resend setup.

Stacked on glitch003/lit-billing-core (PR #358). Targets that branch
so it can land cleanly once the extraction merges.

cargo check + cargo test --lib + cargo clippy -D warnings + cargo fmt
all clean. Tests cover the token issue/verify roundtrip + the
expired/tampered/wrong-key failure modes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

2 participants