Skip to content

Conversation

@linchen00
Copy link

Fixes StoreKit 2 purchase flow to send cancelled/pending/unverified results to purchaseStream.

flutter/flutter#176757

Pre-Review Checklist

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-assist bot 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

  1. 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

…celled/pending/unverified results to purchaseStream.
Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a 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 ||
Copy link
Contributor

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).
Copy link
Contributor

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?

@LongCatIsLooong
Copy link
Contributor

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 status since the Android playstore implementation is already sending the events to the purchase stream?

@linchen00
Copy link
Author

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 status since the Android playstore implementation is already sending the events to the purchase stream?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants