Repository navigation
Redeem a prepaid Omi Pro code with no card, behind PREPAID_CODE_REDEEM (default off) - #26146
Merged
Merged
Conversation
…M (default off) A single-use code whose coupon makes Omi Pro monthly exactly zero for a fixed term (bundle 12 months, prepaid year, creator 3 months, first month included) is redeemed server-side: Stripe customer + subscription with the code, no payment method, cancel_at an hour before the first undiscounted renewal. The existing webhook grants Pro. Partial and shared codes keep checkout. App: Have a code? on the trial paywall and plans sheet.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
…ide the CPU budget
Paywall closes after a redeem; prepaid plans show only their end date (server marker, admitted users only); one code row on the plans sheet, discount codes hand off to the promo field; no entry for Play-billed or provider-unknown Android readers; cancel, portal, upgrade and reactivation refuse a prepaid subscription; any billable Stripe subscription blocks redeem; no paid-through grace at term end; three-state switch with no read when off; per-uid limit only; analytics events removed.
kodjima33
marked this pull request as ready for review
November 23, 2026 19:21
kodjima33
added a commit
that referenced
this pull request
Nov 23, 2026
…ays off) (#26166) ## What changed and why Follow-up to #26146, which merged with `PREPAID_CODE_REDEEM` off. Round 2 of the general and money reviews listed what must be fixed before the switch can turn on for anyone. This PR does those fixes. The prod switch stays `off` and nobody is added to the cohort. 1. **Stay offer (money, N1).** A prepaid plan made with a `once` code (first month included) has no discount after its first invoice, so `utils/retention_offer.evaluate` offered the stay discount. Accepting it would clear `cancel_at` and renew the plan with no card, or charge a saved card without fresh consent. `evaluate` now refuses any subscription carrying the prepaid marker (`reason='prepaid'`), and `accept` goes through the same check. Other offers on this path: - the monthly downsell (`utils/monthly_switch.py`) only acts on a `past_due` yearly subscription, which a $0 monthly prepaid plan never is, and it refuses `cancel_at`; - the yearly switch refuses `cancel_at`; - no win-back or trial-extension endpoint exists. 2. **The prepaid marker no longer follows the switch.** `subscription.prepaid` stays in the subscription response whenever the stored plan has it, so a redeemed reader keeps "Your Omi Pro plan ends {date}." if the switch goes off or they leave the cohort. Only `prepaid_code_redeem` (the ability to redeem) follows the switch. For readers without a prepaid plan, switch-off responses stay byte-identical (tested). 3. **Server-side Play check on redeem.** `POST /v1/payments/prepaid-code/redeem` refuses with `409 play_billed` when `config.play_billing.client_uses_play` is true for the caller (same `X-App-Platform` / `X-App-Build` headers and helper as the subscription response). It refuses before the rate-limit bucket or any Stripe call. Note: **checkout itself is still client-gated only** for Play-billed builds; this PR does not change that. 4. **Portal before the webhook.** The stored-row check stays. The portal endpoint now also lists the customer's Stripe subscriptions and refuses when any one that can still bill carries the marker. Stripe has the marker from creation, so this covers the seconds before the webhook writes the row, and a lost webhook. Cost: one read-only Stripe call per portal open. I chose this over refusing during an in-flight claim because claims are keyed by promotion code, not uid. 5. **Clean-ups.** - Removed the dead `PrepaidCodeSource` / `source` parameter left after the analytics cut. - The has_plan message now gives a next step: "You already have a plan. Your code was not used. Redeem it after your plan ends." This is in all 49 locales via `scripts/l10n.py`. 6. **Evidence.** The MUX simulator scenario was run on one lane (`sim`, iPhone 17 Pro, real backend plus loopback Stripe stub, switch on locally), in light and dark. ## Screenshots (iPhone 17 Pro simulator) | One code row | Discount code hand-off | Prepaid plan view | Paywall closes after redeem | |---|---|---|---| | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/001-mobile-ios-plans-single-code-row.png" width="150"> | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/002-mobile-ios-discount-code-handoff.png" width="150"> | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/003-mobile-ios-prepaid-plan-ends.png" width="150"> | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/005-mobile-ios-paywall-closed.png" width="150"> | | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/006-mobile-ios-plans-single-code-row-dark.png" width="150"> | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/007-mobile-ios-discount-code-handoff-dark.png" width="150"> | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/008-mobile-ios-prepaid-plan-ends-dark.png" width="150"> | <img src="https://raw.githubusercontent.com/BasedHardware/omi/0e44b3270ec5ca8639e495bfed24c2ec9f13ed07/.agent-artifacts/ui-evidence/feat-prepaid-code-turn-on-fixes/009-mobile-ios-paywall-closed-dark.png" width="150"> | Full frames: `~/mobile-ux-agent/runs/2026-11-23/p1/r3-light/` and `r3-dark/` (12 states each). The stale `after-*/03-plans-sheet-entry.png` and `after-*/10-plans-after-redeem.png` are replaced. ## Money-safety: changed lines - `backend/utils/retention_offer.py` `evaluate`: prepaid marker check before any other rule. - `backend/routers/payment.py`: `_customer_has_prepaid_subscription` and its call in `create_customer_portal_endpoint`. - `backend/routers/redeem_code.py`: Play check before the rate limit and the redeem call. - `backend/routers/users.py` `_apply_prepaid_code_switch`: no longer strips `subscription.prepaid`. ## How it was verified - **Backend:** - `tests/unit/test_retention_offer.py` (36, including a once-shaped prepaid subscription: `evaluate` refuses and `accept` makes no Stripe write); - `tests/unit/test_prepaid_code_redemption.py` (48: marker kept with the switch off and switch-off bytes unchanged for others, Play caller refused, portal refused before the webhook and open for ended or ordinary subscriptions); - 182 neighbouring files one by one; `test.sh` timing guard; `backend/scripts/typecheck.sh` 0 errors; - OpenAPI and the Dart, TS and Swift clients regenerated (the redeem route gained two optional headers). - **App:** `prepaid_code_sheet_test.dart` and `play_billing_plans_sheet_test.dart`, including a new test that the prepaid plan view stays with the switch off. 788 tests across 68 neighbouring files pass. `l10n.py check` passes. ## Not verified - Live Stripe and the production webhook grant (sandbox and stub only). - Whether Stripe emails anything for $0 invoices. - A Checkout session already open with the code applied. - The live Stripe portal configuration. - Android on a device or emulator (widget tests only). - Desktop, Windows and web are not prepaid-aware; they show the server's 409 text on Manage or Cancel (UX only, no money path). ## Product invariants affected none ## Line-count exceptions Line-Count-Exception: backend/routers/payment.py | 2418 -> 2432 | the portal guard must sit in the portal endpoint it protects <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/26166?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26166?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26166&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
kodjima33
added a commit
that referenced
this pull request
Nov 23, 2026
…another live plan (switch stays off) (#26173) ## 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 #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 <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/26173?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26173?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26173&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
kodjima33
added a commit
that referenced
this pull request
Nov 24, 2026
…6247) ## Problem Google Play Billing for Android is merged and off in prod. On an Android build the server puts on Play, there is no way to activate a Shopify "12 months included" bundle code or a prepaid code: the app hides "Have a code?" (`usage_provider.dart` canRedeemPrepaidCode, `play_plans_content.dart` has no code row, the trial paywall hides the hint) and the server answers 409 `play_billed` to a Play client (`routers/redeem_code.py`). About 78 Android upgrades a month use one of these codes at Stripe checkout today, and about 32 users a week contact support because a code does not land (play-go-nogo.md section 4). Nik's decision (Nov 24): in-app code entry on the Play build. ## Change Server (`routers/redeem_code.py`, `routers/users.py`): - A client where `client_uses_play(platform, build, uid)` is true can redeem whatever `PREPAID_CODE_REDEEM` and its cohort say: `GET /v1/users/me/subscription` carries `prepaid_code_redeem: true`, and `POST /v1/payments/prepaid-code/redeem` runs the redemption instead of 409 `play_billed` / 404. - Nothing else in the redemption changed: same code checks, one redemption per code, same claim, same $0 no-card subscription ending one hour before the first full-price renewal, same marker, same per-user rate limit. It still refuses a reader with a live Stripe subscription, a live or recoverable Play purchase (the #26232 admission, including `play_check_unavailable` as a 503 `try_again`). - Reverse guard: buying Play next to a live prepaid plan is already refused (`utils/play_billing.py` `_live_stripe_subscription`, paginated non-terminal scan from #26232; the prepaid subscription is `active` until its term). Tests added, no code change needed. - iOS, web, desktop and Android below the Play minimum build follow the switch exactly as before. App: - `play_plans_content.dart`: a free reader on a Play build sees the existing "Have a code?" entry (same `PrepaidCodeEntry`, same text style, centered like the Stripe sheet's) as the last row, under Subscribe, Restore and the Play disclosure. It opens the existing prepaid code sheet unchanged. No discount-code hand-off, link or price. - Trial paywall: the same entry where the Stripe code hint is hidden today (provider change only). - `usage_provider.dart` `canRedeemPrepaidCode`: no longer hides on a Play build; never shows to a paid reader on a Play build (Play or Stripe, any status) or before the billing provider is known. - `plans_sheet.dart`: a Play build never shows the Stripe storefront; a prepaid plan reaches its existing "Your Omi Pro plan ends <date>." body. At term end the plan is Free again and the Play plans come back. - `plan_cards.dart`: at accessibility text sizes the price stacks under the title. The Play plans sheet overflowed by 486 px at the largest size on main; default sizes are unchanged. - No new strings. Changelog fragment `app/changelog/unreleased/20261124-play-code-entry.json` (android). ## Impact estimate If a bundle or prepaid code can be entered on the Play build, the about 78 Android code upgrades a month keep working after the Play switch (0 of them would activate without it), and code-related support contacts on Android go from about 32 a week across platforms toward 0 for Play-build users. Reach today: one throwaway Play-cohort test uid (see review round 1, item 4); no real user until the Play switch is flipped. Basis: 78/month Android code upgrades and 32/week code contacts are from the brief (play-go-nogo.md section 4 and the redemption reviews of #26146/#26166). ## Evidence Widget-test renders (Android, Play config present, Free reader). Paths: `~/mobile-ux-agent/runs/2026-11-24/g3/`.     ## Tests Backend (`tests/unit/test_play_prepaid_code_entry.py`, new): - Byte identity through the real routes (FastAPI TestClient on the users and redeem routers): every client (iOS, web, macOS, Windows, Android 1616, 1623, a Play-qualifying build, no headers) under prod settings (`ANDROID_BILLING=stripe`, empty Play cohort, `PREPAID_CODE_REDEEM=cohort` with an empty cohort), and with the switch off or on, gets main's exact bytes for both routes. Pins come from origin/main 120dfa4 running the same harness (`test_pin_main_responses`, regenerated with main's two routers checked out; deterministic across two runs). With `ANDROID_BILLING=play`, every non-Play client also gets main's bytes. - Play client with the switch off: offered (only `prepaid_code_redeem` added to main's body) and redeems; a non-Play client with the switch off gets 404 before the rate limit or lookup; a Play cohort member on a Stripe server can redeem. - Through the real redemption: no-card plan ending with the term, same reader again returns the same redemption, another account gets `code_used`; refused with `has_plan` next to a live Stripe subscription, a live Play row, an active, on-hold or paused Play purchase read from fake Google; 503 `try_again` when Google cannot be read; nothing created or claimed in each refusal. - Reverse: a Play purchase next to a live prepaid subscription is refused with `stripe_subscription_active` and nothing granted; a stored prepaid row also blocks; an ended prepaid plan does not. - 9 of these fail with main's routers (all the Play-client allow and refusal cases); the byte-identity cases pass on both by design. Updated: `test_prepaid_code_redemption.py` (the old 409 `play_billed` test now asserts the Play client redeems and iOS / old Android still follow the switch) and `test_play_billing.py` (Play build response now also carries `prepaid_code_redeem`). - Ran: `test_play_prepaid_code_entry`, `test_prepaid_code_redemption`, `test_play_billing`, `test_play_billing_guards`, `test_play_billing_money`, all `test_payment_*` and `test_users_*`: pass. App (`play_billing_plans_sheet_test.dart`): entry under Subscribe and Restore with the Stripe sheet's text style at x1 and x3.2; trial paywall entry at x1 and x3.2 opening the sheet; hidden for Play and Stripe subscribers (x1, x3.2), a paid non-active plan, when the server does not offer it, and before the provider is known; redeem success shows "Your Omi Pro plan ends", then the prepaid body with no Play purchase, then Play plans again at term end; no storefront for a prepaid plan on a Play build; the three refusal messages (`has_plan`, `code_used`, `try_again`); off a Play build the Stripe sheet keeps its own entry. 9 fail with main's app code. Ran with Flutter 3.44.5 (after round 2, 25 suites, 232 tests, plus the three files above): plans_sheet_{selection,checkout_refresh,redeem_code,cancel_pending}, prepaid_code_sheet, trial_paywall_{page,navigation,monthly_offer,real_font,trust}, the four usage_provider suites, plan_option_card_tap, contextual_plans_fallback, billing_currency_surfaces: all pass. `flutter analyze` on changed files: one existing info in trial_paywall_page.dart:185 (not touched). `make preflight` with this body. ## Review round 1 fixes (#26247) 1. **Redeeming from a paywall no longer strands the reader.** The auto-close on Outline, Trial and the trial upsell acts only while that page is the top route (`ModalRoute.of(context)?.isCurrent`, re-checked in the post-frame callback) and does not latch `_dismissed`/`_closed` when it skips. `ModalRoute.of` rebuilds the page when it is on top again. On the Trial paywall the code-success sheet stays until Done or Android back, then the existing `onRedeemed` closes the paywall with `true`. Prepaid readers are not exempted: an open paywall still closes for them once nothing covers it. Only the Trial paywall has the code entry; Outline and the upsell are tested with another route covering them. 2. **Code entry eligibility** (`UsageProvider.canRedeemPrepaidCode`): hidden when the latest subscription read failed after an earlier success (`_subscriptionReadFailed`; the cached Play setup still governs purchases exactly as before), and when the reader shows Free with a `payment_issue` and a `stripe_subscription_id` (a past-due Stripe agreement). The subscription response exposes nothing for a Play purchase on hold or pending on a Free row, so the app cannot hide the entry for that reader; the server refusal (`has_plan` from the #26232 admission) stays the guard there. These two checks apply on every platform, but only change anything where the entry shows (Play builds, and the prepaid cohort elsewhere, empty in prod). 3. **Prepaid redemption next to a Play purchase.** (a) `utils/prepaid_code_redemption.py`: after the code claim is taken and right before the Stripe create, redemption reads the user document and, for a reader with Play history, Google again (the same #26232 admission). A Play purchase that is now live or recoverable releases the claim and answers 409 `has_plan`; Google unreadable releases it and answers 503 `try_again`. This narrows the window; it does not close it. (b) `utils/play_stripe_guard.py` (Stripe webhook, `routers/payment.py`) never cancels or refunds a subscription carrying the prepaid marker: it keeps it and logs `prepaid_code_play_overlap uid=<uid> purchase=<first 12 hex> code=<promotion code id>` at ERROR each time. The Play-side observation (`utils/play_billing.py` `_record_stripe_conflict`) logs the same line instead of a double charge, with no user notice, when the only Stripe subscriptions are prepaid ones; a paid card subscription there is still a double charge as before. Runbook section added: `backend/docs/runbooks/play-billing-double-charge.md`, "Prepaid code next to Google Play". No automatic cancel or refund anywhere. 4. **Not a no-op for one account today.** With today's prod settings, the one throwaway uid in the Play cohort can redeem a code on a qualifying Android build (it gets `prepaid_code_redeem: true` and the route answers instead of 404). Every other account and client gets main's bytes. Tests: app `play_billing_plans_sheet_test.dart`: Trial redeem, success sheet visible, Done closes the paywall with `true`; same with Android back; Outline, Trial and upsell covered by another route when the reader turns out to pay outside Play: the cover is never popped, the paywall closes once after it, result `false`, a later refresh pops nothing; past-due Stripe and failed latest read hide the entry on the plans sheet and the Trial paywall, keep `buysThroughPlay`, and a good read brings it back. 9 fail on the previous head. The hosted navigation test now closes the page by Android back and asks for a URL the Play rule would allow (it fails with the close guard removed). Backend `test_play_prepaid_code_entry.py`: Play verified between the first check and the create refuses and frees the code; Google unreadable at the re-check frees it; Play verified after the re-check keeps both, the webhook guard never cancels the prepaid subscription and logs the line each time, the claim still points at the subscription; an ordinary paid Stripe subscription next to live Play is still cancelled and refunded (webhook and checkout paths); the Play-side observation logs the prepaid line with no notice and still reports a real double charge. 5 fail on the previous head. `test_play_billing_guards.py` read count updated for the re-check (one more user-document read). Byte-identity tests unchanged and passing. Backend type check (`scripts/typecheck.sh`): 0 errors. ## Money review round 2 follow-ups (#26231's remaining items before Play can be switched on) From `~/mobile-ux-agent/runs/2026-11-24/g2/money-review.md`, "Round 2", "Remaining items before this PR's part can be GO". 1. **Already-open native paywall.** New `UsageProvider.paywallClosedForPlay`: a paid plan not billed by Play on a Play build. An open Outline or Trial paywall (and the Stripe trial upsell on any Play build) closes with `false` as soon as that state is known, the same result a tap gets today (`alreadyPaid`), so no Stripe price or Upgrade CTA stays on screen and there is no skeleton. Same-price Resubscribe while a Stripe cancel is pending stays open; a prepaid plan never gets it. Files: `outline_paywall_page.dart`, `trial_paywall_page.dart`, `trial_upsell_sheet.dart`, `usage_provider.dart`. 2. **Home payment row copy on a Play build.** "Update your card at omi.me to get {plan} back." is replaced by "Your {plan} plan is paused." (title kept), real translations in all 49 locales via `scripts/l10n.py`; the old key is removed. Off a Play build the row is unchanged. 3. **Hosted paywall lifecycle.** `web_paywall_page.dart` re-checks closed, mounted and the Play gate after the catalog await and before building the controller or calling `loadRequest`; a closed or disposed page's navigation delegate always answers prevent. 4. **Real refusal statuses.** Tests now use the backend's shapes and statuses: 409 `use_google_play`, 400 `play_subscription_on_hold`, 400 `play_check_unavailable`. `monthly_switch_sheet.dart`: a 400 `play_check_unavailable` is transient and keeps Confirm (tested with a second tap). Tests (`play_billing_plans_sheet_test.dart`, `payment_issue_row_test.dart`, `unit/payment_refusal_test.dart`): open Outline, Trial and upsell paywalls refreshed to paid Stripe + Play close with no Stripe price, CTA or spinner and result `false`; cancel-pending Resubscribe stays; hosted page with Play arriving during the catalog wait records no `loadRequest`; a navigation callback after close answers prevent (and navigate while open, off Play); monthly 400 `play_check_unavailable` keeps Confirm; row copy names no place to pay. 7 of these fail with the five lib files reverted.   ## Not in this PR - Manage and Cancel for a prepaid plan on desktop, Windows and web show the raw 409 text. - A stuck code claim has no expiry or admin release. - A prepaid redemption and a Play purchase can still both land in a narrow race; a person resolves it from the `prepaid_code_play_overlap` log (runbook). - The subscription response does not expose a Play purchase on hold or pending on a Free row, so the app still shows the code entry there; the server refuses with `has_plan`. - Live proofs still owed: webhook grant, term end, $0 invoice emails, portal settings. - On a Play build a discount (not prepaid) code gets the existing "This code can't be redeemed here. Use it when you choose a plan." The Play sheet has no promo field, so that second sentence does not apply there. - At accessibility text sizes the trial paywall's notes scroll with the page while Try for Free stays pinned at the bottom, so the entry sits visually above the pinned button there (same layout the Stripe hint has on main). The paywall's timeline row also overflows at x3.2 on main; not touched. ## Not verified - No emulator or device run; renders are widget-test renders. The reviewer's item 4 (final qualifying Android build smoke against the deployed backend) is still owed before enabling. - No dark-mode render. Line-Count-Exception: backend/routers/payment.py | 2476 -> 2478 | the webhook passes the Stripe object to the Play guard so a prepaid subscription is never cancelled (one call wrapped by the formatter) UI-Evidence: see the images above (.agent-artifacts/ui-evidence/mux-2026-11-24-play-code-entry) ## Product invariants affected none ## Failure class (fixes) Failure-Class: none
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
People who bought Omi with "12 months included" (Shopify bundle), or who hold a prepaid or creator code, can only use it through Stripe Checkout today. Checkout asks for a card even at US$0, and in-app redemption needs an existing paid plan. 31 people wrote to support in 7 days because their prepaid Pro "doesn't land".
This adds a way to redeem a fully prepaid code in the app, with no card and no payment screen. It sits behind
PREPAID_CODE_REDEEM:off(default, prod value): nobody, no cohort read.cohort: members of theprepaid-code-redeemrollout cohort, for a test account.on: everyone, no read.Google Play-billed Android readers keep main's behaviour. For them, and while Android doesn't yet know its billing provider, no code entry is shown anywhere. Opening it for Play is a later decision.
Which codes are in scope
Scope comes from the code itself (live Stripe objects), not from a list of names:
max_redemptions == 1): something one person prepaid, not a shared discount.repeatingN months (1–24): the bundle "Omi Pro: 12 months included", prepaid-year codes, creator codesOMI-TRYBE-…(3 months) and support grants.repeatingN months, oronce= 1 month when the amount is below the yearly price ("Omi Monthly: first month included", $29.99 once).applies_toproduct restriction.forever,once100% (its term depends on which price it lands on, so it isn't knowable), and shared codes. The sheet says "This code can't be redeemed here. Use it when you choose a plan." The code is not consumed.Screenshots (iPhone 17 Pro simulator, real backend + Stripe stub)
Note: these frames are from the first round. The plans-sheet frames with two code rows and "Resubscribe" after redeeming are removed because this round changed both. The new plans-sheet states are covered by widget tests only. Free disk was below the 30 GB floor, so no simulator build was made this round.
App behaviour this round
not_prepaid) closes the sheet, opens today's promo field with the code filled in, and goes through today's checkout. Paid readers and switch-off readers see only today's "Promo code" row.showPrepaidCodeSheetreturnsbool. On Done after a redeem, the trial paywall pops withtrue, the same way Restore does.TargetPlatform.android:Grant model (Stripe stays the record)
POST /v1/payments/prepaid-code/redeemcreates or reuses the Stripe customer, then callsSubscription.createon Omi Pro monthly withdiscounts=[{promotion_code}]and no payment method. It setspayment_behavior=error_if_incomplete,proration_behavior=none, andcancel_at= N calendar months minus 1 hour. Stripe enforces max redemptions, expiry and first-time restrictions, and counts the redemption.customer.subscription.created/updatedwebhook grants Pro unchanged, with metadatauid,redeemed_promotion_code_id,prepaid_code_redemption=1and Shopify attribution.promotion_code_redemptions/{promo_id}(the same ledger as/redeem-code, so the two paths exclude each other) plus Stripe idempotency keys. A double tap or retry by the same user returns the first result and never creates a second subscription. A definitive Stripe refusal releases the claim. An unknown outcome keeps it, so a retry replays the same idempotent create.Stripe sandbox test clocks (
livemode=false,~/mobile-ux-agent/runs/2026-11-23/p1/sandbox/):cancel_at, 0 charge attempts.cancel_at, 0 charge attempts.The production path adds a 1-hour margin before the boundary.
End of term
cancel_atStripe ends the subscription. Thedeletedwebhook projects Free at once: the paid-through grace is skipped for prepaid subscriptions (routers/payment.py,_build_subscription_from_stripe_object), so the normal downgrade and ended event fire once. The user then sees their platform's normal purchase options. No renewal is attempted and no dunning email is sent.subscription.prepaid: true, only for users the switch admits; it is omitted otherwise, so switch-off responses are byte-identical. With that marker, Plans & Billing shows only the plan name and "Your Omi Pro plan ends {date}.", with no Resubscribe, Upgrade, Cancel or Manage payment method control.trial_will_endskips subscriptions withcancel_at(utils/trial_reminder.py:40). A pre-expiry nudge is a follow-up.Money-safety: every changed line near code validation, subscription creation and entitlement
backend/utils/prepaid_code_redemption.pyprepaid_months: the scope rule.applies_to, not prepaid._has_live_plan/_has_open_stripe_subscription: refuses withhas_planfor a live Stripe row, a live Play row, or any Stripe subscription that can still bill (active, trialing, past_due, unpaid, incomplete, paused). The code is not consumed.Subscription.create._resume: idempotent retry.backend/database/promotion_redemptions.py:claim(extra=),get,set_subscription.backend/routers/redeem_code.py: switch gate (404 when not admitted), per-uid rate limit, error to reason-code mapping.backend/routers/payment.py, each returning 409 "Your prepaid plan ends on its own…" before any Stripe change:DELETE /v1/payments/subscription);POST /v1/payments/customer-portal);POST /v1/payments/upgrade-subscription);POST /v1/payments/checkout-session);backend/utils/subscription_state_machine.py,backend/utils/subscription.py: projection of end date, "ends" state and theprepaidmarker, for the prepaid metadata marker only.backend/config/prepaid_code_redeem.py: the three-state switch, marker andprepaid_end.Endpoints audited for a guard on a prepaid subscription:
utils/retention_offer.py): refused, the subscription already has a discount.utils/yearly_switch.py:111,117) and monthly switch / downsell (utils/monthly_switch.py:124,130): refused forcancel_ator a discount.utils/promotion_redemption.py): refused, already discounted.pause_collection.utils/stripe.py:577), and the old-subscription cancel after a new checkout (payment.py).web/admin). The Stripe dashboard itself is not guarded.Switch off = today
PREPAID_CODE_REDEEM=offthere is no cohort read onGET /v1/users/me/subscriptionfor any user. A test exercises the realenabled_foragainst a counting cohort resolver. Withcohortit reads theprepaid-code-redeemcohort document; withonit reads nothing. The first round of this PR read the cohort on every request even when off; that is fixed.prepaid_code_redeemandsubscription.prepaidare omitted (tested).404 Not Foundand reads no rate-limit bucket (tested).before-light/).backend/deploy/runtime_env/{prod,dev}.overlay.yaml→runtime_env.yaml(PREPAID_CODE_REDEEM: 'off', rollout), plusconfig/feature-flags.yaml.cohortand add a member doc torollout_cohorts/prepaid-code-redeem. No uid is in source.Rate limits
payments:prepaid_code: 10 per hour per uid. Fail-open on a Redis outage, like/redeem-code.X-Forwarded-Forhops behind the load balancer don't identify the client.Analytics
prepaid_code_redemptionmetadata) and support contacts.Will miscount these $0 subscriptions (listed, not rewritten):
web/admin/lib/stripe-subscriptions.ts:105-134,255,275-352: MRR fromunit_amount, ignores discounts. Feedsweb/admin/lib/wall-metrics.ts:747.web/admin/app/api/omi/stats/revenue/route.ts:40-47,.../mrr-trends/route.ts:110-119,.../profitability/route.ts:552-570,.../subscription-trends/route.ts:60-68,web/admin/app/api/omi/subscriptions/route.ts:93-94.backend/scripts/finops/pull_stripe.py:281,318-319: counts them as paying subscribers.:139-148reads only legacydiscount.:329ignorescancel_at.backend/utils/observability/subscription_events.py:74-93,139-168:Billing Subscription Startedwith full-pricemrr_cents.Merged with #26129 (Play Billing follow-up)
origin/main(with Play Billing follow-up: money fixes (deletion retry, refund-only periods, keyed account id), Play reviewer app fixes (trial disclosure, hardware-only store, paywall Retry, Play prices), prod deploy config #26129) into this branch.trial_paywall_page.dart: two hunks, both sides kept (if (canRedeemCode) … else if (!playBilled) …).scripts/l10n.py.UsageProvider.canRedeemPrepaidCode), which matches Play Billing follow-up: money fixes (deletion retry, refund-only periods, keyed account id), Play reviewer app fixes (trial disclosure, hardware-only store, paywall Retry, Play prices), prod deploy config #26129's Play trial page.How it was verified
Backend:
tests/unit/test_prepaid_code_redemption.py(46 tests, Stripe mocked). Covers:prepaidmarker only when admitted.Also passing: 191 neighbouring files one by one, including
tests/routers/test_users.py, the Stripe webhook behaviour tests, lifecycle writer inventory, runtime-env validator, route policy and app-client schema inventory.test.shtiming guard passes.backend/scripts/typecheck.sh: 0 errors. OpenAPI and the Dart, TS and Swift clients are regenerated and checked.App:
test/widgets/prepaid_code_sheet_test.dart(18) andtest/widgets/play_billing_plans_sheet_test.dart(27, including 5 new). 777 tests across 68 neighbouring files pass.l10n.py checkpasses.Simulator (first round): iPhone 17 Pro, real backend plus loopback Stripe stub,
~/mobile-ux-agent/runs/2026-11-23/p1/.Not verified
test_people_generation_inventoryfailed on main itself;ccb96700f4was already in the old base, so rebasing alone would not have fixed it. Main now carries thepeople-generation-writers.jsonpin from Play Billing follow-up: money fixes (deletion retry, refund-only periods, keyed account id), Play reviewer app fixes (trial disclosure, hardware-only store, paywall Retry, Play prices), prod deploy config #26129, and the test passes on this merged branch. No pin was added here.tests/unit/test_merge_validation.py(backend unit shard 6/8) fails with 50ImportErrorerrors on current origin/main too (reproduced on a clean origin/main checkout). It comes from main's recentpipeline_ledgerimport changes, not this PR.test_conversations_v3_streamandtest_batch_result_protocolhit the 1.00 s CPU guard once (1.01–1.20 s) and passed on re-run.Metric
Support contacts about codes: 31 a week → near 0. Android code upgrades kept after Play Billing: about 23 a week (MODELED from 99 in 30 days).
Product invariants affected
INV-MEM-4 is selected by changed paths. No memory intake, consolidation or promotion code changes. This PR touches billing, subscription projection and app paywall code only.
Line-count exceptions
Line-Count-Exception: backend/routers/payment.py | 2395 -> 2418 | prepaid guards must sit inside the cancel, portal, upgrade, reactivation and term-end grace paths they protect
Line-Count-Exception: backend/routers/users.py | 2875 -> 2885 | the prepaid switch fields sit beside play_billing on the subscription response
Line-Count-Exception: backend/utils/subscription.py | 1880 -> 1882 | the Stripe self-heal projection shows the prepaid end date like project_subscription