Fix affichage jours d'essai
This commit is contained in:
@@ -29,9 +29,7 @@ def _plan_card(meta: dict, trial: int | None, trial_used: bool):
|
||||
className="text-muted mb-2",
|
||||
)
|
||||
elif trial:
|
||||
badge = html.Div(
|
||||
f"{trial} jours d'essai gratuit", className="text-success mb-2"
|
||||
)
|
||||
badge = html.Div(f"{trial} jours d'essai gratuit", className="mb-2")
|
||||
else:
|
||||
badge = None
|
||||
return dbc.Card(
|
||||
|
||||
@@ -15,7 +15,7 @@ def _handle(env_name: str) -> str:
|
||||
PLANS = {
|
||||
"simple": {
|
||||
"env": "FRISBII_PLAN_SIMPLE",
|
||||
"label": "Abonnement simple",
|
||||
"label": "Abonnement",
|
||||
"prix_ht": 20,
|
||||
"description": "Accès à des fonctionnalités supplémentaires de decp.info.",
|
||||
},
|
||||
@@ -50,14 +50,11 @@ def plan_meta(key: str) -> dict | None:
|
||||
}
|
||||
|
||||
|
||||
def _parse_trial_interval(value) -> int | None:
|
||||
# Reepay/Frisbii renvoie une durée type "2d" (jours), "1m" (mois), etc.
|
||||
# On ne sait afficher que les jours pour l'instant ; format à confirmer.
|
||||
if not value or not isinstance(value, str):
|
||||
return None
|
||||
value = value.strip().lower()
|
||||
if value.endswith("d") and value[:-1].isdigit():
|
||||
return int(value[:-1])
|
||||
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
|
||||
|
||||
|
||||
@@ -77,6 +74,6 @@ def trial_days(key: str) -> int | 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.get("trial_interval"))
|
||||
days = _parse_trial_interval(plan)
|
||||
_trial_cache[handle] = (now, days)
|
||||
return days
|
||||
|
||||
@@ -20,7 +20,7 @@ def test_trial_days_parses_and_caches(monkeypatch):
|
||||
|
||||
def fake_get_plan(handle):
|
||||
calls.append(handle)
|
||||
return {"trial_interval": "2d"}
|
||||
return {"trial_interval_unit": "days", "trial_interval_length": 2}
|
||||
|
||||
monkeypatch.setattr(client, "get_plan", fake_get_plan)
|
||||
assert plans.trial_days("simple") == 2
|
||||
@@ -37,7 +37,7 @@ def test_trial_days_none_on_error(monkeypatch):
|
||||
|
||||
|
||||
def test_trial_days_none_when_no_trial(monkeypatch):
|
||||
monkeypatch.setattr(client, "get_plan", lambda h: {"trial_interval": None})
|
||||
monkeypatch.setattr(client, "get_plan", lambda h: {})
|
||||
assert plans.trial_days("simple") is None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user