diff --git a/cloud/billing.py b/cloud/billing.py index 29ed7d2..1af2d07 100644 --- a/cloud/billing.py +++ b/cloud/billing.py @@ -16,7 +16,8 @@ from fastapi import APIRouter, Request, HTTPException from pydantic import BaseModel from sqlalchemy import select -from .config import settings, PLAN_MINUTES, TRIAL_DAYS, SUBSCRIPTION_LOOKUP_KEYS, TOPUP_LOOKUP_KEYS +from .config import (settings, PLAN_MINUTES, TRIAL_DAYS, SUBSCRIPTION_LOOKUP_KEYS, + TOPUP_LOOKUP_KEYS, new_subscriber_label) from . import analytics, config, database from .models import User, Subscription, CreditTopup, StripeEvent, SignupAttribution from .auth import get_current_user_required @@ -490,19 +491,6 @@ def _sub_period(sub_obj: dict): return start, end -def new_subscriber_label(status: str) -> str | None: - """Alert text for a brand-new subscription row, or None to stay silent. - - Only states where a payment method actually went through count: an - 'incomplete' row is a checkout that has not been paid (yet), not a sale. - """ - if status == "trialing": - return "trial started — card on file" - if status == "active": - return status - return None - - async def _upsert_subscription(sub_obj: dict, event_created: datetime): price_id = _sub_price_id(sub_obj) info = plan_info_for_price(price_id) diff --git a/cloud/config.py b/cloud/config.py index 53e79c3..8c74674 100644 --- a/cloud/config.py +++ b/cloud/config.py @@ -61,6 +61,21 @@ BILLING_ATTENTION_STATES = ("past_due", "unpaid", "incomplete", "paused") # within 24h), so blocking that would only stop the retry. CHECKOUT_BLOCKING_STATES = ("active", "trialing", "past_due", "unpaid", "paused") +def new_subscriber_label(status: str): + """Admin-alert text for a brand-new subscription row, or None to stay silent. + + Only states where a payment method actually went through count. Stripe + creates the row as 'incomplete' seconds after the Checkout page opens, + before the user types anything; announcing that is announcing a click. + Lives here (not in billing.py) so the test runs without the stripe SDK. + """ + if status == "trialing": + return "trial started — card on file" + if status == "active": + return status + return None + + # Smallest slice of a long video worth offering instead of the quota wall. # A user whose remaining minutes cannot cover the whole source is offered its # first N minutes (N = what they have left) so they see clips before paying: diff --git a/tests/test_billing_states.py b/tests/test_billing_states.py index ffa5903..dae3e73 100644 --- a/tests/test_billing_states.py +++ b/tests/test_billing_states.py @@ -86,10 +86,8 @@ class TestNewSubscriberAlert: """The 'New subscriber' admin alert must mean money, not a click on pay.""" def test_incomplete_is_silent(self): - from cloud.billing import new_subscriber_label - assert new_subscriber_label("incomplete") is None + assert config.new_subscriber_label("incomplete") is None @pytest.mark.parametrize("status", ["active", "trialing"]) def test_paid_states_alert(self, status): - from cloud.billing import new_subscriber_label - assert new_subscriber_label(status) + assert config.new_subscriber_label(status)