Skip to content

Let Google Play builds redeem a bundle or prepaid code in the app - #26247

Merged
kodjima33 merged 10 commits into
mainfrom
mux/2026-11-24-play-code-entry
Nov 24, 2026
Merged

kodjima33 merged 10 commits into
mainfrom
mux/2026-11-24-play-code-entry

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 Stop Stripe and Google Play from both charging one user #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 Stop Stripe and Google Play from both charging one user #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 ." 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/.

Play plans sheet with Have a code?
Play plans sheet, largest text
Trial paywall on a Play build
Trial paywall, largest text

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 Stop Stripe and Google Play from both charging one user #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 Stop Stripe and Google Play from both charging one user #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.

Home payment row on a Play build
Home payment row, largest text

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

A Play build has no other way to activate a bundle or prepaid code. The
subscription response offers redemption to every Play client and the
redeem route accepts it, with the same code checks, single use, claim
handling and live-plan refusals on both Stripe and Google Play. Every
other client and today's production settings get main's exact bytes.
A free reader on a Play build sees the existing code entry under
Subscribe and Restore in Plans & Billing, and on the trial paywall. It
opens the existing prepaid code sheet; paid readers never see it. A
prepaid plan on a Play build shows its end date, never the Stripe
storefront. Plan cards stack the price under the title at accessibility
text sizes so the Play sheet no longer overflows.
@kodjima33 kodjima33 added the mux-proposal Mobile UX improver (MUX) proposal; waits for Nik's ship label Nov 24, 2026
@mintlify

mintlify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Nov 24, 2026, 2:51 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

…sed row copy

An open Outline, Trial or trial upsell paywall closes, with nothing
bought, once the reader turns out to pay outside Play on a Play build
(same-price Resubscribe while a cancel is pending stays). The hosted
paywall re-checks the Play gate after its catalog wait and a closed page
navigates nowhere. The Home payment row on a Play build says the plan is
paused and names no place to pay. A 400 play_check_unavailable keeps
Confirm in the monthly switch, and the tests use the backend's real
statuses.
…otect a prepaid term next to Play

Paywall auto-close acts only when the paywall is the top route, so a
redeemed code's success sheet stays until Done and the paywall then
closes as redeemed. The code entry hides for a past-due Stripe agreement
and after a failed latest subscription read. Redemption re-reads Google
Play right before the Stripe create and releases the claim if Play is
now live; the Stripe and Play overlap guards never cancel a prepaid
subscription and log prepaid_code_play_overlap for a person instead.
@kodjima33
kodjima33 merged commit 19fd0a8 into main Nov 24, 2026
70 checks passed
@kodjima33
kodjima33 deleted the mux/2026-11-24-play-code-entry branch November 24, 2026 16:54
kodjima33 added a commit that referenced this pull request Nov 24, 2026
…code and asks to retry (#26256)

## What changed and why

Follow-up to #26247, from its round 2 money review. When a prepaid or
bundle code is redeemed, the code is claimed, then the reader's Google
Play state is read once more before the no-card plan is created. If that
second read failed with a storage error (not a typed refusal), the
exception escaped: the route answered 500 and the claim stayed on the
code with no plan created.

Now a storage failure at that point frees the code and answers the
existing 503 `try_again`, so the reader can redeem again. If freeing the
claim itself fails, the claim stays with the same reader and their retry
resumes it, as before. Nothing is created in either case.

Play Billing is still off in prod, and the redemption switch is `cohort`
with an empty cohort, so only the one throwaway test account can reach
this path today.

## Product invariants affected

none

## How it was verified

- `backend/tests/unit/test_play_prepaid_code_entry.py`: two new tests. A
storage failure at the re-check ends in 503 `try_again` with the claim
released and no Stripe create, and the same reader's retry then gets the
plan. A failed release keeps the claim with the reader and still returns
the typed refusal. Both fail without the fix.
- `test_play_prepaid_code_entry.py` and
`test_prepaid_code_redemption.py`: 123 passed.

## Failure class

No `fix:` commits; no declaration required.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/26256?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/26256?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26256&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. -->
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