Fix #5186: share ReceiptStore across Purchase instances#5188
Merged
Conversation
Display.getInAppPurchase() returns a fresh Purchase instance on every call on every port (iOS ZoozPurchase, Android ZoozPurchase, the JavaSE anonymous subclass), but receiptStore was a per-instance field. The native receipt path on iOS enters through the static Purchase.postReceipt(...) (invoked from StoreKit's paymentQueue:updatedTransactions:) which calls getInAppPurchase().postReceipt(r) on a brand-new instance whose receiptStore is null. As a result synchronizeReceipts() fell through to loadReceipts(), logged "No receipt store is currently registered" and the app's ReceiptStore.submitReceipt/fetchReceipts were never invoked for auto-submitted receipts -- only an explicit synchronizeReceipts call on the app's own configured instance worked. Make receiptStore static so the store configured via setReceiptStore is visible to the native auto-submit path regardless of which Purchase instance the call arrives on. There is logically one IAP store per app, so static is the correct scope. Access stays EDT-only by construction. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Cloudflare Preview
|
Collaborator
Author
|
Compared 124 screenshots: 124 matched. Native Android coverage
✅ Native Android screenshot tests passed. Native Android coverage
Benchmark ResultsDetailed Performance Metrics
|
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
Collaborator
Author
|
Compared 124 screenshots: 124 matched. Benchmark Results
Detailed Performance Metrics
|
Collaborator
Author
|
Compared 124 screenshots: 124 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
Collaborator
Author
|
Compared 124 screenshots: 124 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
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
Display.getInAppPurchase()returns a freshPurchaseinstance on every call on every port:IOSImplementation.getInAppPurchase()→new ZoozPurchase(...)AndroidImplementation.getInAppPurchase()→ZoozPurchase.class.newInstance()JavaSEPort.getInAppPurchase()→new Purchase() { ... }But
receiptStorewas a per-instance field. The native receipt path on iOS enters through the staticPurchase.postReceipt(...)(invoked from StoreKit'spaymentQueue:updatedTransactions:), which callsgetInAppPurchase().postReceipt(r)on a brand-new instance whosereceiptStoreisnull.So
synchronizeReceipts()fell through toloadReceipts(), logged "No receipt store is currently registered", and the app'sReceiptStore.submitReceipt/fetchReceiptswere never invoked for auto-submitted receipts. Only an explicitsynchronizeReceipts(...)call on the app's own configured instance worked — which is exactly the behavior reported in #5186 (receipts only submitted when the developer calledsynchronizeReceiptsSync(...)manually).Fix
Make
receiptStorestaticso the store installed viasetReceiptStore(...)is visible to the native auto-submit path regardless of whichPurchaseinstance the callback arrives on. There is logically one IAP store per app, so static is the correct scope. Access remains EDT-only by construction, consistent with the existingsyncInProgress/loadInProgress/synchronizeReceiptsCallbacksstatic state.Scope
This PR addresses only the confirmed, source-visible bug: the native auto-submit path never reaching the configured
ReceiptStore. The separate "app crashes right after a successful purchase" symptom in #5186 is not addressed here and its root cause is still undetermined — it needs the device crash log to diagnose.🤖 Generated with Claude Code