Repository navigation
Let Google Play builds redeem a bundle or prepaid code in the app - #26247
Merged
Merged
Conversation
…re/omi into mux/2026-11-24-play-code-entry
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.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 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
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. -->
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 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.dartcanRedeemPrepaidCode,play_plans_content.darthas no code row, the trial paywall hides the hint) and the server answers 409play_billedto 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):client_uses_play(platform, build, uid)is true can redeem whateverPREPAID_CODE_REDEEMand its cohort say:GET /v1/users/me/subscriptioncarriesprepaid_code_redeem: true, andPOST /v1/payments/prepaid-code/redeemruns the redemption instead of 409play_billed/ 404.play_check_unavailableas a 503try_again).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 isactiveuntil its term). Tests added, no code change needed.App:
play_plans_content.dart: a free reader on a Play build sees the existing "Have a code?" entry (samePrepaidCodeEntry, 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.usage_provider.dartcanRedeemPrepaidCode: 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.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):ANDROID_BILLING=stripe, empty Play cohort,PREPAID_CODE_REDEEM=cohortwith 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). WithANDROID_BILLING=play, every non-Play client also gets main's bytes.prepaid_code_redeemadded 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.code_used; refused withhas_plannext to a live Stripe subscription, a live Play row, an active, on-hold or paused Play purchase read from fake Google; 503try_againwhen Google cannot be read; nothing created or claimed in each refusal.stripe_subscription_activeand nothing granted; a stored prepaid row also blocks; an ended prepaid plan does not.test_prepaid_code_redemption.py(the old 409play_billedtest now asserts the Play client redeems and iOS / old Android still follow the switch) andtest_play_billing.py(Play build response now also carriesprepaid_code_redeem).test_play_prepaid_code_entry,test_prepaid_code_redemption,test_play_billing,test_play_billing_guards,test_play_billing_money, alltest_payment_*andtest_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 analyzeon changed files: one existing info in trial_paywall_page.dart:185 (not touched).make preflightwith this body.Review round 1 fixes (#26247)
ModalRoute.of(context)?.isCurrent, re-checked in the post-frame callback) and does not latch_dismissed/_closedwhen it skips.ModalRoute.ofrebuilds the page when it is on top again. On the Trial paywall the code-success sheet stays until Done or Android back, then the existingonRedeemedcloses the paywall withtrue. 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.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 apayment_issueand astripe_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_planfrom 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).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 409has_plan; Google unreadable releases it and answers 503try_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 logsprepaid_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.prepaid_code_redeem: trueand 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 withtrue; 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, resultfalse, a later refresh pops nothing; past-due Stripe and failed latest read hide the entry on the plans sheet and the Trial paywall, keepbuysThroughPlay, 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). Backendtest_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.pyread 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".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 withfalseas 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.scripts/l10n.py; the old key is removed. Off a Play build the row is unchanged.web_paywall_page.dartre-checks closed, mounted and the Play gate after the catalog await and before building the controller or callingloadRequest; a closed or disposed page's navigation delegate always answers prevent.use_google_play, 400play_subscription_on_hold, 400play_check_unavailable.monthly_switch_sheet.dart: a 400play_check_unavailableis 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 resultfalse; cancel-pending Resubscribe stays; hosted page with Play arriving during the catalog wait records noloadRequest; a navigation callback after close answers prevent (and navigate while open, off Play); monthly 400play_check_unavailablekeeps Confirm; row copy names no place to pay. 7 of these fail with the five lib files reverted.Not in this PR
prepaid_code_play_overlaplog (runbook).has_plan.Not verified
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