SHKeeper
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
@@ -97,6 +98,17 @@ STRIPE_WEBHOOK_SECRET = os.environ.get("STRIPE_WEBHOOK_SECRET", "")
|
||||
STRIPE_LIVE_MODE = os.environ.get("STRIPE_LIVE_MODE", "0") == "1"
|
||||
STRIPE_PORTAL_CONFIGURATION = os.environ.get("STRIPE_PORTAL_CONFIGURATION", "")
|
||||
STRIPE_API_VERSION = "2025-03-31.basil"
|
||||
SHKEEPER_URL = os.environ.get("SHKEEPER_URL", "").rstrip("/")
|
||||
SHKEEPER_API_KEY = os.environ.get("SHKEEPER_API_KEY", "")
|
||||
SHKEEPER_CA_CERT_FILE = os.environ.get("SHKEEPER_CA_CERT_FILE", "")
|
||||
SHKEEPER_CURRENCIES = [value.strip() for value in os.environ.get("SHKEEPER_CURRENCIES", "").split(",") if value.strip()]
|
||||
SHKEEPER_ENABLED = bool(SHKEEPER_URL and SHKEEPER_API_KEY and SHKEEPER_CURRENCIES)
|
||||
if SHKEEPER_URL:
|
||||
shkeeper_origin = urlsplit(SHKEEPER_URL)
|
||||
if shkeeper_origin.scheme != "https" or not shkeeper_origin.hostname or shkeeper_origin.username or shkeeper_origin.path or shkeeper_origin.query or shkeeper_origin.fragment:
|
||||
raise ImproperlyConfigured("SHKEEPER_URL must be a certificate-verified HTTPS origin.")
|
||||
if any(not re.fullmatch(r"[A-Z0-9][A-Z0-9-]{0,31}", value) for value in SHKEEPER_CURRENCIES):
|
||||
raise ImproperlyConfigured("SHKEEPER_CURRENCIES must contain API crypto identifiers such as BTC or ETH-USDT.")
|
||||
tier_file = os.environ.get("MEMBERSHIP_TIERS_FILE", "")
|
||||
MEMBERSHIP_TIERS = json.loads(os.environ["MEMBERSHIP_TIERS_JSON"]) if "MEMBERSHIP_TIERS_JSON" in os.environ else json.loads(Path(tier_file).read_text(encoding="utf-8")) if tier_file else {}
|
||||
if not isinstance(MEMBERSHIP_TIERS, dict):
|
||||
@@ -111,3 +123,10 @@ for key, tier in MEMBERSHIP_TIERS.items():
|
||||
if not tier["price_id"].startswith("price_") or tier["price_id"] in prices:
|
||||
raise ImproperlyConfigured("Each tier must have a unique Stripe Price ID.")
|
||||
prices.add(tier["price_id"])
|
||||
if "usd_amount" in tier:
|
||||
try:
|
||||
amount = Decimal(tier["usd_amount"])
|
||||
if not amount.is_finite() or amount <= 0 or amount > 1000000 or amount != amount.quantize(Decimal("0.01")):
|
||||
raise ValueError
|
||||
except (InvalidOperation, ValueError, TypeError):
|
||||
raise ImproperlyConfigured(f"Tier {key} usd_amount must be a positive USD amount with at most two decimals.") from None
|
||||
|
||||
Reference in New Issue
Block a user