-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[in_app_purchase_storekit] Add Transaction.unfinished API and expose appAccountToken #10439
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?
[in_app_purchase_storekit] Add Transaction.unfinished API and expose appAccountToken #10439
Conversation
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 introduces two new features from StoreKit 2: the unfinishedTransactions() API and the exposure of appAccountToken on purchase details. The changes are additive, well-implemented, and follow the existing architecture. The implementation correctly spans native Swift code, pigeon interface updates, and Dart-side wrappers, complete with corresponding unit tests. This is a solid contribution that enhances the plugin's capabilities.
| @MainActor in | ||
| do { | ||
| let transactionsMsgs = await rawUnfinishedTransactions().map { | ||
| $0.convertToPigeon(receipt: nil) | ||
| } | ||
| completion(.success(transactionsMsgs)) | ||
| } |
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.
The do block is unnecessary here because rawUnfinishedTransactions() is a non-throwing function. While it doesn't cause a bug in this case, it's a good practice to avoid do-catch structures when no errors can be thrown and caught. If rawUnfinishedTransactions were to throw, the lack of a catch block would prevent the completion handler from being called on an error path. Removing the do block simplifies the code and makes it more robust.
@MainActor in
let transactionsMsgs = await rawUnfinishedTransactions().map {
$0.convertToPigeon(receipt: nil)
}
completion(.success(transactionsMsgs))|
This also partially solves #165355 |
dabe171 to
fa16cac
Compare
LouiseHsu
left a comment
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.
This looks good!! Thank you so much for your contribution. I took a look, and the test failures seems to be half swift formatting errors and pigeon files. Could you upgrade pigeon and regenerate the files + fix the swift formatting errors? Otherwise looks good!
fa16cac to
1c0aecc
Compare
|
@LouiseHsu Thanks for the kind words! Problem with updating pigeon to the latest version is that when I run I downgraded pigeon until I found a working version (i.e. version before the introduction of the generation of == method) Here is one of the error logs when running on real device after updating pigeon to the latest version 26.1.0: Generated file that is causing the errorHere is the version that introduced this behavior in the generated code What I am going to do now is pin pigeon to the latest version I found that works (25.2.0) and push the changes. Do you think this works? |
|
A repo-wide update of all packages to Pigeon 26 landed yesterday, FYI. |
|
@stuartmorgan-g I fetched it locally, and ran the pigeon generator, and I am hitting Commands I ran: # Verify pigeon version
cd packages/in_app_purchase/in_app_purchase_storekit
dart pub deps | grep pigeon
# Output: ├── pigeon 26.1.0
# Regenerate pigeon
dart run pigeon --input pigeons/sk2_pigeon.dart
# Check format
cd ../../..
dart run script/tool/bin/flutter_plugin_tools.dart format --packages
in_app_purchase_storekitResult: The weird thing: upstream/main's generated file has the |
|
Sorry, I meant to follow up on that this morning and had forgotten. I filed flutter/flutter#178736 to track the problem; for now you can just manually add those (which is what I did to unblock the roll). (Longer term we need to fix that issue, and/or change the output names of these Pigeon files.) |
|
@stuartmorgan-g ohh I thought claude was hallucinating when it told me the flutter team added them manually😂😂 Thank you for the guidance, will supress them manually then and update the PR🙏🏻 And a suggestion, if this takes some time to fix (the pigeon issue), maybe mention this as a note in the pigeon section so new comers like me know that they are not doing anything wrong in their setup but rather they should supress such errors (to be specified) manually for now. |
1c0aecc to
f8257a4
Compare
Having to make manual changes is extremely rare, and my plan was to resolve this case ASAP; it confuses everyone (not just newcomers). I wouldn't have done it at all except that it was blocking an important change in flutter/flutter for complex reasons. Yesterday I thought this was a quick Pigeon fix that I would do today, but having investigated the cause more I'll probably change the Swift filenames for this package today as the short-term fix. |
|
The remaining failing check as per logs is due to: I don't have an option to rerun the check to try it again. |
This landed as #10465, so the manual change is no longer necessary. |
…aseDetails This PR adds two new features to in_app_purchase_storekit for StoreKit 2: 1. SK2Transaction.unfinishedTransactions() - Queries only unfinished transactions, mirroring Apple's Transaction.unfinished API for better performance. 2. SK2PurchaseDetails.appAccountToken - Exposes the UUID that associates transactions with users in custom backend systems. Both features are additive and maintain full backward compatibility. Tests included for both features.
Previously returned nil for receipt data, now properly includes jwsRepresentation for server-side verification.
swift-format-ignore comments for deepEqualssk2_pigeon and deepHashsk2_pigeon functions as a workaround for flutter/flutter#178736.
f8257a4 to
6445537
Compare

Summary
Adds two new StoreKit 2 features to
in_app_purchase_storekit:SK2Transaction.unfinishedTransactions()- Queries only unfinished transactions for better performanceSK2PurchaseDetails.appAccountToken- Exposes user UUID for backend integrationMotivation
Transaction.unfinishedAPI.appAccountTokenalready exists when making purchases, but reading it back from transaction details was missing.Changes
unfinishedTransactions()Transaction.unfinishedAPIappAccountTokenproperty inSK2PurchaseDetailsBreaking Changes
None. Both features are additive and maintain full backward compatibility.