Skip to content

[in_app_purchase] Return jwsRepresentation and jsonRepresentation for StoreKit2 #9280

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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,3 +1,8 @@
## 0.4.2

* Add [jwsRepresentation](https://developer.apple.com/documentation/storekit/verificationresult/jwsrepresentation-21vgo) to `SK2PurchaseDetails` as `serverVerificationData` for secure server-side purchase verification. Use this JSON Web Signature (JWS) value to perform your own JWS verification on your server.
* Add [jsonRepresentation](https://developer.apple.com/documentation/storekit/transaction/jsonrepresentation) to `SK2PurchaseDetails` as `localVerificationData` for local transaction debugging and verification.

## 0.4.1

* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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)
completion(.success(result.convertToPigeon()))
case .unverified(_, let error):
completion(.failure(error))
Expand Down Expand Up @@ -284,7 +285,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.1
version: 0.4.2

environment:
sdk: ^3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,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 @@ -154,6 +154,38 @@ void main() {
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 final StreamSubscription<List<PurchaseDetails>> subscription;
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');
});

test('should process Sk2PurchaseParam with winBackOfferId only', () async {
final Sk2PurchaseParam purchaseParam = Sk2PurchaseParam(
productDetails:
Expand Down