Skip to content

Commit 2e166de

Browse files
authored
[in_app_purchase_storekit] Make Storekit 2 the default (#9178)
Make Storekit 2 the default. Fixes flutter/flutter#159871 ## Pre-Review Checklist
1 parent 6affa42 commit 2e166de

File tree

11 files changed

+49
-13
lines changed

11 files changed

+49
-13
lines changed

packages/in_app_purchase/in_app_purchase/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 3.2.2
22

3+
* Updates `in_app_purchase_storekit` to 0.4.0
4+
* Updates README with Storekit 2 examples.
35
* Updates README to indicate that Andoid SDK <21 is no longer supported.
46

57
## 3.2.1

packages/in_app_purchase/in_app_purchase/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ if (productDetails is AppStoreProductDetails) {
356356
SKProductWrapper skProduct = (productDetails as AppStoreProductDetails).skProduct;
357357
print(skProduct.subscriptionGroupIdentifier);
358358
}
359+
360+
// With StoreKit 2
361+
import 'package:in_app_purchase_storekit/store_kit_2_wrappers.dart';
362+
363+
if (productDetails is AppStoreProduct2Details) {
364+
SK2Product product = (productDetails as AppStoreProduct2Details).sk2Product;
365+
print(product.subscription?.subscriptionGroupID);
366+
}
359367
```
360368

361369
The `purchaseStream` provides objects of type `PurchaseDetails`. PurchaseDetails' provides all
@@ -377,7 +385,7 @@ if (purchaseDetails is GooglePlayPurchaseDetails) {
377385
}
378386
```
379387

380-
How to get the `transactionState` of a purchase in iOS:
388+
How to get the `transactionState` of a purchase in iOS, using the original StoreKit API:
381389
```dart
382390
//import for AppStorePurchaseDetails
383391
import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart';
@@ -390,6 +398,15 @@ if (purchaseDetails is AppStorePurchaseDetails) {
390398
}
391399
```
392400

401+
How to get the `jsonRepresentation` of a transaction in iOS, using StoreKit 2:
402+
```dart
403+
//import for SK2TransactionWrapper
404+
import 'package:in_app_purchase_storekit/store_kit_2_wrappers.dart';
405+
406+
List<SK2Transaction> transactions = await SK2Transaction.transactions();
407+
print(transactions[0].jsonRepresentation);
408+
```
409+
393410
Please note that it is required to import `in_app_purchase_android` and/or `in_app_purchase_storekit`.
394411

395412
### Presenting a code redemption sheet (iOS 14)

packages/in_app_purchase/in_app_purchase/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase
22
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 3.2.1
5+
version: 3.2.2
66

77
environment:
88
sdk: ^3.5.0

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.4.0
2+
3+
* **BREAKING CHANGE:** StoreKit 2 is now the default for all devices that support it.
4+
* To revert to StoreKit1 for devices below iOS 15, call `enableStoreKit1`
5+
16
## 0.3.22+1
27

38
* Fix a channel thread-safety issue when StoreKit2 is enabled.

packages/in_app_purchase/in_app_purchase_storekit/example/lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'consumable_store.dart';
1212
import 'example_payment_queue_delegate.dart';
1313

1414
void main() {
15-
InAppPurchaseStoreKitPlatform.enableStoreKit2();
1615
WidgetsFlutterBinding.ensureInitialized();
1716
// When using the Android plugin directly it is mandatory to register
1817
// the plugin as default instance as part of initializing the app.

packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_storekit_platform.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
3131
InAppPurchaseStoreKitPlatform();
3232

3333
/// Experimental flag for StoreKit2.
34-
static bool _useStoreKit2 = false;
34+
static bool _useStoreKit2 = true;
3535

3636
/// StoreKit1
3737
static late SKPaymentQueueWrapper _skPaymentQueueWrapper;
@@ -251,10 +251,17 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
251251
@Deprecated('Use countryCode')
252252
Future<String?> getCountryCode() => countryCode();
253253

254-
/// Turns on StoreKit2. You cannot disable this after it is enabled.
255-
/// This can only be enabled if your device supports StoreKit 2.
254+
/// StoreKit 2 is now the default.
255+
@Deprecated('StoreKit 2 is now the default')
256256
static Future<bool> enableStoreKit2() async {
257-
_useStoreKit2 = await SKRequestMaker.supportsStoreKit2();
257+
_useStoreKit2 = true;
258+
return true;
259+
}
260+
261+
/// Call this before `registerPlatform` to re-enable StoreKit1
262+
@Deprecated('Please note that StoreKit 1 will be removed in the future.')
263+
static Future<bool> enableStoreKit1() async {
264+
_useStoreKit2 = !(await SKRequestMaker.supportsStoreKit2());
258265
return _useStoreKit2;
259266
}
260267
}

packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_transaction_wrapper.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class SK2Transaction {
2727
required this.appAccountToken,
2828
this.subscriptionGroupID,
2929
this.price,
30-
this.error});
30+
this.error,
31+
this.jsonRepresentation});
3132

3233
/// The unique identifier for the transaction.
3334
final String id;
@@ -62,6 +63,9 @@ class SK2Transaction {
6263
/// Any error returned from StoreKit
6364
final SKError? error;
6465

66+
/// The json representation of a transaction
67+
final String? jsonRepresentation;
68+
6569
/// Wrapper around [Transaction.finish]
6670
/// https://developer.apple.com/documentation/storekit/transaction/3749694-finish
6771
/// Indicates to the App Store that the app delivered the purchased content
@@ -105,7 +109,8 @@ extension on SK2TransactionMessage {
105109
productId: productId,
106110
purchaseDate: purchaseDate,
107111
expirationDate: expirationDate,
108-
appAccountToken: appAccountToken);
112+
appAccountToken: appAccountToken,
113+
jsonRepresentation: jsonRepresentation);
109114
}
110115

111116
PurchaseDetails convertToDetails() {

packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_storekit
22
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.3.22+1
5+
version: 0.4.0
66

77
environment:
88
sdk: ^3.4.0

packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi {
3333
bool isPaymentQueueDelegateRegistered = false;
3434
String _countryCode = 'USA';
3535
String _countryIdentifier = 'LL';
36+
bool shouldStoreKit2BeEnabled = true;
3637

3738
void reset() {
3839
transactionList = <SKPaymentTransactionWrapper>[];
@@ -283,7 +284,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi {
283284

284285
@override
285286
bool supportsStoreKit2() {
286-
return true;
287+
return shouldStoreKit2BeEnabled;
287288
}
288289
}
289290

packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_2_platform_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void main() {
4040
InAppPurchaseStoreKitPlatform.registerPlatform();
4141
iapStoreKitPlatform =
4242
InAppPurchasePlatform.instance as InAppPurchaseStoreKitPlatform;
43-
InAppPurchaseStoreKitPlatform.enableStoreKit2();
4443
fakeStoreKit2Platform.reset();
4544
});
4645

packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void main() {
2626
});
2727

2828
setUp(() {
29+
InAppPurchaseStoreKitPlatform.enableStoreKit1();
2930
InAppPurchaseStoreKitPlatform.registerPlatform();
3031
iapStoreKitPlatform =
3132
InAppPurchasePlatform.instance as InAppPurchaseStoreKitPlatform;

0 commit comments

Comments
 (0)