Skip to content

Prepaid code: switch off is a no-op on the portal, resume checks for another live plan (switch stays off) - #26173

Merged
kodjima33 merged 1 commit into
mainfrom
feat/prepaid-code-switch-off-portal-and-resume
Nov 23, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
feat/prepaid-code-switch-off-portal-and-resume

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Follow-up to #26171 from its review. Backend only. PREPAID_CODE_REDEEM stays off and nobody is added to the cohort.

  1. Switch off is a true no-op on the customer portal. With the switch off, free, churned and past_due/unpaid readers (dunning users fixing a card) still took the extra Stripe subscription read, and got a 503 if Stripe failed there, where they used to get a portal session. Now:
    • When PREPAID_CODE_REDEEM is off and the stored row has no prepaid marker, the read is skipped. The new config.prepaid_code_redeem.mode() is an env read with no I/O. Those readers get exactly the session they got before Redeem a prepaid Omi Pro code with no card, behind PREPAID_CODE_REDEEM (default off) #26146 (customer and return_url only).
    • In cohort or on mode the read turns itself back on for any row that isn't a live paid plan.
    • A stored prepaid row is refused whatever the switch says.
  2. _resume checks for another live plan. If the first create never reached Stripe and the reader bought a card-billed plan in between, a retry could create a prepaid plan next to it. Portal and cancel would then return 409, so the reader couldn't cancel the card-billed plan in the app. Now:
    • A resumed redemption whose claim has no subscription id re-runs the live-plan check (Play row, live stored row, any Stripe subscription that can still bill).
    • That check ignores the subscription this same code created: one with the prepaid marker and redeemed_promotion_code_id equal to this promotion code, plus the stored row when it points at that subscription.
    • The reader's own half-finished plan completes. Any other live plan gives 409 has_plan with no Stripe write.
    • The claim stays with the reader, so the code is used by nobody else and the same reader can finish once that plan has ended.

Money-safety: changed lines

  • backend/config/prepaid_code_redeem.py: mode(), which enabled_for now uses (same behaviour).
  • backend/routers/payment.py create_customer_portal_endpoint: the read also requires mode() != 'off'.
  • backend/utils/prepaid_code_redemption.py:
    • _has_live_plan(..., own_promotion_code_id) and _open_stripe_subscriptions, which replace _has_open_stripe_subscription;
    • the resume guard in _resume.

How it was verified

  • tests/unit/test_prepaid_code_redemption.py (66), covering:
    • switch unset, off or unknown, with a free or a churned/past_due row: zero Stripe list calls, and the portal session is created with only customer and return_url;
    • cohort or on, with a free row and a marked Stripe subscription: refused;
    • a stored prepaid row is refused in every mode;
    • mode() is an env read only;
    • resume with only its own half-finished subscription (in Stripe and on the stored row) completes without a second subscription;
    • resume next to another live card-billed plan is refused 409 has_plan, with no Stripe write and the promotion code unredeemed; it finishes once that plan has ended.
  • 155 neighbouring backend files pass one by one, the test.sh timing guard passes, and backend/scripts/typecheck.sh has 0 errors.

Not verified

  • Live Stripe and the production webhook grant (sandbox and stub only).
  • The live Stripe customer portal configuration.

Product invariants affected

none

Line-count exceptions

Line-Count-Exception: backend/routers/payment.py | 2445 -> 2447 | the switch-off skip belongs in the portal endpoint it guards

View guided diff Turn on auto-fix

…another live plan

With PREPAID_CODE_REDEEM off and no prepaid marker on the stored row, the portal makes no
extra Stripe read. A resumed redemption refuses when another live plan exists, ignoring
the prepaid subscription this same code created.
@kodjima33 kodjima33 added the mux-proposal Mobile UX improver (MUX) proposal; waits for Nik's ship label Nov 23, 2026
@kodjima33
kodjima33 marked this pull request as ready for review November 23, 2026 21:24
@kodjima33
kodjima33 merged commit 36fd86f into main Nov 23, 2026
75 of 76 checks passed
@kodjima33
kodjima33 deleted the feat/prepaid-code-switch-off-portal-and-resume branch November 23, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mux-proposal Mobile UX improver (MUX) proposal; waits for Nik's ship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant