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

@ -166,25 +166,26 @@ EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
# REDIS_URL=redis://redis:6379/0
# ------------------------------------------------------------------------------
# Stripe (pay-as-you-go page packs, disabled by default)
# Stripe (unified credit wallet, disabled by default)
# ------------------------------------------------------------------------------
# Set TRUE to allow users to buy additional page packs via Stripe Checkout
STRIPE_PAGE_BUYING_ENABLED=FALSE
# Set TRUE to allow users to buy credit packs via Stripe Checkout. $1 buys
# 1_000_000 micro-USD of credit; both ETL page processing and premium turns
# debit this balance at the actual per-call provider cost from LiteLLM.
STRIPE_CREDIT_BUYING_ENABLED=FALSE
# STRIPE_SECRET_KEY=sk_test_...
# STRIPE_WEBHOOK_SECRET=whsec_...
# STRIPE_PRICE_ID=price_...
# STRIPE_PAGES_PER_UNIT=1000
# STRIPE_CREDIT_PRICE_ID=price_...
# STRIPE_CREDIT_MICROS_PER_UNIT=1000000
# STRIPE_RECONCILIATION_INTERVAL=10m
# STRIPE_RECONCILIATION_LOOKBACK_MINUTES=10
# STRIPE_RECONCILIATION_BATCH_SIZE=100
# Premium credit purchases via Stripe ($1 buys 1_000_000 micro-USD of
# credit; premium turns debit the actual per-call provider cost
# reported by LiteLLM, so cheap and expensive models bill proportionally)
# STRIPE_TOKEN_BUYING_ENABLED=FALSE
# STRIPE_PREMIUM_TOKEN_PRICE_ID=price_...
# STRIPE_CREDIT_MICROS_PER_UNIT=1000000
# Auto-reload: 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
# ------------------------------------------------------------------------------
# TTS & STT (Text-to-Speech / Speech-to-Text)
@ -407,13 +408,16 @@ SURFSENSE_ENABLE_DOOM_LOOP=true
# ACCESS_TOKEN_LIFETIME_SECONDS=86400
# REFRESH_TOKEN_LIFETIME_SECONDS=1209600
# Pages limit per user for ETL (default: unlimited)
# PAGES_LIMIT=500
# Unified credit wallet starting balance for new users, in micro-USD
# (default: $5). Funds both ETL page processing and premium model calls,
# debited at the actual per-call provider cost reported by LiteLLM.
# DEFAULT_CREDIT_MICROS_BALANCE=5000000
# Premium credit quota per registered user, in micro-USD (default: $5).
# Premium turns are debited at the actual per-call provider cost reported
# by LiteLLM. Only applies to models with billing_tier=premium.
# PREMIUM_CREDIT_MICROS_LIMIT=5000000
# Debit the credit wallet for ETL page processing. Default FALSE keeps ETL
# effectively free for self-hosted installs. 1 page == MICROS_PER_PAGE
# micro-USD ($0.001); premium ETL mode is 10x.
# ETL_CREDIT_BILLING_ENABLED=FALSE
# MICROS_PER_PAGE=1000
# Safety ceiling on per-call premium reservation, in micro-USD ($1.00 default).
# QUOTA_MAX_RESERVE_MICROS=1000000