diff --git a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md index 1fa6e393bca..d30e38e9260 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.6+1 + +* Refactors internals for improved testability. + ## 0.4.6 * Adds a new case `.unverified` to enum `SK2ProductPurchaseResult` diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_apis.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_apis.dart new file mode 100644 index 00000000000..0895118a20f --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/in_app_purchase_apis.dart @@ -0,0 +1,39 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart' show visibleForTesting; + +import 'messages.g.dart'; +import 'sk2_pigeon.g.dart'; + +/// The instance of the host API used to communicate with the platform side for +/// the original StoreKit API. +/// +/// This is a global to allow tests to override the host API with a mock, since +/// in practice the host API is a singleton, and there is no way to inject it +/// in the usual way since many uses aren't in objects. +InAppPurchaseAPI hostApi = InAppPurchaseAPI(); + +/// The instance of the host API used to communicate with the platform side +/// for StoreKit2. +/// +/// This is a global to allow tests to override the host API with a mock, since +/// in practice the host API is a singleton, and there is no way to inject it +/// in the usual way since many uses aren't in objects. +InAppPurchase2API hostApi2 = InAppPurchase2API(); + +/// Set up pigeon API. +@visibleForTesting +void setInAppPurchaseHostApis({ + InAppPurchaseAPI? api, + InAppPurchase2API? api2, +}) { + if (api != null) { + hostApi = api; + } + + if (api2 != null) { + hostApi2 = api2; + } +} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_appstore_wrapper.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_appstore_wrapper.dart index 07a806d268c..8bfc8e47893 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_appstore_wrapper.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_appstore_wrapper.dart @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import '../../store_kit_2_wrappers.dart'; - -InAppPurchase2API _hostApi = InAppPurchase2API(); +import '../in_app_purchase_apis.dart'; /// Wrapper for StoreKit2's AppStore /// (https://developer.apple.com/documentation/storekit/appstore) @@ -13,7 +11,7 @@ final class AppStore { /// Returns a bool that indicates whether the person can make purchases. /// https://developer.apple.com/documentation/storekit/appstore/3822277-canmakepayments Future canMakePayments() { - return _hostApi.canMakePayments(); + return hostApi2.canMakePayments(); } /// Dart wrapper for StoreKit2's sync() @@ -21,6 +19,6 @@ final class AppStore { /// Will initiate an authentication pop up. /// https://developer.apple.com/documentation/storekit/appstore/sync() Future sync() { - return _hostApi.sync(); + return hostApi2.sync(); } } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_product_wrapper.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_product_wrapper.dart index 4a0ba1de4e9..8baffa75743 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_product_wrapper.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_product_wrapper.dart @@ -5,8 +5,7 @@ import 'package:flutter/services.dart'; import '../../store_kit_2_wrappers.dart'; - -InAppPurchase2API _hostApi = InAppPurchase2API(); +import '../in_app_purchase_apis.dart'; /// A wrapper around StoreKit2's ProductType /// https://developer.apple.com/documentation/storekit/product/producttype @@ -381,7 +380,7 @@ class SK2Product { /// If any of the identifiers are invalid or can't be found, they are excluded /// from the returned list. static Future> products(List identifiers) async { - final List productsMsg = await _hostApi.products( + final List productsMsg = await hostApi2.products( identifiers, ); if (productsMsg.isEmpty && identifiers.isNotEmpty) { @@ -406,9 +405,9 @@ class SK2Product { }) async { SK2ProductPurchaseResultMessage result; if (options != null) { - result = await _hostApi.purchase(id, options: options.convertToPigeon()); + result = await hostApi2.purchase(id, options: options.convertToPigeon()); } else { - result = await _hostApi.purchase(id); + result = await hostApi2.purchase(id); } return result.convertFromPigeon(); } @@ -416,7 +415,7 @@ class SK2Product { /// Checks if the user is eligible for an introductory offer. /// The product must be an auto-renewable subscription. static Future isIntroductoryOfferEligible(String productId) async { - final bool result = await _hostApi.isIntroductoryOfferEligible(productId); + final bool result = await hostApi2.isIntroductoryOfferEligible(productId); return result; } @@ -426,7 +425,7 @@ class SK2Product { String productId, String offerId, ) async { - final bool result = await _hostApi.isWinBackOfferEligible( + final bool result = await hostApi2.isWinBackOfferEligible( productId, offerId, ); diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_storefront_wrapper.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_storefront_wrapper.dart index aed8f12d90b..7d2215d1e65 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_storefront_wrapper.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_storefront_wrapper.dart @@ -2,9 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import '../../store_kit_2_wrappers.dart'; - -InAppPurchase2API _hostApi = InAppPurchase2API(); +import '../in_app_purchase_apis.dart'; /// Wrapper for StoreKit2's Storefront /// (https://developer.apple.com/documentation/storekit/storefront) @@ -13,6 +11,6 @@ final class Storefront { /// Returns the 3 letter code for a store's locale /// (https://developer.apple.com/documentation/storekit/storefront/countrycode) Future countryCode() async { - return _hostApi.countryCode(); + return hostApi2.countryCode(); } } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_transaction_wrapper.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_transaction_wrapper.dart index f8359c85400..bc09ff5c96f 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_transaction_wrapper.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_2_wrappers/sk2_transaction_wrapper.dart @@ -8,10 +8,9 @@ import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_inte import '../../in_app_purchase_storekit.dart'; import '../../store_kit_wrappers.dart'; +import '../in_app_purchase_apis.dart'; import '../sk2_pigeon.g.dart'; -InAppPurchase2API _hostApi = InAppPurchase2API(); - /// Dart wrapper around StoreKit2's [Transaction](https://developer.apple.com/documentation/storekit/transaction) /// Note that in StoreKit2, a Transaction encompasses the data contained by /// SKPayment and SKTransaction in StoreKit1 @@ -72,14 +71,14 @@ class SK2Transaction { /// Indicates to the App Store that the app delivered the purchased content /// or enabled the service to finish the transaction. static Future finish(int id) async { - await _hostApi.finish(id); + await hostApi2.finish(id); } /// A wrapper around [Transaction.all] /// https://developer.apple.com/documentation/storekit/transaction/3851203-all /// A sequence that emits all the customer’s transactions for your app. static Future> transactions() async { - final List msgs = await _hostApi.transactions(); + final List msgs = await hostApi2.transactions(); final List transactions = msgs .map((SK2TransactionMessage e) => e.convertFromPigeon()) .toList(); @@ -89,17 +88,17 @@ class SK2Transaction { /// Start listening to transactions. /// Call this as soon as you can your app to avoid missing transactions. static void startListeningToTransactions() { - _hostApi.startListeningToTransactions(); + hostApi2.startListeningToTransactions(); } /// Stop listening to transactions. static void stopListeningToTransactions() { - _hostApi.stopListeningToTransactions(); + hostApi2.stopListeningToTransactions(); } /// Restore previously completed purchases. static Future restorePurchases() async { - await _hostApi.restorePurchases(); + await hostApi2.restorePurchases(); } } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart index b413523eb00..4a8a5728d39 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_wrapper.dart @@ -11,19 +11,12 @@ import 'package:json_annotation/json_annotation.dart'; import '../../store_kit_wrappers.dart'; import '../channel.dart'; +import '../in_app_purchase_apis.dart'; import '../in_app_purchase_storekit_platform.dart'; import '../messages.g.dart'; part 'sk_payment_queue_wrapper.g.dart'; -InAppPurchaseAPI _hostApi = InAppPurchaseAPI(); - -/// Set up pigeon API. -@visibleForTesting -void setInAppPurchaseHostApi(InAppPurchaseAPI api) { - _hostApi = api; -} - /// A wrapper around /// [`SKPaymentQueue`](https://developer.apple.com/documentation/storekit/skpaymentqueue?language=objc). /// @@ -54,12 +47,12 @@ class SKPaymentQueueWrapper { /// /// Returns `null` if the user's device is below iOS 13.0 or macOS 10.15. Future storefront() async { - return SKStorefrontWrapper.convertFromPigeon(await _hostApi.storefront()); + return SKStorefrontWrapper.convertFromPigeon(await hostApi.storefront()); } /// Calls [`-[SKPaymentQueue transactions]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506026-transactions?language=objc). Future> transactions() async { - final List pigeonMsgs = await _hostApi + final List pigeonMsgs = await hostApi .transactions(); return pigeonMsgs .map( @@ -70,7 +63,7 @@ class SKPaymentQueueWrapper { } /// Calls [`-[SKPaymentQueue canMakePayments:]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506139-canmakepayments?language=objc). - static Future canMakePayments() async => _hostApi.canMakePayments(); + static Future canMakePayments() async => hostApi.canMakePayments(); /// Sets an observer to listen to all incoming transaction events. /// @@ -89,7 +82,7 @@ class SKPaymentQueueWrapper { /// Call this method when the first listener is subscribed to the /// [InAppPurchaseStoreKitPlatform.purchaseStream]. Future startObservingTransactionQueue() => - _hostApi.startObservingPaymentQueue(); + hostApi.startObservingPaymentQueue(); /// Instructs the iOS implementation to remove the transaction observer and /// stop listening to it. @@ -97,7 +90,7 @@ class SKPaymentQueueWrapper { /// Call this when there are no longer any listeners subscribed to the /// [InAppPurchaseStoreKitPlatform.purchaseStream]. Future stopObservingTransactionQueue() => - _hostApi.stopObservingPaymentQueue(); + hostApi.stopObservingPaymentQueue(); /// Sets an implementation of the [SKPaymentQueueDelegateWrapper]. /// @@ -111,10 +104,10 @@ class SKPaymentQueueWrapper { /// default behaviour will apply (see [documentation](https://developer.apple.com/documentation/storekit/skpaymentqueue/3182429-delegate?language=objc)). Future setDelegate(SKPaymentQueueDelegateWrapper? delegate) async { if (delegate == null) { - await _hostApi.removePaymentQueueDelegate(); + await hostApi.removePaymentQueueDelegate(); paymentQueueDelegateChannel.setMethodCallHandler(null); } else { - await _hostApi.registerPaymentQueueDelegate(); + await hostApi.registerPaymentQueueDelegate(); paymentQueueDelegateChannel.setMethodCallHandler( handlePaymentQueueDelegateCallbacks, ); @@ -149,7 +142,7 @@ class SKPaymentQueueWrapper { '[in_app_purchase]: Trying to add a payment without an observer. One must be set using `SkPaymentQueueWrapper.setTransactionObserver` before the app launches.', ); - await _hostApi.addPayment(payment.toMap()); + await hostApi.addPayment(payment.toMap()); } /// Finishes a transaction and removes it from the queue. @@ -167,7 +160,7 @@ class SKPaymentQueueWrapper { SKPaymentTransactionWrapper transaction, ) async { final Map requestMap = transaction.toFinishMap(); - await _hostApi.finishTransaction(requestMap); + await hostApi.finishTransaction(requestMap); } /// Restore previously purchased transactions. @@ -191,7 +184,7 @@ class SKPaymentQueueWrapper { /// or [`-[SKPayment restoreCompletedTransactionsWithApplicationUsername:]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1505992-restorecompletedtransactionswith?language=objc) /// depending on whether the `applicationUserName` is set. Future restoreTransactions({String? applicationUserName}) async { - await _hostApi.restoreTransactions(applicationUserName); + await hostApi.restoreTransactions(applicationUserName); } /// Present Code Redemption Sheet @@ -201,7 +194,7 @@ class SKPaymentQueueWrapper { /// This method triggers [`-[SKPayment /// presentCodeRedemptionSheet]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/3566726-presentcoderedemptionsheet?language=objc) Future presentCodeRedemptionSheet() async { - await _hostApi.presentCodeRedemptionSheet(); + await hostApi.presentCodeRedemptionSheet(); } /// Shows the price consent sheet if the user has not yet responded to a @@ -213,7 +206,7 @@ class SKPaymentQueueWrapper { /// /// See documentation of StoreKit's [`-[SKPaymentQueue showPriceConsentIfNeeded]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/3521327-showpriceconsentifneeded?language=objc). Future showPriceConsentIfNeeded() async { - await _hostApi.showPriceConsentIfNeeded(); + await hostApi.showPriceConsentIfNeeded(); } /// Triage a method channel call from the platform and triggers the correct observer method. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_receipt_manager.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_receipt_manager.dart index 58f00ac4610..e0e6784bc54 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_receipt_manager.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_receipt_manager.dart @@ -4,9 +4,7 @@ import 'dart:async'; -import '../messages.g.dart'; - -InAppPurchaseAPI _hostApi = InAppPurchaseAPI(); +import '../in_app_purchase_apis.dart'; // ignore: avoid_classes_with_only_static_members /// This class contains static methods to manage StoreKit receipts. @@ -19,6 +17,6 @@ class SKReceiptManager { /// For more details on how to validate the receipt data, you can refer to Apple's document about [`About Receipt Validation`](https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Introduction.html#//apple_ref/doc/uid/TP40010573-CH105-SW1). /// If the receipt is invalid or missing, you can use [SKRequestMaker.startRefreshReceiptRequest] to request a new receipt. static Future retrieveReceiptData() async { - return (await _hostApi.retrieveReceiptData()) ?? ''; + return (await hostApi.retrieveReceiptData()) ?? ''; } } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_request_maker.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_request_maker.dart index d65d0f45862..be73348dbe9 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_request_maker.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_request_maker.dart @@ -6,11 +6,10 @@ import 'dart:async'; import 'package:flutter/services.dart'; +import '../in_app_purchase_apis.dart'; import '../messages.g.dart'; import 'sk_product_wrapper.dart'; -InAppPurchaseAPI _hostApi = InAppPurchaseAPI(); - /// A request maker that handles all the requests made by SKRequest subclasses. /// /// There are multiple [SKRequest](https://developer.apple.com/documentation/storekit/skrequest?language=objc) subclasses handling different requests in the `StoreKit` with multiple delegate methods, @@ -29,7 +28,7 @@ class SKRequestMaker { Future startProductRequest( List productIdentifiers, ) async { - final SKProductsResponseMessage productResponsePigeon = await _hostApi + final SKProductsResponseMessage productResponsePigeon = await hostApi .startProductRequest(productIdentifiers); // should products be null or [] ? @@ -55,11 +54,11 @@ class SKRequestMaker { Future startRefreshReceiptRequest({ Map? receiptProperties, }) { - return _hostApi.refreshReceipt(receiptProperties: receiptProperties); + return hostApi.refreshReceipt(receiptProperties: receiptProperties); } /// Check if current device supports StoreKit 2. static Future supportsStoreKit2() async { - return _hostApi.supportsStoreKit2(); + return hostApi.supportsStoreKit2(); } } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/pigeons/messages.dart b/packages/in_app_purchase/in_app_purchase_storekit/pigeons/messages.dart index cee8def2a9f..95b215cb5b6 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pigeons/messages.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/pigeons/messages.dart @@ -7,7 +7,6 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon( PigeonOptions( dartOut: 'lib/src/messages.g.dart', - dartTestOut: 'test/test_api.g.dart', objcHeaderOut: 'darwin/in_app_purchase_storekit/Sources/in_app_purchase_storekit_objc/include/in_app_purchase_storekit_objc/messages.g.h', objcSourceOut: @@ -238,7 +237,7 @@ class SKProductSubscriptionPeriodMessage { enum SKSubscriptionPeriodUnitMessage { day, week, month, year } -@HostApi(dartHostTestHandler: 'TestInAppPurchaseApi') +@HostApi() abstract class InAppPurchaseAPI { /// Returns if the current device is able to make payments bool canMakePayments(); diff --git a/packages/in_app_purchase/in_app_purchase_storekit/pigeons/sk2_pigeon.dart b/packages/in_app_purchase/in_app_purchase_storekit/pigeons/sk2_pigeon.dart index da8806d1b25..4feea15180e 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pigeons/sk2_pigeon.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/pigeons/sk2_pigeon.dart @@ -7,7 +7,6 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon( PigeonOptions( dartOut: 'lib/src/sk2_pigeon.g.dart', - dartTestOut: 'test/sk2_test_api.g.dart', swiftOut: 'darwin/in_app_purchase_storekit/Sources/in_app_purchase_storekit/StoreKit2/sk2_pigeon.g.swift', copyrightHeader: 'pigeons/copyright.txt', @@ -216,7 +215,7 @@ enum SK2ProductPurchaseResultMessage { pending, } -@HostApi(dartHostTestHandler: 'TestInAppPurchase2Api') +@HostApi() abstract class InAppPurchase2API { // https://developer.apple.com/documentation/storekit/appstore/3822277-canmakepayments bool canMakePayments(); diff --git a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml index 345ac034774..195e1614ddc 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml @@ -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.6 +version: 0.4.6+1 environment: sdk: ^3.9.0 diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart index 0c7ca53fcb4..4b155205af5 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/fakes/fake_storekit_platform.dart @@ -11,11 +11,9 @@ import 'package:in_app_purchase_storekit/src/store_kit_2_wrappers/sk2_product_wr import 'package:in_app_purchase_storekit/src/store_kit_2_wrappers/sk2_transaction_wrapper.dart'; import 'package:in_app_purchase_storekit/store_kit_wrappers.dart'; -import '../sk2_test_api.g.dart'; import '../store_kit_wrappers/sk_test_stub_objects.dart'; -import '../test_api.g.dart'; -class FakeStoreKitPlatform implements TestInAppPurchaseApi { +class FakeStoreKitPlatform implements InAppPurchaseAPI { // pre-configured store information String? receiptData; late Set validProductIDs; @@ -155,12 +153,12 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - bool canMakePayments() { + Future canMakePayments() async { return true; } @override - void addPayment(Map paymentMap) { + Future addPayment(Map paymentMap) async { final String id = paymentMap['productIdentifier']! as String; final int quantity = paymentMap['quantity']! as int; @@ -221,7 +219,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - SKStorefrontMessage storefront() { + Future storefront() async { return SKStorefrontMessage( countryCode: _countryCode, identifier: _countryIdentifier, @@ -229,12 +227,12 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - List transactions() { + Future> transactions() async { throw UnimplementedError(); } @override - void finishTransaction(Map finishMap) { + Future finishTransaction(Map finishMap) async { finishedTransactions.add( createPurchasedTransaction( finishMap['productIdentifier']! as String, @@ -245,10 +243,10 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - void presentCodeRedemptionSheet() {} + Future presentCodeRedemptionSheet() async {} @override - void restoreTransactions(String? applicationUserName) { + Future restoreTransactions(String? applicationUserName) async { if (restoreException != null) { throw restoreException!; } @@ -301,17 +299,17 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - void registerPaymentQueueDelegate() { + Future registerPaymentQueueDelegate() async { isPaymentQueueDelegateRegistered = true; } @override - void removePaymentQueueDelegate() { + Future removePaymentQueueDelegate() async { isPaymentQueueDelegateRegistered = false; } @override - String retrieveReceiptData() { + Future retrieveReceiptData() async { if (receiptData != null) { return receiptData!; } else { @@ -320,25 +318,33 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - void showPriceConsentIfNeeded() {} + Future showPriceConsentIfNeeded() async {} @override - void startObservingPaymentQueue() { + Future startObservingPaymentQueue() async { queueIsActive = true; } @override - void stopObservingPaymentQueue() { + Future stopObservingPaymentQueue() async { queueIsActive = false; } @override - bool supportsStoreKit2() { + Future supportsStoreKit2() async { return shouldStoreKit2BeEnabled; } + + @override + // ignore: non_constant_identifier_names + BinaryMessenger? get pigeonVar_binaryMessenger => null; + + @override + // ignore: non_constant_identifier_names + String get pigeonVar_messageChannelSuffix => ''; } -class FakeStoreKit2Platform implements TestInAppPurchase2Api { +class FakeStoreKit2Platform implements InAppPurchase2API { late Set validProductIDs; late Map validProducts; late List transactionList = []; @@ -387,12 +393,12 @@ class FakeStoreKit2Platform implements TestInAppPurchase2Api { } @override - bool canMakePayments() { + Future canMakePayments() async { return true; } @override - Future> products(List identifiers) { + Future> products(List identifiers) async { if (queryProductException != null) { throw queryProductException!; } @@ -445,12 +451,12 @@ class FakeStoreKit2Platform implements TestInAppPurchase2Api { } @override - void startListeningToTransactions() { + Future startListeningToTransactions() async { isListenerRegistered = true; } @override - void stopListeningToTransactions() { + Future stopListeningToTransactions() async { isListenerRegistered = false; } @@ -467,9 +473,7 @@ class FakeStoreKit2Platform implements TestInAppPurchase2Api { } @override - Future sync() { - return Future.value(); - } + Future sync() async {} @override Future isWinBackOfferEligible(String productId, String offerId) async { @@ -512,6 +516,14 @@ class FakeStoreKit2Platform implements TestInAppPurchase2Api { return eligibleIntroductoryOffers[productId] ?? false; } + + @override + // ignore: non_constant_identifier_names + BinaryMessenger? get pigeonVar_binaryMessenger => null; + + @override + // ignore: non_constant_identifier_names + String get pigeonVar_messageChannelSuffix => ''; } SK2TransactionMessage createPendingTransaction(String id, {int quantity = 1}) { diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_2_platform_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_2_platform_test.dart index 7477775f360..8ce69c30066 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_2_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_2_platform_test.dart @@ -8,11 +8,10 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart'; import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart'; +import 'package:in_app_purchase_storekit/src/in_app_purchase_apis.dart'; import 'package:in_app_purchase_storekit/store_kit_2_wrappers.dart'; import 'fakes/fake_storekit_platform.dart'; -import 'sk2_test_api.g.dart'; -import 'test_api.g.dart'; void main() { final SK2Product dummyProductWrapper = SK2Product( @@ -33,8 +32,10 @@ void main() { late InAppPurchaseStoreKitPlatform iapStoreKitPlatform; setUpAll(() { - TestInAppPurchase2Api.setUp(fakeStoreKit2Platform); - TestInAppPurchaseApi.setUp(fakeStoreKitPlatform); + setInAppPurchaseHostApis( + api: fakeStoreKitPlatform, + api2: fakeStoreKit2Platform, + ); }); setUp(() { @@ -399,7 +400,7 @@ void main() { setUp(() async { fakeStoreKit2Platform = FakeStoreKit2Platform(); fakeStoreKit2Platform.reset(); - TestInAppPurchase2Api.setUp(fakeStoreKit2Platform); + setInAppPurchaseHostApis(api2: fakeStoreKit2Platform); await InAppPurchaseStoreKitPlatform.enableStoreKit2(); }); @@ -537,7 +538,7 @@ void main() { setUp(() async { fakeStoreKit2Platform = FakeStoreKit2Platform(); fakeStoreKit2Platform.reset(); - TestInAppPurchase2Api.setUp(fakeStoreKit2Platform); + setInAppPurchaseHostApis(api2: fakeStoreKit2Platform); await InAppPurchaseStoreKitPlatform.enableStoreKit2(); }); diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_addtion_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_addtion_test.dart index afbf18cf587..5e2ad208896 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_addtion_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_addtion_test.dart @@ -5,9 +5,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart'; import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart'; +import 'package:in_app_purchase_storekit/src/in_app_purchase_apis.dart'; import 'fakes/fake_storekit_platform.dart'; -import 'test_api.g.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -15,7 +15,7 @@ void main() { final FakeStoreKitPlatform fakeStoreKitPlatform = FakeStoreKitPlatform(); setUpAll(() { - TestInAppPurchaseApi.setUp(fakeStoreKitPlatform); + setInAppPurchaseHostApis(api: fakeStoreKitPlatform); }); group('present code redemption sheet', () { diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart index 859b6779614..cf793c6c482 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/in_app_purchase_storekit_platform_test.dart @@ -8,12 +8,12 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart'; import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart'; +import 'package:in_app_purchase_storekit/src/in_app_purchase_apis.dart'; import 'package:in_app_purchase_storekit/src/store_kit_wrappers/enum_converters.dart'; import 'package:in_app_purchase_storekit/store_kit_wrappers.dart'; import 'fakes/fake_storekit_platform.dart'; import 'store_kit_wrappers/sk_test_stub_objects.dart'; -import 'test_api.g.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -22,7 +22,7 @@ void main() { late InAppPurchaseStoreKitPlatform iapStoreKitPlatform; setUpAll(() { - TestInAppPurchaseApi.setUp(fakeStoreKitPlatform); + setInAppPurchaseHostApis(api: fakeStoreKitPlatform); }); setUp(() { diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/sk2_test_api.g.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/sk2_test_api.g.dart deleted file mode 100644 index bde01de4964..00000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/sk2_test_api.g.dart +++ /dev/null @@ -1,601 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v25.5.0), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers -// ignore_for_file: avoid_relative_lib_imports -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:in_app_purchase_storekit/src/sk2_pigeon.g.dart'; - -class _PigeonCodec extends StandardMessageCodec { - const _PigeonCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is int) { - buffer.putUint8(4); - buffer.putInt64(value); - } else if (value is SK2ProductTypeMessage) { - buffer.putUint8(129); - writeValue(buffer, value.index); - } else if (value is SK2SubscriptionOfferTypeMessage) { - buffer.putUint8(130); - writeValue(buffer, value.index); - } else if (value is SK2SubscriptionOfferPaymentModeMessage) { - buffer.putUint8(131); - writeValue(buffer, value.index); - } else if (value is SK2SubscriptionPeriodUnitMessage) { - buffer.putUint8(132); - writeValue(buffer, value.index); - } else if (value is SK2ProductPurchaseResultMessage) { - buffer.putUint8(133); - writeValue(buffer, value.index); - } else if (value is SK2SubscriptionOfferMessage) { - buffer.putUint8(134); - writeValue(buffer, value.encode()); - } else if (value is SK2SubscriptionPeriodMessage) { - buffer.putUint8(135); - writeValue(buffer, value.encode()); - } else if (value is SK2SubscriptionInfoMessage) { - buffer.putUint8(136); - writeValue(buffer, value.encode()); - } else if (value is SK2ProductMessage) { - buffer.putUint8(137); - writeValue(buffer, value.encode()); - } else if (value is SK2PriceLocaleMessage) { - buffer.putUint8(138); - writeValue(buffer, value.encode()); - } else if (value is SK2SubscriptionOfferSignatureMessage) { - buffer.putUint8(139); - writeValue(buffer, value.encode()); - } else if (value is SK2SubscriptionOfferPurchaseMessage) { - buffer.putUint8(140); - writeValue(buffer, value.encode()); - } else if (value is SK2ProductPurchaseOptionsMessage) { - buffer.putUint8(141); - writeValue(buffer, value.encode()); - } else if (value is SK2TransactionMessage) { - buffer.putUint8(142); - writeValue(buffer, value.encode()); - } else if (value is SK2ErrorMessage) { - buffer.putUint8(143); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 129: - final int? value = readValue(buffer) as int?; - return value == null ? null : SK2ProductTypeMessage.values[value]; - case 130: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SK2SubscriptionOfferTypeMessage.values[value]; - case 131: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SK2SubscriptionOfferPaymentModeMessage.values[value]; - case 132: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SK2SubscriptionPeriodUnitMessage.values[value]; - case 133: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SK2ProductPurchaseResultMessage.values[value]; - case 134: - return SK2SubscriptionOfferMessage.decode(readValue(buffer)!); - case 135: - return SK2SubscriptionPeriodMessage.decode(readValue(buffer)!); - case 136: - return SK2SubscriptionInfoMessage.decode(readValue(buffer)!); - case 137: - return SK2ProductMessage.decode(readValue(buffer)!); - case 138: - return SK2PriceLocaleMessage.decode(readValue(buffer)!); - case 139: - return SK2SubscriptionOfferSignatureMessage.decode(readValue(buffer)!); - case 140: - return SK2SubscriptionOfferPurchaseMessage.decode(readValue(buffer)!); - case 141: - return SK2ProductPurchaseOptionsMessage.decode(readValue(buffer)!); - case 142: - return SK2TransactionMessage.decode(readValue(buffer)!); - case 143: - return SK2ErrorMessage.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class TestInAppPurchase2Api { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - - bool canMakePayments(); - - Future> products(List identifiers); - - Future purchase( - String id, { - SK2ProductPurchaseOptionsMessage? options, - }); - - Future isWinBackOfferEligible(String productId, String offerId); - - Future isIntroductoryOfferEligible(String productId); - - Future> transactions(); - - Future finish(int id); - - void startListeningToTransactions(); - - void stopListeningToTransactions(); - - Future restorePurchases(); - - Future countryCode(); - - Future sync(); - - static void setUp( - TestInAppPurchase2Api? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty - ? '.$messageChannelSuffix' - : ''; - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.canMakePayments$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final bool output = api.canMakePayments(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.products$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.products was null.', - ); - final List args = (message as List?)!; - final List? arg_identifiers = (args[0] as List?) - ?.cast(); - assert( - arg_identifiers != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.products was null, expected non-null List.', - ); - try { - final List output = await api.products( - arg_identifiers!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.purchase$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.purchase was null.', - ); - final List args = (message as List?)!; - final String? arg_id = (args[0] as String?); - assert( - arg_id != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.purchase was null, expected non-null String.', - ); - final SK2ProductPurchaseOptionsMessage? arg_options = - (args[1] as SK2ProductPurchaseOptionsMessage?); - try { - final SK2ProductPurchaseResultMessage output = await api - .purchase(arg_id!, options: arg_options); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isWinBackOfferEligible$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler< - Object? - >(pigeonVar_channel, (Object? message) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isWinBackOfferEligible was null.', - ); - final List args = (message as List?)!; - final String? arg_productId = (args[0] as String?); - assert( - arg_productId != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isWinBackOfferEligible was null, expected non-null String.', - ); - final String? arg_offerId = (args[1] as String?); - assert( - arg_offerId != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isWinBackOfferEligible was null, expected non-null String.', - ); - try { - final bool output = await api.isWinBackOfferEligible( - arg_productId!, - arg_offerId!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString()), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isIntroductoryOfferEligible$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isIntroductoryOfferEligible was null.', - ); - final List args = (message as List?)!; - final String? arg_productId = (args[0] as String?); - assert( - arg_productId != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.isIntroductoryOfferEligible was null, expected non-null String.', - ); - try { - final bool output = await api.isIntroductoryOfferEligible( - arg_productId!, - ); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.transactions$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final List output = await api - .transactions(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.finish$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.finish was null.', - ); - final List args = (message as List?)!; - final int? arg_id = (args[0] as int?); - assert( - arg_id != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.finish was null, expected non-null int.', - ); - try { - await api.finish(arg_id!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.startListeningToTransactions$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.startListeningToTransactions(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.stopListeningToTransactions$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.stopListeningToTransactions(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.restorePurchases$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - await api.restorePurchases(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.countryCode$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final String output = await api.countryCode(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.sync$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - await api.sync(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - } -} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_methodchannel_apis_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_methodchannel_apis_test.dart index e9bb9d41e95..497c567bbf6 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_methodchannel_apis_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_methodchannel_apis_test.dart @@ -4,9 +4,9 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:in_app_purchase_storekit/src/in_app_purchase_apis.dart'; import 'package:in_app_purchase_storekit/src/messages.g.dart'; import 'package:in_app_purchase_storekit/store_kit_wrappers.dart'; -import '../test_api.g.dart'; import 'sk_test_stub_objects.dart'; void main() { @@ -15,7 +15,7 @@ void main() { final FakeStoreKitPlatform fakeStoreKitPlatform = FakeStoreKitPlatform(); setUpAll(() { - TestInAppPurchaseApi.setUp(fakeStoreKitPlatform); + setInAppPurchaseHostApis(api: fakeStoreKitPlatform); }); setUp(() {}); @@ -77,7 +77,7 @@ void main() { fakeStoreKitPlatform.getReceiptFailTest = true; expect( () async => SKReceiptManager.retrieveReceiptData(), - throwsA(const TypeMatcher()), + throwsA(const TypeMatcher()), ); }); }); @@ -192,7 +192,7 @@ void main() { }); } -class FakeStoreKitPlatform implements TestInAppPurchaseApi { +class FakeStoreKitPlatform implements InAppPurchaseAPI { // get product request List startProductRequestParam = []; bool getProductRequestFailTest = false; @@ -223,19 +223,19 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { bool? queueIsActive; @override - void addPayment(Map paymentMap) { + Future addPayment(Map paymentMap) async { payments.add( SKPaymentWrapper.fromJson(Map.from(paymentMap)), ); } @override - bool canMakePayments() { + Future canMakePayments() async { return true; } @override - SKStorefrontMessage storefront() { + Future storefront() async { return SKStorefrontMessage( countryCode: 'USA', identifier: 'unique_identifier', @@ -243,59 +243,59 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - List transactions() => + Future> transactions() async => [dummyTransactionMessage]; @override - void finishTransaction(Map finishMap) { + Future finishTransaction(Map finishMap) async { transactionsFinished.add(Map.from(finishMap)); } @override - void presentCodeRedemptionSheet() { + Future presentCodeRedemptionSheet() async { presentCodeRedemption = true; } @override - void restoreTransactions(String? applicationUserName) { + Future restoreTransactions(String? applicationUserName) async { applicationNameHasTransactionRestored = applicationUserName!; } @override Future startProductRequest( List productIdentifiers, - ) { + ) async { startProductRequestParam = productIdentifiers; if (getProductRequestFailTest) { return Future.value( SKProductsResponseMessage(), ); } - return Future.value(dummyProductResponseMessage); + return dummyProductResponseMessage; } @override - void registerPaymentQueueDelegate() { + Future registerPaymentQueueDelegate() async { isPaymentQueueDelegateRegistered = true; } @override - void removePaymentQueueDelegate() { + Future removePaymentQueueDelegate() async { isPaymentQueueDelegateRegistered = false; } @override - void startObservingPaymentQueue() { + Future startObservingPaymentQueue() async { queueIsActive = true; } @override - void stopObservingPaymentQueue() { + Future stopObservingPaymentQueue() async { queueIsActive = false; } @override - String retrieveReceiptData() { + Future retrieveReceiptData() async { if (getReceiptFailTest) { throw Exception('some arbitrary error'); } @@ -312,14 +312,22 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - void showPriceConsentIfNeeded() { + Future showPriceConsentIfNeeded() async { showPriceConsent = true; } @override - bool supportsStoreKit2() { + Future supportsStoreKit2() async { return true; } + + @override + // ignore: non_constant_identifier_names + BinaryMessenger? get pigeonVar_binaryMessenger => null; + + @override + // ignore: non_constant_identifier_names + String get pigeonVar_messageChannelSuffix => ''; } class TestPaymentQueueDelegate extends SKPaymentQueueDelegateWrapper {} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_payment_queue_delegate_api_test.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_payment_queue_delegate_api_test.dart index bc136d03d07..08eca698b1a 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_payment_queue_delegate_api_test.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/test/store_kit_wrappers/sk_payment_queue_delegate_api_test.dart @@ -4,10 +4,10 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:in_app_purchase_storekit/src/in_app_purchase_apis.dart'; import 'package:in_app_purchase_storekit/store_kit_wrappers.dart'; import '../fakes/fake_storekit_platform.dart'; -import '../test_api.g.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -15,7 +15,7 @@ void main() { final FakeStoreKitPlatform fakeStoreKitPlatform = FakeStoreKitPlatform(); setUpAll(() { - TestInAppPurchaseApi.setUp(fakeStoreKitPlatform); + setInAppPurchaseHostApis(api: fakeStoreKitPlatform); }); test( diff --git a/packages/in_app_purchase/in_app_purchase_storekit/test/test_api.g.dart b/packages/in_app_purchase/in_app_purchase_storekit/test/test_api.g.dart deleted file mode 100644 index c970a8bde29..00000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/test/test_api.g.dart +++ /dev/null @@ -1,714 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v22.7.3), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers -// ignore_for_file: avoid_relative_lib_imports -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:in_app_purchase_storekit/src/messages.g.dart'; - -class _PigeonCodec extends StandardMessageCodec { - const _PigeonCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is int) { - buffer.putUint8(4); - buffer.putInt64(value); - } else if (value is SKPaymentTransactionStateMessage) { - buffer.putUint8(129); - writeValue(buffer, value.index); - } else if (value is SKProductDiscountTypeMessage) { - buffer.putUint8(130); - writeValue(buffer, value.index); - } else if (value is SKProductDiscountPaymentModeMessage) { - buffer.putUint8(131); - writeValue(buffer, value.index); - } else if (value is SKSubscriptionPeriodUnitMessage) { - buffer.putUint8(132); - writeValue(buffer, value.index); - } else if (value is SKPaymentTransactionMessage) { - buffer.putUint8(133); - writeValue(buffer, value.encode()); - } else if (value is SKPaymentMessage) { - buffer.putUint8(134); - writeValue(buffer, value.encode()); - } else if (value is SKErrorMessage) { - buffer.putUint8(135); - writeValue(buffer, value.encode()); - } else if (value is SKPaymentDiscountMessage) { - buffer.putUint8(136); - writeValue(buffer, value.encode()); - } else if (value is SKStorefrontMessage) { - buffer.putUint8(137); - writeValue(buffer, value.encode()); - } else if (value is SKProductsResponseMessage) { - buffer.putUint8(138); - writeValue(buffer, value.encode()); - } else if (value is SKProductMessage) { - buffer.putUint8(139); - writeValue(buffer, value.encode()); - } else if (value is SKPriceLocaleMessage) { - buffer.putUint8(140); - writeValue(buffer, value.encode()); - } else if (value is SKProductDiscountMessage) { - buffer.putUint8(141); - writeValue(buffer, value.encode()); - } else if (value is SKProductSubscriptionPeriodMessage) { - buffer.putUint8(142); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 129: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SKPaymentTransactionStateMessage.values[value]; - case 130: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SKProductDiscountTypeMessage.values[value]; - case 131: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SKProductDiscountPaymentModeMessage.values[value]; - case 132: - final int? value = readValue(buffer) as int?; - return value == null - ? null - : SKSubscriptionPeriodUnitMessage.values[value]; - case 133: - return SKPaymentTransactionMessage.decode(readValue(buffer)!); - case 134: - return SKPaymentMessage.decode(readValue(buffer)!); - case 135: - return SKErrorMessage.decode(readValue(buffer)!); - case 136: - return SKPaymentDiscountMessage.decode(readValue(buffer)!); - case 137: - return SKStorefrontMessage.decode(readValue(buffer)!); - case 138: - return SKProductsResponseMessage.decode(readValue(buffer)!); - case 139: - return SKProductMessage.decode(readValue(buffer)!); - case 140: - return SKPriceLocaleMessage.decode(readValue(buffer)!); - case 141: - return SKProductDiscountMessage.decode(readValue(buffer)!); - case 142: - return SKProductSubscriptionPeriodMessage.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class TestInAppPurchaseApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - - /// Returns if the current device is able to make payments - bool canMakePayments(); - - List transactions(); - - SKStorefrontMessage storefront(); - - void addPayment(Map paymentMap); - - Future startProductRequest( - List productIdentifiers, - ); - - void finishTransaction(Map finishMap); - - void restoreTransactions(String? applicationUserName); - - void presentCodeRedemptionSheet(); - - String? retrieveReceiptData(); - - Future refreshReceipt({Map? receiptProperties}); - - void startObservingPaymentQueue(); - - void stopObservingPaymentQueue(); - - void registerPaymentQueueDelegate(); - - void removePaymentQueueDelegate(); - - void showPriceConsentIfNeeded(); - - bool supportsStoreKit2(); - - static void setUp( - TestInAppPurchaseApi? api, { - BinaryMessenger? binaryMessenger, - String messageChannelSuffix = '', - }) { - messageChannelSuffix = messageChannelSuffix.isNotEmpty - ? '.$messageChannelSuffix' - : ''; - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final bool output = api.canMakePayments(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final List output = api - .transactions(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final SKStorefrontMessage output = api.storefront(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment was null.', - ); - final List args = (message as List?)!; - final Map? arg_paymentMap = - (args[0] as Map?)?.cast(); - assert( - arg_paymentMap != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment was null, expected non-null Map.', - ); - try { - api.addPayment(arg_paymentMap!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest was null.', - ); - final List args = (message as List?)!; - final List? arg_productIdentifiers = - (args[0] as List?)?.cast(); - assert( - arg_productIdentifiers != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest was null, expected non-null List.', - ); - try { - final SKProductsResponseMessage output = await api - .startProductRequest(arg_productIdentifiers!); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction was null.', - ); - final List args = (message as List?)!; - final Map? arg_finishMap = - (args[0] as Map?)?.cast(); - assert( - arg_finishMap != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction was null, expected non-null Map.', - ); - try { - api.finishTransaction(arg_finishMap!); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions was null.', - ); - final List args = (message as List?)!; - final String? arg_applicationUserName = (args[0] as String?); - try { - api.restoreTransactions(arg_applicationUserName); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.presentCodeRedemptionSheet(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final String? output = api.retrieveReceiptData(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - assert( - message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt was null.', - ); - final List args = (message as List?)!; - final Map? arg_receiptProperties = - (args[0] as Map?)?.cast(); - try { - await api.refreshReceipt( - receiptProperties: arg_receiptProperties, - ); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.startObservingPaymentQueue(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.stopObservingPaymentQueue(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.registerPaymentQueueDelegate(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.removePaymentQueueDelegate(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - api.showPriceConsentIfNeeded(); - return wrapResponse(empty: true); - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - { - final BasicMessageChannel - pigeonVar_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.supportsStoreKit2$messageChannelSuffix', - pigeonChannelCodec, - binaryMessenger: binaryMessenger, - ); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(pigeonVar_channel, ( - Object? message, - ) async { - try { - final bool output = api.supportsStoreKit2(); - return [output]; - } on PlatformException catch (e) { - return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException( - code: 'error', - message: e.toString(), - ), - ); - } - }); - } - } - } -}