From 7fff7e56cedbcc967662794f2fc1a96b51b17e19 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 18 Nov 2020 15:15:42 +0100 Subject: [PATCH 01/14] Add Plugin Implementation --- .../ios/Classes/FIAPaymentQueueHandler.h | 1 + .../ios/Classes/FIAPaymentQueueHandler.m | 6 ++++++ .../ios/Classes/InAppPurchasePlugin.m | 7 +++++++ .../src/in_app_purchase/app_store_connection.dart | 5 +++++ .../src/in_app_purchase/google_play_connection.dart | 6 ++++++ .../in_app_purchase/in_app_purchase_connection.dart | 6 ++++++ .../store_kit_wrappers/sk_payment_queue_wrapper.dart | 12 ++++++++++++ 7 files changed, 43 insertions(+) diff --git a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.h b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.h index 54898d170304..a27855230adb 100644 --- a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.h +++ b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.h @@ -29,6 +29,7 @@ typedef void (^UpdatedDownloads)(NSArray *downloads); // Can throw exceptions if the transaction type is purchasing, should always used in a @try block. - (void)finishTransaction:(nonnull SKPaymentTransaction *)transaction; - (void)restoreTransactions:(nullable NSString *)applicationName; +- (void)presentCodeRedemptionSheet; - (NSArray *)getUnfinishedTransactions; // This method needs to be called before any other methods. diff --git a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m index ecbd237c90ce..513f3a19ed4e 100644 --- a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m +++ b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m @@ -66,6 +66,12 @@ - (void)restoreTransactions:(nullable NSString *)applicationName { } } +- (void)presentCodeRedemptionSheet { + if (@available(iOS 14.0, *)) { + [self.queue presentCodeRedemptionSheet]; + } +} + #pragma mark - observing // Sent when the transaction array has changed (additions or state changes). Client should check diff --git a/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m index 872a34a94954..f4b8726714d3 100644 --- a/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m @@ -93,6 +93,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self finishTransaction:call result:result]; } else if ([@"-[InAppPurchasePlugin restoreTransactions:result:]" isEqualToString:call.method]) { [self restoreTransactions:call result:result]; + } else if ([@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" isEqualToString:call.method]) { + [self presentCodeRedemptionSheet:call result:result]; } else if ([@"-[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString:call.method]) { [self retrieveReceiptData:call result:result]; } else if ([@"-[InAppPurchasePlugin refreshReceipt:result:]" isEqualToString:call.method]) { @@ -246,6 +248,11 @@ - (void)restoreTransactions:(FlutterMethodCall *)call result:(FlutterResult)resu result(nil); } +- (void)presentCodeRedemptionSheet:(FlutterMethodCall *)call result:(FlutterResult)result { + [self.paymentQueueHandler presentCodeRedemptionSheet]; + result(nil); +} + - (void)retrieveReceiptData:(FlutterMethodCall *)call result:(FlutterResult)result { FlutterError *error = nil; NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&error]; diff --git a/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart b/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart index a244ab13fc28..1f08ed4eaa08 100644 --- a/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart +++ b/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart @@ -184,6 +184,11 @@ class AppStoreConnection implements InAppPurchaseConnection { ); return productDetailsResponse; } + + @override + Future presentCodeRedemptionSheet() { + _skPaymentQueueWrapper.presentCodeRedemptionSheet(); + } } class _TransactionObserver implements SKTransactionObserverWrapper { diff --git a/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart b/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart index b980bbd77d85..410d018911da 100644 --- a/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart +++ b/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart @@ -293,4 +293,10 @@ class GooglePlayConnection return purchaseDetails; } + + @override + Future presentCodeRedemptionSheet() { + throw UnsupportedError( + 'The method only works on iOS.'); + } } diff --git a/packages/in_app_purchase/lib/src/in_app_purchase/in_app_purchase_connection.dart b/packages/in_app_purchase/lib/src/in_app_purchase/in_app_purchase_connection.dart index f07ff96d4403..d38f356d56ef 100644 --- a/packages/in_app_purchase/lib/src/in_app_purchase/in_app_purchase_connection.dart +++ b/packages/in_app_purchase/lib/src/in_app_purchase/in_app_purchase_connection.dart @@ -243,6 +243,12 @@ abstract class InAppPurchaseConnection { /// Throws an [UnsupportedError] on Android. Future refreshPurchaseVerificationData(); + /// (App Store only) present Code Redemption Sheet. + /// Available on devices running iOS 14 and iPadOS 14 and later. + /// + /// Throws an [UnsupportedError] on Android. + Future presentCodeRedemptionSheet(); + /// The [InAppPurchaseConnection] implemented for this platform. /// /// Throws an [UnsupportedError] when accessed on a platform other than diff --git a/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart b/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart index ce38759c74ec..f1d1d3e74b86 100644 --- a/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart +++ b/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart @@ -135,6 +135,18 @@ class SKPaymentQueueWrapper { applicationUserName); } + /// Present Code Redemption Sheet + /// + /// Use this to allow Users to enter and redeem Codes + /// + /// This method triggers [`-[SKPayment + /// presentCodeRedemptionSheet]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/3566726-presentcoderedemptionsheet?language=objc) + Future presentCodeRedemptionSheet() async { + await channel.invokeMethod( + '-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]', + ); + } + // Triage a method channel call from the platform and triggers the correct observer method. Future _handleObserverCallbacks(MethodCall call) { assert(_observer != null, From 3a9e84c7c922016e81e010c2a481bd2eaf0d00db Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 18 Nov 2020 16:29:42 +0100 Subject: [PATCH 02/14] Adjust for Tests --- .../src/in_app_purchase/app_store_connection.dart | 4 ++-- .../src/in_app_purchase/google_play_connection.dart | 12 ++++++------ .../store_kit_wrappers/sk_payment_queue_wrapper.dart | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart b/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart index 1f08ed4eaa08..90dc7a3b7d8b 100644 --- a/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart +++ b/packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart @@ -186,8 +186,8 @@ class AppStoreConnection implements InAppPurchaseConnection { } @override - Future presentCodeRedemptionSheet() { - _skPaymentQueueWrapper.presentCodeRedemptionSheet(); + Future presentCodeRedemptionSheet() { + return _skPaymentQueueWrapper.presentCodeRedemptionSheet(); } } diff --git a/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart b/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart index 410d018911da..c3d6f2abc434 100644 --- a/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart +++ b/packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart @@ -166,6 +166,12 @@ class GooglePlayConnection 'The method only works on iOS.'); } + @override + Future presentCodeRedemptionSheet() async { + throw UnsupportedError( + 'The method only works on iOS.'); + } + /// Resets the connection instance. /// /// The next call to [instance] will create a new instance. Should only be @@ -293,10 +299,4 @@ class GooglePlayConnection return purchaseDetails; } - - @override - Future presentCodeRedemptionSheet() { - throw UnsupportedError( - 'The method only works on iOS.'); - } } diff --git a/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart b/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart index f1d1d3e74b86..18f86a67d9c6 100644 --- a/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart +++ b/packages/in_app_purchase/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart @@ -143,8 +143,7 @@ class SKPaymentQueueWrapper { /// presentCodeRedemptionSheet]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/3566726-presentcoderedemptionsheet?language=objc) Future presentCodeRedemptionSheet() async { await channel.invokeMethod( - '-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]', - ); + '-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]'); } // Triage a method channel call from the platform and triggers the correct observer method. From 8f3682bbb559e7a3cb2273830445b0d0e470da3d Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 18 Nov 2020 16:30:19 +0100 Subject: [PATCH 03/14] Add Tests --- .../app_store_connection_test.dart | 6 ++++++ .../google_play_connection_test.dart | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart b/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart index b22737ca041b..6b3a7f60afc6 100644 --- a/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart +++ b/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart @@ -292,6 +292,12 @@ void main() { throwsUnsupportedError); }); }); + + group('present code redemption sheet', () { + test('null', () async { + expect(await AppStoreConnection.instance.presentCodeRedemptionSheet(), null); + }); + }); } class FakeIOSPlatform { diff --git a/packages/in_app_purchase/test/in_app_purchase_connection/google_play_connection_test.dart b/packages/in_app_purchase/test/in_app_purchase_connection/google_play_connection_test.dart index f06c4ff7efef..64bbf7ce32e1 100644 --- a/packages/in_app_purchase/test/in_app_purchase_connection/google_play_connection_test.dart +++ b/packages/in_app_purchase/test/in_app_purchase_connection/google_play_connection_test.dart @@ -234,6 +234,13 @@ void main() { }); }); + group('present code redemption sheet', () { + test('should throw on android', () { + expect(GooglePlayConnection.instance.presentCodeRedemptionSheet(), + throwsUnsupportedError); + }); + }); + group('make payment', () { final String launchMethodName = 'BillingClient#launchBillingFlow(Activity, BillingFlowParams)'; From 1d02f54ad51c9202f51b98cf8c877c0650e8f5c4 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 18 Nov 2020 16:53:59 +0100 Subject: [PATCH 04/14] Add XCTest --- .../ios/Tests/InAppPurchasePluginTest.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m b/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m index 4025e9270fa9..344032e43248 100644 --- a/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m +++ b/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m @@ -250,6 +250,21 @@ - (void)testRefreshReceiptRequest { XCTAssertTrue(result); } +- (void)testPresentCodeRedemptionSheet { + XCTestExpectation* expectation = [self expectationWithDescription:@"expect successfully present Code Redemption Sheet"]; + FlutterMethodCall* call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" + arguments:nil]; + __block BOOL callbackInvoked = NO; + [self.plugin handleMethodCall:call + result:^(id r) { + callbackInvoked = YES; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertTrue(callbackInvoked); +} + - (void)testGetPendingTransactions { XCTestExpectation* expectation = [self expectationWithDescription:@"expect success"]; FlutterMethodCall* call = From 9df88c6af4cb10013402c9fa0edbb414f0d644ca Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 18 Nov 2020 17:02:24 +0100 Subject: [PATCH 05/14] Update CHANGELOG and pubspec --- packages/in_app_purchase/CHANGELOG.md | 4 ++++ packages/in_app_purchase/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/in_app_purchase/CHANGELOG.md b/packages/in_app_purchase/CHANGELOG.md index 6207da9b403c..66841fffc68c 100644 --- a/packages/in_app_purchase/CHANGELOG.md +++ b/packages/in_app_purchase/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.5 + +* [iOS] Introduce `SKPaymentQueueWrapper.presentCodeRedemptionSheet` + ## 0.3.4+16 * Add Dartdocs to all public APIs. diff --git a/packages/in_app_purchase/pubspec.yaml b/packages/in_app_purchase/pubspec.yaml index eda865e487f7..1da6c2bfc330 100644 --- a/packages/in_app_purchase/pubspec.yaml +++ b/packages/in_app_purchase/pubspec.yaml @@ -1,7 +1,7 @@ name: in_app_purchase description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play. homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase -version: 0.3.4+16 +version: 0.3.5 dependencies: async: ^2.0.8 From 792d0912323a0965a70eeaafa620aafb3f563024 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Fri, 20 Nov 2020 10:07:50 +0100 Subject: [PATCH 06/14] Formatting --- .../in_app_purchase/ios/Classes/InAppPurchasePlugin.m | 3 ++- .../in_app_purchase/ios/Tests/InAppPurchasePluginTest.m | 9 +++++---- .../app_store_connection_test.dart | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m index f4b8726714d3..e1397e428ddc 100644 --- a/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m @@ -93,7 +93,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self finishTransaction:call result:result]; } else if ([@"-[InAppPurchasePlugin restoreTransactions:result:]" isEqualToString:call.method]) { [self restoreTransactions:call result:result]; - } else if ([@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" isEqualToString:call.method]) { + } else if ([@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" + isEqualToString:call.method]) { [self presentCodeRedemptionSheet:call result:result]; } else if ([@"-[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString:call.method]) { [self retrieveReceiptData:call result:result]; diff --git a/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m b/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m index 344032e43248..f826ccad72b4 100644 --- a/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m +++ b/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m @@ -251,10 +251,11 @@ - (void)testRefreshReceiptRequest { } - (void)testPresentCodeRedemptionSheet { - XCTestExpectation* expectation = [self expectationWithDescription:@"expect successfully present Code Redemption Sheet"]; - FlutterMethodCall* call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" - arguments:nil]; + XCTestExpectation* expectation = + [self expectationWithDescription:@"expect successfully present Code Redemption Sheet"]; + FlutterMethodCall* call = [FlutterMethodCall + methodCallWithMethodName:@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" + arguments:nil]; __block BOOL callbackInvoked = NO; [self.plugin handleMethodCall:call result:^(id r) { diff --git a/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart b/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart index 6b3a7f60afc6..b7c2f7130d53 100644 --- a/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart +++ b/packages/in_app_purchase/test/in_app_purchase_connection/app_store_connection_test.dart @@ -295,7 +295,8 @@ void main() { group('present code redemption sheet', () { test('null', () async { - expect(await AppStoreConnection.instance.presentCodeRedemptionSheet(), null); + expect( + await AppStoreConnection.instance.presentCodeRedemptionSheet(), null); }); }); } From 86a46d8412d27c6a1f8cea1a918a0d775b3e4085 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Fri, 20 Nov 2020 10:50:31 +0100 Subject: [PATCH 07/14] Update Xcode --- .cirrus.yml | 4 ++-- packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 98cd6276e0e6..6db478bb6801 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -130,7 +130,7 @@ task: only_if: $CIRRUS_TAG == '' use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true' osx_instance: - image: catalina-xcode-11.3.1-flutter + image: catalina-xcode-12.2 upgrade_script: - flutter channel stable - flutter upgrade @@ -186,7 +186,7 @@ task: only_if: $CIRRUS_TAG == '' use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true' osx_instance: - image: catalina-xcode-11.3.1-flutter + image: catalina-xcode-12.2 setup_script: - flutter config --enable-macos-desktop upgrade_script: diff --git a/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m b/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m index f826ccad72b4..31e0f255034d 100644 --- a/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m +++ b/packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m @@ -253,9 +253,9 @@ - (void)testRefreshReceiptRequest { - (void)testPresentCodeRedemptionSheet { XCTestExpectation* expectation = [self expectationWithDescription:@"expect successfully present Code Redemption Sheet"]; - FlutterMethodCall* call = [FlutterMethodCall + FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" - arguments:nil]; + arguments:nil]; __block BOOL callbackInvoked = NO; [self.plugin handleMethodCall:call result:^(id r) { From 193c351e5725e9b5d659cbc2f51c502f3e320fd1 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Mon, 1 Mar 2021 15:06:09 +0100 Subject: [PATCH 08/14] Remove empty line --- packages/in_app_purchase/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/in_app_purchase/pubspec.yaml b/packages/in_app_purchase/pubspec.yaml index cc431b2a34a7..3d121fd51e5e 100644 --- a/packages/in_app_purchase/pubspec.yaml +++ b/packages/in_app_purchase/pubspec.yaml @@ -1,7 +1,6 @@ name: in_app_purchase description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play. homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase - version: 0.5.0 dependencies: From b3280da1928f6d22aadd2bd56ebd4a46473b8e19 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Tue, 2 Mar 2021 18:24:57 +0100 Subject: [PATCH 09/14] Change Version to 0.4.2 --- packages/in_app_purchase/CHANGELOG.md | 2 +- packages/in_app_purchase/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/in_app_purchase/CHANGELOG.md b/packages/in_app_purchase/CHANGELOG.md index a8e00230c25b..4019f1d66ce8 100644 --- a/packages/in_app_purchase/CHANGELOG.md +++ b/packages/in_app_purchase/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.5.0 +## 0.4.2 * [iOS] Introduce `SKPaymentQueueWrapper.presentCodeRedemptionSheet` diff --git a/packages/in_app_purchase/pubspec.yaml b/packages/in_app_purchase/pubspec.yaml index 3d121fd51e5e..4fda5c308b7f 100644 --- a/packages/in_app_purchase/pubspec.yaml +++ b/packages/in_app_purchase/pubspec.yaml @@ -1,7 +1,7 @@ name: in_app_purchase description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play. homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase -version: 0.5.0 +version: 0.4.2 dependencies: flutter: From b76aeabbabf030b1dc9043c40dc1dae39e56089b Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Tue, 2 Mar 2021 19:09:08 +0100 Subject: [PATCH 10/14] Use respondToSelector to check for xcode version Also add Log message if functionality is unavaible --- packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m index 513f3a19ed4e..fb8c00225256 100644 --- a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m +++ b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m @@ -67,8 +67,10 @@ - (void)restoreTransactions:(nullable NSString *)applicationName { } - (void)presentCodeRedemptionSheet { - if (@available(iOS 14.0, *)) { + if (@available(iOS 14, *) && [self.queue respondsToSelector:@selector(presentCodeRedemptionSheet)]) { [self.queue presentCodeRedemptionSheet]; + } else { + NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 and Xcode 12 or newer"); } } From de6f09049845bb3ada1ee61cc0aac761a7f81287 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Tue, 2 Mar 2021 19:09:26 +0100 Subject: [PATCH 11/14] Add Unit Test in sk_methodchannel_apis_test.dart --- .../sk_methodchannel_apis_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart b/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart index d41a1269d6c9..77ba3355d0a0 100644 --- a/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart +++ b/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart @@ -133,6 +133,13 @@ void main() { expect(fakeIOSPlatform.applicationNameHasTransactionRestored, 'aUserID'); }); }); + + group('Code Redemption Sheet', () { + test('presentCodeRedemptionSheet should not throw', () async { + await SKPaymentQueueWrapper().presentCodeRedemptionSheet(); + expect(fakeIOSPlatform.presentCodeRedemption, true); + }); + }); } class FakeIOSPlatform { @@ -153,6 +160,9 @@ class FakeIOSPlatform { List> transactionsFinished = []; String applicationNameHasTransactionRestored = ''; + // present Code Redemption + bool presentCodeRedemption = false; + Future onMethodCall(MethodCall call) { switch (call.method) { // request makers @@ -193,6 +203,9 @@ class FakeIOSPlatform { case '-[InAppPurchasePlugin restoreTransactions:result:]': applicationNameHasTransactionRestored = call.arguments; return Future.sync(() {}); + case '-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]': + presentCodeRedemption = true; + return Future.sync(() {}); } return Future.sync(() {}); } From 8858147ec7b552bb6a0d7052299b1e25063b8aa7 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 3 Mar 2021 14:48:40 +0100 Subject: [PATCH 12/14] Clean up fakeIOSPlatform.presentCodeRedemption --- .../test/store_kit_wrappers/sk_methodchannel_apis_test.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart b/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart index 77ba3355d0a0..8df380bc223b 100644 --- a/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart +++ b/packages/in_app_purchase/test/store_kit_wrappers/sk_methodchannel_apis_test.dart @@ -136,8 +136,10 @@ void main() { group('Code Redemption Sheet', () { test('presentCodeRedemptionSheet should not throw', () async { + expect(fakeIOSPlatform.presentCodeRedemption, false); await SKPaymentQueueWrapper().presentCodeRedemptionSheet(); expect(fakeIOSPlatform.presentCodeRedemption, true); + fakeIOSPlatform.presentCodeRedemption = false; }); }); } From 4a761a01040580dd250691f7b72efd65681efb19 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 3 Mar 2021 14:59:34 +0100 Subject: [PATCH 13/14] Formatting --- .../in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m index fb8c00225256..772f1a9146da 100644 --- a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m +++ b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m @@ -67,10 +67,11 @@ - (void)restoreTransactions:(nullable NSString *)applicationName { } - (void)presentCodeRedemptionSheet { - if (@available(iOS 14, *) && [self.queue respondsToSelector:@selector(presentCodeRedemptionSheet)]) { + if (@available(iOS 14, *) && + [self.queue respondsToSelector:@selector(presentCodeRedemptionSheet)]) { [self.queue presentCodeRedemptionSheet]; } else { - NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 and Xcode 12 or newer"); + NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 and Xcode 12 or newer"); } } From 47f9016a7893c233e7c6e767e4aecb185f669661 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 4 Mar 2021 19:21:59 +0100 Subject: [PATCH 14/14] Remove respondsToSelector check --- .../in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m index 772f1a9146da..8d179aee7ba8 100644 --- a/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m +++ b/packages/in_app_purchase/ios/Classes/FIAPaymentQueueHandler.m @@ -67,11 +67,10 @@ - (void)restoreTransactions:(nullable NSString *)applicationName { } - (void)presentCodeRedemptionSheet { - if (@available(iOS 14, *) && - [self.queue respondsToSelector:@selector(presentCodeRedemptionSheet)]) { + if (@available(iOS 14, *)) { [self.queue presentCodeRedemptionSheet]; } else { - NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 and Xcode 12 or newer"); + NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 or newer"); } }