Fix iOS purchase receipt loss after backend acknowledgment failure#8817
Open
atavism wants to merge 3 commits into
Open
Fix iOS purchase receipt loss after backend acknowledgment failure#8817atavism wants to merge 3 commits into
atavism wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves iOS in-app purchase reliability by preventing StoreKit transactions from being completed until the Lantern backend successfully acknowledges the receipt, reducing the chance of “lost” receipts after transient backend/network failures.
Changes:
- Registers
LanternPlatformServiceearlier so startup purchase updates can safely call backend APIs. - Persists selected plan metadata for pending purchases so retries can send the intended
planId. - Adds acknowledgement retry logic (short backoff) and keeps transactions pending on ack failure; relies on fresh backend user state before treating purchases as already active.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/core/services/injection_container.dart | Registers LanternPlatformService before AppPurchase init to support early purchase update handling. |
| lib/core/services/app_purchase.dart | Adds pending plan persistence + ack retry flow; avoids completing iOS transactions until backend ack succeeds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+724
to
+737
| if (attempt >= _ackRetryDelays.length) { | ||
| appLogger.warning( | ||
| '[AppPurchase] Acknowledgment retries exhausted; StoreKit transaction ' | ||
| 'remains pending: productID=${purchaseDetails.productID} ' | ||
| 'purchaseID=${purchaseDetails.purchaseID}', | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| final delay = _ackRetryDelays[attempt]; | ||
| _ackRetryAttempts[key] = attempt + 1; | ||
| appLogger.info( | ||
| '[AppPurchase] Scheduling acknowledgment retry ${attempt + 1}/' | ||
| '${_ackRetryDelays.length} in $delay: ' |
Comment on lines
+733
to
+739
| final delay = _ackRetryDelays[attempt]; | ||
| _ackRetryAttempts[key] = attempt + 1; | ||
| appLogger.info( | ||
| '[AppPurchase] Scheduling acknowledgment retry ${attempt + 1}/' | ||
| '${_ackRetryDelays.length} in $delay: ' | ||
| 'productID=${purchaseDetails.productID} purchaseID=${purchaseDetails.purchaseID}', | ||
| ); |
Comment on lines
+862
to
+871
| try { | ||
| final decoded = jsonDecode(raw); | ||
| if (decoded is Map) { | ||
| return decoded.map( | ||
| (key, value) => MapEntry(key.toString(), value.toString()), | ||
| ); | ||
| } | ||
| } catch (e, st) { | ||
| appLogger.error('Failed to parse pending purchase plans', e, st); | ||
| } |
jigar-f
reviewed
May 29, 2026
Contributor
There was a problem hiding this comment.
@atavism, let's not merge this yet. Let's test this thoroughly because at the moment, our Apple payment is stable.
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.
Partially resolves https://github.com/getlantern/engineering/issues/3557