Skip to content

Conversation

@Haidar0096
Copy link

Summary

Adds two new StoreKit 2 features to in_app_purchase_storekit:

  • SK2Transaction.unfinishedTransactions() - Queries only unfinished transactions for better performance
  • SK2PurchaseDetails.appAccountToken - Exposes user UUID for backend integration

Motivation

  1. Performance: Developers often only need unfinished transactions to complete them, not all historical transactions. This mirrors Apple's official Transaction.unfinished API.
  2. User Identification: The ability to set appAccountToken already exists when making purchases, but reading it back from transaction details was missing.

Changes

  • Added pigeon interface method for unfinishedTransactions()
  • Implemented Swift native code using Apple's Transaction.unfinished API
  • Exposed appAccountToken property in SK2PurchaseDetails
  • Added unit tests for both features

Breaking Changes

None. Both features are additive and maintain full backward compatibility.

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

Comment on lines 239 to 253
@MainActor in
do {
let transactionsMsgs = await rawUnfinishedTransactions().map {
$0.convertToPigeon(receipt: nil)
}
completion(.success(transactionsMsgs))
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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))

@Haidar0096
Copy link
Author

Haidar0096 commented Nov 15, 2025

This also partially solves #165355

…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.
@Haidar0096 Haidar0096 force-pushed the add-storekit2-transaction-unfinished-and-appaccounttoken branch from dabe171 to fa16cac Compare November 16, 2025 19:00
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.

1 participant