fix(abonnement): garde active→pending, datetime parse, resolve_handle vide (#90)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DRGb8NAMwaTZxUszSbaj4N
This commit is contained in:
Colin Maudry
2026-06-25 19:26:15 +02:00
parent d3025e323b
commit 5f500a1aa8
6 changed files with 96 additions and 4 deletions
+7 -1
View File
@@ -102,7 +102,13 @@ def has_active_subscription(user_id: int) -> bool:
if row["status"] in _ACCESS_STATUSES:
return True
if row["status"] == "cancelled" and row["current_period_end"]:
return row["current_period_end"] > _now()
try:
end = datetime.fromisoformat(
row["current_period_end"].replace("Z", "+00:00")
)
return end > datetime.now(timezone.utc)
except ValueError:
return False
return False
+6 -2
View File
@@ -30,16 +30,20 @@ PLANS = {
def resolve_handle(key: str) -> str | None:
meta = PLANS.get(key)
return _handle(meta["env"]) if meta else None
if meta is None:
return None
h = _handle(meta["env"])
return h if h else None
def plan_meta(key: str) -> dict | None:
meta = PLANS.get(key)
if meta is None:
return None
h = _handle(meta["env"])
return {
"key": key,
"handle": _handle(meta["env"]),
"handle": h if h else None,
"label": meta["label"],
"prix_ht": meta["prix_ht"],
"description": meta["description"],
+3
View File
@@ -22,6 +22,9 @@ def subscribe():
return "Plan inconnu", 400
base = os.getenv("APP_BASE_URL", "")
if db.has_active_subscription(current_user.id):
return redirect(f"{base}/compte/abonnement")
cust = _customer_handle(current_user.id)
try:
client.get_or_create_customer(cust, current_user.email)