-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fixes StoreKit 2 purchase flow to send cancelled/pending/unverified results to purchaseStream. #10736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…celled/pending/unverified results to purchaseStream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses an issue where certain StoreKit 2 purchase outcomes (cancelled, pending) were not being reported on the purchaseStream. The approach of manually creating and emitting PurchaseDetails for these cases is sound and correctly implemented. The accompanying changes to the fake platform and the new tests are thorough, ensuring the new logic is well-verified. I have one suggestion to improve the maintainability of the new tests by reducing code duplication.
.../in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_2_platform_test.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing! The changes make sense but I wonder if it should be implemented in the swift code instead?
| // For userCancelled and pending results, manually send update to the stream | ||
| // since native side only sends transaction for success cases (both verified and unverified). | ||
| // Note: unverified is handled by native side as it's part of .success case in StoreKit. | ||
| if (result == SK2ProductPurchaseResult.userCancelled || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: prefer using switch statements for the analyzer's exhaustiveness check / feedback.
| ); | ||
|
|
||
| // For userCancelled and pending results, manually send update to the stream | ||
| // since native side only sends transaction for success cases (both verified and unverified). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to change the native side to send transactions for both cancel / pending cases then?
|
Hmm I do have some concerns regarding adding this to the purchaseStream, right now it seems purchaseStream only emits verified transactions? So is it possible that some developers might not be checking the status of the transaction / purchase detail and just assume it's verified? Or in most cases existing users of the API should already be checking the |
Thanks for raising this — that’s a valid concern. While it may look like purchaseStream only emits verified transactions today, consumers are already expected to rely on the status field rather than assume verification. In particular, the Android Play Store implementation already emits non-success states (e.g. pending, canceled) through the same stream. From that perspective, this change is less about expanding the contract and more about bringing StoreKit 2 in line with the existing cross-platform behavior, avoiding a situation where certain outcomes are silently dropped on iOS. if you think this needs further adjustment, I’m happy to revise the implementation and move the handling to the Swift side instead. |
Fixes StoreKit 2 purchase flow to send cancelled/pending/unverified results to purchaseStream.
flutter/flutter#176757
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3