Repository navigation
No Stripe purchase actions on Android builds that sell through Google Play - #26231
Merged
Merged
Conversation
…hrough Google Play A reader who already pays on Stripe keeps the plan, its date, Cancel (with the stay offer) and Resubscribe at the same price. Tier change, yearly switch, code field, payment portal, the Home payment row's Stripe actions and paid Marketplace Subscribe no longer show on a Play build. Coded server refusals from checkout, upgrade and the yearly and monthly switches show their sentence.
… re-read the plan after use_google_play, no Subscribe without a payment link on Android
Reads the top-level {detail, code} shape from #26232. A 409 with no code keeps
the old text. The CI failure was a largest-text truncation check that only holds
with real fonts; it now runs at the default size.
…he copy Home's payment row watches the gate with the issue and re-checks it before the portal and the charged monthly switch, including an open sheet; Monthly Shown fires only when the switch shows. The shared paywall checkout starts no Stripe Checkout for a paid Stripe reader on a Play build (same-price reactivation only, and only a reactivated answer), drops a Checkout URL that answers after Play arrived, and the hosted paywall closes and loads nothing once Play is known. The getter documents its failed-refresh contract. Copy: 'Billed through omi.me. Cancel here anytime.', the short form next to Resubscribe, and one Home line.
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 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.
Problem
Google rejected every Android update since Oct 24 for payments reasons. Play Billing is merged and off in prod. The money review of turning it on (play-go-nogo.md §1.3, §3, §8) found that on an Android build that uses Play, a reader who already pays on Stripe still sees Stripe purchase actions: tier change and the yearly switch in Plans & Billing (plans_sheet.dart:545-552, yearly_switch.dart:34-44), the promo field, the Stripe portal, the Home payment row's portal and charged monthly switch (payment_issue_row.dart:158-180), and Subscribe on paid Marketplace apps (app_detail.dart:925-932).
playBilledPurchaser(usage_provider.dart:157-160) excludes every paid non-Play plan on purpose, so none of these were gated.Change
One new getter,
UsageProvider.buysThroughPlay: Play config present on Android, whatever the plan.playBilledPurchaseris unchanged for the purchase rail.For a reader on a Play build whose paid plan is billed by Stripe (not Play, not prepaid):
{"detail": "<sentence>", "code": "..."}): checkout (Plans & Billing and the paywall), upgrade, yearly switch and monthly switch show the sentence in their existing error spot foruse_google_play(409),play_subscription_on_hold(400) and the retryable Play-check refusal (any status, as long as it has a code). Never JSON. A 409 with no code still says "You already have a subscription". Afteruse_google_playthe app re-reads the subscription (fetchSubscription(fresh: true)), so the sheet moves to Play prices. A bare snake_case code is never shown as text.alreadyPaid). Same-price reactivation while cancel is pending is the one request allowed, and only areactivatedanswer is accepted. A Checkout URL that answers after Play setup arrived is dropped, never opened. The hosted paywall closes once Play is known and its navigation loads nothing on a Play build.buysThroughPlayfollows the last successful read. A failed refresh keeps the last known Play setup in force, so no Stripe action reopens; a failed first read is false while the existing failed/Retry state applies.Unchanged: iOS, web, desktop, Android without Play config (every production user today), Play-billed subscribers, prepaid plans, Free readers on a Play build.
Three strings, translated in all 49 locales via
scripts/l10n.py.Files:
usage_provider.dart,plans_sheet.dart,payment_issue_row.dart,yearly_switch.dart,monthly_switch_sheet.dart,app_detail.dart,paywall_checkout.dart,backend/http/api/payment.dart.Impact estimate
If the Play build still offered Stripe purchases to existing subscribers, Google could reject the update again (Android has had no update since Oct 24; 98.8% of Android users are on 1.0.573). With this, the Play build offers Google Play for every new purchase; existing Stripe subscribers keep their plan and can cancel.
Evidence
Widget-test renders (Android, Play config present, Stripe-billed Omi Pro). The orchestrator takes Android emulator shots on the internal build after merge; this is Android-only behaviour behind a server config, so there is no iOS simulator shot.
Renders, default and largest text:
~/mobile-ux-agent/runs/2026-11-24/g2/(--dart-define=SURFACE_RENDER_OUTPUT=<dir>on the tests below).Tests
New, each fails on main's UI code (14 failures with the six UI files reverted):
play_billing_plans_sheet_test.dart: Stripe subscriber on a Play build at text x1 and x3.2 (no Upgrade, period toggle, yearly switch, code field, payment method; Cancel not truncated); cancel-pending Resubscribe never opens Checkout; reactivation confirms; iOS and non-Play Android keep the full Stripe sheet; Free reader still gets Play; on both checkout surfaces (plans sheet and paywall) each of the three refusals shows its sentence, onlyuse_google_playmoves the sheet to Play prices, and a 409 with no code keeps the old text.payment_issue_row_test.dart: Play build at x1 and x3.2 opens nothing; iOS and non-Play Android keep Update and Switch to Monthly; monthly switch shows both refusals.yearly_switch_test.dart: Play build never offers or reads the switch; iOS keeps it; both refusals.app_detail_paid_billing_test.dart: Stripe subscriber on a Play build at x1 and x3.2 gets "Not available on Android"; non-Play Android and iOS keep Subscribe; a paid app with no payment link shows the unavailable state on Android (with or without Play setup).app_install_flow_test.dart: the missing-link test now covers iOS (error on tap) and Android (unavailable state); neither calls enable.unit/payment_refusal_test.dart: refusal parsing.reactivated; hosted paywall closes and its navigation is blocked; success to failed refresh to recovery keeps Cancel and never shows a Stripe purchase action;outline_paywall_page_test.dartcloses onalreadyPaid.Ran locally (Flutter 3.44.5): those plus quiet_payer_row, plans_sheet_{selection,checkout_refresh,redeem_code,cancel_pending}, storefront_checkout_handoff, billing_currency_surfaces, contextual_plans_fallback, plan_refresh_on_resume, paywall_router, value_moment_paywall, app_install_flow, paywall_experiment and the four usage_provider suites: all pass.
flutter analyzeon changed files: clean.l10n.py check: ok.make preflight: passed.Not verified
play_check_unavailable, 503). Any coded refusal shows its sentence whatever the status.PaywallOffer.forUsagestill builds the Stripe catalog offer for a paid Stripe reader on a Play build; the purchase is refused at the checkout boundary instead.Product invariants affected
none
Failure class (fixes)
Failure-Class: none
UI-Evidence: see the images above (.agent-artifacts/ui-evidence/mux-2026-11-24-play-no-stripe-actions)