feat(refactor): refactor payment system to implement unified credit wallet.

- Updated environment variables and - configurations for credit purchases via Stripe, replacing legacy page pack system.
- Introduced auto-reload feature for credit top-ups and modified database models to track credit transactions.
- Updated notification system to handle insufficient credits and auto-reload failures.
- Adjusted API routes and schemas to reflect changes in credit management.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-06-10 16:49:03 -07:00
parent 4fe216856d
commit a7407502d3
88 changed files with 3229 additions and 2261 deletions

View file

@ -75,23 +75,16 @@ SECRET_KEY=SECRET
NEXT_FRONTEND_URL=http://localhost:3000
# Stripe Checkout for pay-as-you-go page packs
# Configure STRIPE_PRICE_ID to point at your 1,000-page price in Stripe.
# Pages granted per purchase = quantity * STRIPE_PAGES_PER_UNIT.
# Stripe Checkout for the unified credit wallet.
# Each pack grants STRIPE_CREDIT_MICROS_PER_UNIT micro-USD of credit
# (default 1_000_000 = $1.00). Both ETL page processing and premium model
# turns are billed against this single balance at actual provider cost.
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
STRIPE_PRICE_ID=price_...
STRIPE_PAGES_PER_UNIT=1000
# Set FALSE to disable new checkout session creation temporarily
STRIPE_PAGE_BUYING_ENABLED=TRUE
# Premium credit purchases via Stripe (for premium-tier model usage).
# Each pack grants STRIPE_CREDIT_MICROS_PER_UNIT micro-USD of credit
# (default 1_000_000 = $1.00). Premium turns are billed at the actual
# per-call provider cost reported by LiteLLM.
STRIPE_TOKEN_BUYING_ENABLED=FALSE
STRIPE_PREMIUM_TOKEN_PRICE_ID=price_...
STRIPE_CREDIT_PRICE_ID=price_...
STRIPE_CREDIT_MICROS_PER_UNIT=1000000
# Set FALSE to disable new checkout session creation temporarily
STRIPE_CREDIT_BUYING_ENABLED=FALSE
# Periodic Stripe safety net for purchases left in PENDING (minutes old)
STRIPE_RECONCILIATION_LOOKBACK_MINUTES=10
@ -221,15 +214,25 @@ VIDEO_PRESENTATION_FPS=30
VIDEO_PRESENTATION_DEFAULT_DURATION_IN_FRAMES=300
# (Optional) Maximum pages limit per user for ETL services (default: `999999999` for unlimited in OSS version)
PAGES_LIMIT=500
# Unified credit wallet starting balance for new users, in micro-USD
# (default: 5,000,000 == $5.00). The same balance funds ETL page processing
# and premium model calls, debited at actual provider cost.
DEFAULT_CREDIT_MICROS_BALANCE=5000000
# Premium credit quota per registered user, in micro-USD
# (default: 5,000,000 == $5.00 of credit). Premium turns are debited at the
# actual per-call provider cost reported by LiteLLM, so cheap and expensive
# models bill proportionally. Applies only to models with
# billing_tier=premium in global_llm_config.yaml.
PREMIUM_CREDIT_MICROS_LIMIT=5000000
# Debit the credit wallet for ETL page processing. Default FALSE keeps ETL
# effectively free for self-hosted/OSS installs; hosted deployments set TRUE.
# 1 page == MICROS_PER_PAGE micro-USD ($0.001); premium ETL mode is 10x.
ETL_CREDIT_BILLING_ENABLED=FALSE
MICROS_PER_PAGE=1000
# Low-balance warning threshold (micro-USD), surfaced to the UI. Default $0.50.
CREDIT_LOW_BALANCE_WARNING_MICROS=500000
# Auto-reload: automatically top up via a saved Stripe card when the balance
# drops below the user-chosen threshold. Off by default.
AUTO_RELOAD_ENABLED=FALSE
AUTO_RELOAD_MIN_AMOUNT_MICROS=1000000
AUTO_RELOAD_COOLDOWN_MINUTES=10
# Safety ceiling on per-call premium reservation, in micro-USD.
# stream_new_chat estimates an upper-bound cost from the model's