- Add billing module (app/api/billing.py) with 5 API endpoints:
- GET /api/v1/billing/checkout/{tier} — redirect to Stripe Payment Links
- GET /api/v1/billing/status — current org tier, limits, upgrade URLs
- GET /api/v1/billing/success — Stripe success callback
- GET /api/v1/billing/cancel — Stripe cancel callback
- POST /api/v1/billing/webhook — handles 5 Stripe event types
- Zero-code payment flow: uses pre-configured Stripe Payment Links
with client_reference_id (org ID) and prefilled_email params
- Webhook handler processes checkout.session.completed,
customer.subscription.updated/deleted, invoice events
- Stripe signature verification via stripe library (primary)
or manual HMAC-SHA256 (fallback)
- Tier determination from payment amount: =pro, 9=team
- 4 new config settings in app/config.py:
stripe_pro_checkout_url, stripe_team_checkout_url,
stripe_webhook_secret, stripe_api_key
- Added stripe>=5.0,<16.0 dependency
- 29 tests in tests/test_billing.py (all passing)
- Total: 98 tests passing (69 existing + 29 new)
50 lines
No EOL
1.5 KiB
Python
50 lines
No EOL
1.5 KiB
Python
from pydantic_settings import BaseSettings
|
|
from pathlib import Path
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings loaded from environment variables or .env file."""
|
|
|
|
# App
|
|
app_name: str = "Indie Status Page"
|
|
database_url: str = "sqlite+aiosqlite:///./data/statuspage.db"
|
|
secret_key: str = "change-me-to-a-random-string"
|
|
admin_api_key: str = "change-me-to-a-secure-api-key"
|
|
debug: bool = False
|
|
|
|
# Site
|
|
site_name: str = "My SaaS Status"
|
|
site_url: str = "http://localhost:8000"
|
|
site_logo_url: str = ""
|
|
site_accent_color: str = "#4f46e5"
|
|
|
|
# SMTP
|
|
smtp_host: str = ""
|
|
smtp_port: int = 587
|
|
smtp_user: str = ""
|
|
smtp_pass: str = ""
|
|
smtp_from: str = "noreply@example.com"
|
|
|
|
# Webhook
|
|
webhook_notify_url: str = ""
|
|
|
|
# Uptime monitoring
|
|
monitor_check_interval: int = 60
|
|
|
|
# Stripe Checkout Links
|
|
stripe_pro_checkout_url: str = "" # e.g. https://buy.stripe.com/xxxx_pro
|
|
stripe_team_checkout_url: str = "" # e.g. https://buy.stripe.com/xxxx_team
|
|
stripe_webhook_secret: str = "" # e.g. whsec_xxxx
|
|
stripe_api_key: str = "" # e.g. sk_test_xxxx (needed for webhook verification)
|
|
|
|
model_config = {"env_file": ".env", "env_file_encoding": "utf-8"}
|
|
|
|
@property
|
|
def db_path(self) -> Path:
|
|
"""Extract filesystem path from SQLite URL for directory creation."""
|
|
# Remove the sqlite+aiosqlite:/// prefix
|
|
path_str = self.database_url.replace("sqlite+aiosqlite:///", "")
|
|
return Path(path_str)
|
|
|
|
|
|
settings = Settings() |