From 9e5aa7431d29f37577c9d70763d29860c00567c8 Mon Sep 17 00:00:00 2001 From: "victormanuel.caverogracia" <> Date: Sat, 18 Jul 2026 23:34:58 +0200 Subject: [PATCH] fix(billing): block new checkout for past_due/unpaid/incomplete subs Guard only blocked active/trialing, so a user whose first charge failed (sub in past_due) could create a second subscription. Real case: annual trial -> end-trial -> card declined -> past_due, then a fresh monthly sub, leaving two live subs on one customer. Now any non-terminal status blocks. --- cloud/billing.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cloud/billing.py b/cloud/billing.py index 17561a2..5e30c2a 100644 --- a/cloud/billing.py +++ b/cloud/billing.py @@ -101,7 +101,15 @@ async def _active_sub_exists(user_id) -> bool: sub = (await s.execute( select(Subscription).where(Subscription.user_id == user_id) )).scalar_one_or_none() - return bool(sub and sub.status in ("active", "trialing")) + # Block a second checkout for ANY non-terminal subscription, not just + # active/trialing. A first charge that fails leaves the sub in past_due / + # unpaid / incomplete; those must still block, otherwise the user can spawn a + # second subscription while the first one keeps dunning (real case: annual + # trial -> end-trial -> card declined -> past_due, then a fresh monthly sub). + # Terminal states (canceled, incomplete_expired) do NOT block. + return bool(sub and sub.status in ( + "active", "trialing", "past_due", "unpaid", "incomplete", "paused", + )) # --------------------------------------------------------------------------- #