From ee214677bd59fafab217f5612b0c4bf334045e22 Mon Sep 17 00:00:00 2001 From: Colin Maudry Date: Sun, 5 Jul 2026 16:59:20 +0200 Subject: [PATCH] =?UTF-8?q?feat(abonnement):=20bouton=20changer=20de=20m?= =?UTF-8?q?=C3=A9thode=20de=20paiement=20sur=20/compte/abonnement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5 --- src/pages/compte/abonnement.py | 21 +++++++ tests/subscriptions/test_compte_abonnement.py | 60 +++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/src/pages/compte/abonnement.py b/src/pages/compte/abonnement.py index ef05189..063e36b 100644 --- a/src/pages/compte/abonnement.py +++ b/src/pages/compte/abonnement.py @@ -82,6 +82,23 @@ def _active_view(row): elif row["status"] == "active": blocks.append(html.P(f"Prochaine facturation : {end}")) + if row["status"] in ("trial", "active"): + blocks.append( + html.Form( + method="POST", + action="/subscriptions/change-payment-method", + children=[ + _csrf_input(), + html.Button( + "Changer de méthode de paiement", + type="submit", + className="btn btn-outline-secondary mt-3 me-2", + ), + ], + style={"display": "inline-block"}, + ) + ) + if row["status"] in ("pending", "trial", "active"): blocks.append( html.Button( @@ -152,6 +169,10 @@ def _feedback(query): out.append(dbc.Alert(text, color=color)) if query.get("resiliation") == "ok": out.append(dbc.Alert("Votre abonnement a été résilié.", color="info")) + if query.get("carte") == "succes": + out.append(dbc.Alert("Méthode de paiement mise à jour.", color="success")) + if query.get("carte") == "annule": + out.append(dbc.Alert("Modification annulée.", color="secondary")) if query.get("error") == "frisbii": out.append( dbc.Alert( diff --git a/tests/subscriptions/test_compte_abonnement.py b/tests/subscriptions/test_compte_abonnement.py index ac57e87..18c5223 100644 --- a/tests/subscriptions/test_compte_abonnement.py +++ b/tests/subscriptions/test_compte_abonnement.py @@ -66,3 +66,63 @@ def test_show_active_view_false_for_failed_expired_or_none(monkeypatch): assert compte_abonnement._show_active_view({"status": "failed"}) is False assert compte_abonnement._show_active_view({"status": "expired"}) is False assert compte_abonnement._show_active_view(None) is False + + +def test_active_view_shows_change_payment_method_for_active(): + from src.pages.compte import abonnement as compte_abonnement + + row = { + "plan": "simple", + "status": "active", + "current_period_end": "2099-01-01T00:00:00+00:00", + } + text = str(compte_abonnement._active_view(row)) + assert "Changer de méthode de paiement" in text + assert "/subscriptions/change-payment-method" in text + + +def test_active_view_shows_change_payment_method_for_trial(): + from src.pages.compte import abonnement as compte_abonnement + + row = { + "plan": "simple", + "status": "trial", + "current_period_end": "2099-01-01T00:00:00+00:00", + } + assert "Changer de méthode de paiement" in str(compte_abonnement._active_view(row)) + + +def test_active_view_hides_change_payment_method_for_cancelled(): + from src.pages.compte import abonnement as compte_abonnement + + row = { + "plan": "simple", + "status": "cancelled", + "current_period_end": "2099-01-01T00:00:00+00:00", + } + assert "Changer de méthode de paiement" not in str( + compte_abonnement._active_view(row) + ) + + +def test_active_view_hides_change_payment_method_for_pending(): + from src.pages.compte import abonnement as compte_abonnement + + row = {"plan": "simple", "status": "pending", "current_period_end": None} + text = str(compte_abonnement._active_view(row)) + assert "Changer de méthode de paiement" not in text + assert "Ajouter une méthode de paiement" in text + + +def test_feedback_carte_succes(): + from src.pages.compte import abonnement as compte_abonnement + + text = str(compte_abonnement._feedback({"carte": "succes"})) + assert "Méthode de paiement mise à jour." in text + + +def test_feedback_carte_annule(): + from src.pages.compte import abonnement as compte_abonnement + + text = str(compte_abonnement._feedback({"carte": "annule"})) + assert "Modification annulée." in text