Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## NEXT

* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
* Add `jwsRepresentation` to `SK2PurchaseDetails` as `serverVerificationData`
* Add `jsonRepresentation` to `SK2PurchaseDetails` as `localVerificationData`
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a bit color to what are jwsRepresentation and jsonRepresentation? Also maybe which jwsRepresentation and jsonRepresentation since there are several fields with identical names in the StoreKit documentation. The 2 lines seem a bit vague without the context.


Copy link
Contributor

@LouiseHsu LouiseHsu Jun 2, 2025

Choose a reason for hiding this comment

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

The reason the repo_check is failing is b/c of this - could you add lines 3-5 to a new 0.4.1 version and remove the NEXT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I updated to 0.4.2 since 0.4.1 just got merged in recently. Hope that is okay 🙏

## 0.4.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extension InAppPurchasePlugin: InAppPurchase2API {
case .success(let verification):
switch verification {
case .verified(let transaction):
self.sendTransactionUpdate(transaction: transaction)
self.sendTransactionUpdate(
transaction: transaction, receipt: "\(verification.jwsRepresentation)")
Copy link
Contributor

Choose a reason for hiding this comment

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

(here and below) I don't think the string interpolation here is necessary, since jwsRepresentation is a string itself: https://developer.apple.com/documentation/storekit/verificationresult/jwsrepresentation-21vgo (if I'm looking at the right jwsRepresentation, that is)

completion(.success(result.convertToPigeon()))
case .unverified(_, let error):
completion(.failure(error))
Expand Down Expand Up @@ -191,7 +192,8 @@ extension InAppPurchasePlugin: InAppPurchase2API {
for await verificationResult in Transaction.updates {
switch verificationResult {
case .verified(let transaction):
self?.sendTransactionUpdate(transaction: transaction)
self?.sendTransactionUpdate(
transaction: transaction, receipt: "\(verificationResult.jwsRepresentation)")
case .unverified:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ extension on SK2TransactionMessage {
// receipt isn’t necessary with SK2 as a Transaction can only be returned
// from validated purchases.
verificationData: PurchaseVerificationData(
localVerificationData: '', serverVerificationData: '', source: ''),
localVerificationData: jsonRepresentation ?? '',
// receiptData is the JWS representation of the transaction
serverVerificationData: receiptData ?? '',
source: kIAPSource),
transactionDate: purchaseDate,
// Note that with SK2, any transactions that *can* be returned will
// require to be finished, and are already purchased.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_storekit
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.4.0
version: 0.4.1

environment:
sdk: ^3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,7 @@ SK2TransactionMessage createPendingTransaction(String id, {int quantity = 1}) {
originalId: 2,
productId: id,
purchaseDate: 'purchaseDate',
appAccountToken: 'appAccountToken');
appAccountToken: 'appAccountToken',
receiptData: 'receiptData',
jsonRepresentation: 'jsonRepresentation');
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,38 @@ void main() {
purchaseParam: purchaseParam, autoConsume: false),
throwsA(isInstanceOf<AssertionError>()));
});

test(
'buying consumable, should get PurchaseVerificationData with serverVerificationData and localVerificationData',
() async {
final List<PurchaseDetails> details = <PurchaseDetails>[];
final Completer<List<PurchaseDetails>> completer =
Completer<List<PurchaseDetails>>();
final Stream<List<PurchaseDetails>> stream =
iapStoreKitPlatform.purchaseStream;

late StreamSubscription<List<PurchaseDetails>> subscription;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: final instead of late?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it has to be late since it is being referenced inside the listen callback. So it is being referenced before it is initialized.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I didn't notice that. Could you make it late final then, since it looks like subscription isn't getting re-assigned later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, just updated ✅

subscription = stream.listen((List<PurchaseDetails> purchaseDetailsList) {
details.addAll(purchaseDetailsList);
if (purchaseDetailsList.first.status == PurchaseStatus.purchased) {
completer.complete(details);
subscription.cancel();
}
});
final AppStorePurchaseParam purchaseParam = AppStorePurchaseParam(
productDetails:
AppStoreProduct2Details.fromSK2Product(dummyProductWrapper),
applicationUserName: 'appName');
await iapStoreKitPlatform.buyConsumable(purchaseParam: purchaseParam);

final List<PurchaseDetails> result = await completer.future;
expect(result.length, 1);
expect(result.first.productID, dummyProductWrapper.id);
expect(
result.first.verificationData.serverVerificationData, 'receiptData');
expect(result.first.verificationData.localVerificationData,
'jsonRepresentation');
});
});

group('restore purchases', () {
Expand Down