Always redeem existing web codes after a successful purchase and on restore#435
Merged
Conversation
Injects a redeemExistingCodes suspend closure into TransactionManager and invokes it in didPurchase (both internal and external/observer success branches) and didRestore. The closure is wired in DependencyContainer to call reedemer.redeem(RedeemType.Existing), following the AttributionManager.redeemAfterSetting precedent so TransactionManager never references the redeemer directly. Mirrors iOS PR #490 / SW-5516.
…ase-restore # Conflicts: # .benchmark/REPORT.md # .benchmark/results/preload-benchmark-high.json # .benchmark/results/preload-benchmark-low.json # .benchmark/results/preload-benchmark-mid.json
ianrumac
marked this pull request as ready for review
July 22, 2026 13:55
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.
Requested by Ian Rumac · Slack thread
Changes in this pull request
Always redeem existing web codes after a successful Google Play purchase and on restore, so a new or restored subscription is linked to the identified user server-side right away.
Before
A successful Google Play purchase or a restore did not call
/redeem. As a result, a newly purchased or restored subscription was not linked to the identified user on the backend until some other trigger happened to fire a redeem. Until then, the server's view of the user's entitlement state could lag behind reality.After
Both a successful purchase and a successful restore now trigger a redeem of existing codes, pushing the current entitlement state to the backend immediately as part of the same flow.
How
The redeem is injected into
TransactionManageras asuspend () -> Unitclosure (redeemExistingCodes), following the existingAttributionManager.redeemAfterSettingprecedent, rather than havingTransactionManagerreferenceWebPaywallRedeemerdirectly.DependencyContainerwires the closure toreedemer.redeem(WebPaywallRedeemer.RedeemType.Existing). Because the param issuspend, it calls the suspendredeemdirectly — noioScope.launchwrapper is needed since it is already invoked from a coroutine insideTransactionManager.The closure is hooked in:
didPurchase(...)— invoked afterloadPurchasedProducts(...)in both the internal-paywall branch and the external/observer branch, so it fires exactly once per successful purchase.didPurchaseis only reached onPurchaseResult.Purchased, so it is success-only; test mode returns beforedidPurchase.didRestore(...)— invoked at the end, after entitlement/subscription-status handling.didRestoreis only reached on a successful restore, and test mode returns before it, so success-only and test-mode-skip come for free.The default value is a no-op (
{}) so existing constructors and tests are unaffected.Notes
didPurchase, so they naturally do not redeem, which is consistent with iOS.Mirrors iOS PR #490 / Linear SW-5516.
Checklist
CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.ktlintin the main directory and fixed any issues.Generated by Claude Code