Nombre de jours d'essai en dur plutot que via appels HTTP

This commit is contained in:
Colin Maudry
2026-07-02 13:55:22 +02:00
parent 1bdcaaf5d8
commit d08f7aeeac
2 changed files with 9 additions and 54 deletions
+4 -32
View File
@@ -1,11 +1,4 @@
import os
import time
from src.subscriptions import client
from src.utils import logger
_TTL_SECONDS = 3600
_trial_cache: dict[str, tuple[float, int | None]] = {}
def _handle(env_name: str) -> str:
@@ -18,12 +11,14 @@ PLANS = {
"label": "Abonnement",
"prix_ht": 20,
"description": "Accès aux fonctionnalités supplémentaires de colibre.",
"trial_days": 2,
},
"soutien": {
"env": "FRISBII_PLAN_SOUTIEN",
"label": "Abonnement de soutien ✊",
"prix_ht": 50,
"description": "Mêmes fonctionnalités, contribution renforcée au projet.",
"trial_days": 2,
},
}
@@ -50,30 +45,7 @@ def plan_meta(key: str) -> dict | None:
}
def _parse_trial_interval(plan: dict) -> int | None:
unit = plan.get("trial_interval_unit", "")
length = plan.get("trial_interval_length")
if unit == "days" and isinstance(length, int) and length > 0:
return length
return None
def trial_days(key: str) -> int | None:
handle = resolve_handle(key)
if not handle:
if not resolve_handle(key):
return None
now = time.monotonic()
cached = _trial_cache.get(handle)
if cached and now - cached[0] < _TTL_SECONDS:
return cached[1]
try:
plan = client.get_plan(handle)
except client.FrisbiiError:
logger.warning("Impossible de lire le plan Frisbii %s", handle)
return cached[1] if cached else None
# L'API Frisbii/Reepay renvoie une liste de versions ; on prend la dernière (la plus récente).
if isinstance(plan, list):
plan = plan[-1] if plan else {}
days = _parse_trial_interval(plan)
_trial_cache[handle] = (now, days)
return days
return PLANS[key]["trial_days"]