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:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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"],
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user