From 7a2a6687c307611dfdfd50b9a94a1123b01d0030 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 15 Feb 2024 10:34:02 -0800 Subject: [PATCH 01/14] prior to native tests --- .../darwin/Classes/InAppPurchasePlugin.m | 139 +++---- .../darwin/Classes/messages.g.h | 198 +++++---- .../darwin/Classes/messages.g.m | 380 +++++++++++------- .../RunnerTests/InAppPurchasePluginTests.m | 35 +- .../lib/src/messages.g.dart | 271 +++++++++---- .../sk_payment_queue_wrapper.dart | 15 +- .../sk_receipt_manager.dart | 6 +- .../store_kit_wrappers/sk_request_maker.dart | 5 +- .../pigeons/messages.dart | 15 + .../test/fakes/fake_storekit_platform.dart | 37 ++ .../sk_methodchannel_apis_test.dart | 53 ++- .../test/test_api.g.dart | 350 ++++++++++------ 12 files changed, 918 insertions(+), 586 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index 82366537404..7958b57f135 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -86,29 +86,8 @@ - (instancetype)initWithRegistrar:(NSObject *)registrar binaryMessenger:[registrar messenger]]; return self; } - - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - if ([@"-[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString:call.method]) { - [self retrieveReceiptData:call result:result]; - } else if ([@"-[InAppPurchasePlugin refreshReceipt:result:]" isEqualToString:call.method]) { - [self refreshReceipt:call result:result]; - } else if ([@"-[SKPaymentQueue startObservingTransactionQueue]" isEqualToString:call.method]) { - [self startObservingPaymentQueue:result]; - } else if ([@"-[SKPaymentQueue stopObservingTransactionQueue]" isEqualToString:call.method]) { - [self stopObservingPaymentQueue:result]; -#if TARGET_OS_IOS - } else if ([@"-[SKPaymentQueue registerDelegate]" isEqualToString:call.method]) { - [self registerPaymentQueueDelegate:result]; -#endif - } else if ([@"-[SKPaymentQueue removeDelegate]" isEqualToString:call.method]) { - [self removePaymentQueueDelegate:result]; -#if TARGET_OS_IOS - } else if ([@"-[SKPaymentQueue showPriceConsentIfNeeded]" isEqualToString:call.method]) { - [self showPriceConsentIfNeeded:result]; -#endif - } else { - result(FlutterMethodNotImplemented); - } + result(FlutterMethodNotImplemented); } - (nullable NSNumber *)canMakePaymentsWithError: @@ -270,62 +249,8 @@ - (void)presentCodeRedemptionSheetWithError: #endif } -- (void)retrieveReceiptData:(FlutterMethodCall *)call result:(FlutterResult)result { - FlutterError *error = nil; - NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&error]; - if (error) { - result(error); - return; - } - result(receiptData); -} - -- (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result { - NSDictionary *arguments = call.arguments; - SKReceiptRefreshRequest *request; - if (arguments) { - if (![arguments isKindOfClass:[NSDictionary class]]) { - result([FlutterError errorWithCode:@"storekit_invalid_argument" - message:@"Argument type of startRequest is not array" - details:call.arguments]); - return; - } - NSMutableDictionary *properties = [NSMutableDictionary new]; - properties[SKReceiptPropertyIsExpired] = arguments[@"isExpired"]; - properties[SKReceiptPropertyIsRevoked] = arguments[@"isRevoked"]; - properties[SKReceiptPropertyIsVolumePurchase] = arguments[@"isVolumePurchase"]; - request = [self getRefreshReceiptRequest:properties]; - } else { - request = [self getRefreshReceiptRequest:nil]; - } - FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; - [self.requestHandlers addObject:handler]; - __weak typeof(self) weakSelf = self; - [handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable response, - NSError *_Nullable error) { - if (error) { - result([FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error" - message:error.localizedDescription - details:error.description]); - return; - } - result(nil); - [weakSelf.requestHandlers removeObject:handler]; - }]; -} - -- (void)startObservingPaymentQueue:(FlutterResult)result { - [_paymentQueueHandler startObservingPaymentQueue]; - result(nil); -} - -- (void)stopObservingPaymentQueue:(FlutterResult)result { - [_paymentQueueHandler stopObservingPaymentQueue]; - result(nil); -} - +- (void)registerPaymentQueueDelegateWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { #if TARGET_OS_IOS -- (void)registerPaymentQueueDelegate:(FlutterResult)result { if (@available(iOS 13.0, *)) { _paymentQueueDelegateCallbackChannel = [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase_payment_queue_delegate" @@ -335,27 +260,73 @@ - (void)registerPaymentQueueDelegate:(FlutterResult)result { initWithMethodChannel:_paymentQueueDelegateCallbackChannel]; _paymentQueueHandler.delegate = _paymentQueueDelegate; } - result(nil); -} #endif +} -- (void)removePaymentQueueDelegate:(FlutterResult)result { +- (void)removePaymentQueueDelegateWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { if (@available(iOS 13.0, *)) { _paymentQueueHandler.delegate = nil; } _paymentQueueDelegate = nil; _paymentQueueDelegateCallbackChannel = nil; - result(nil); } + +- (NSString * _Nullable)retrieveReceiptDataWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { + FlutterError *flutterError; + NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&flutterError]; + if (flutterError) { + *error = flutterError; + return nil; + } + return receiptData; +} + +- (void)showPriceConsentIfNeededWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { #if TARGET_OS_IOS -- (void)showPriceConsentIfNeeded:(FlutterResult)result { if (@available(iOS 13.4, *)) { [_paymentQueueHandler showPriceConsentIfNeeded]; } - result(nil); -} #endif +} + +- (void)startObservingPaymentQueueWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { + [_paymentQueueHandler startObservingPaymentQueue]; +} + +- (void)stopObservingPaymentQueueWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { + [_paymentQueueHandler stopObservingPaymentQueue]; +} + +- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties completion:(nonnull void (^)(FlutterError * _Nullable))completion { + SKReceiptRefreshRequest *request; + if (receiptProperties) { + // This call is for testing + NSMutableDictionary *properties = [NSMutableDictionary new]; + properties[SKReceiptPropertyIsExpired] = receiptProperties[@"isExpired"]; + properties[SKReceiptPropertyIsRevoked] = receiptProperties[@"isRevoked"]; + properties[SKReceiptPropertyIsVolumePurchase] = receiptProperties[@"isVolumePurchase"]; + request = [self getRefreshReceiptRequest:properties]; + } else { + request = [self getRefreshReceiptRequest:nil]; + } + + FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; + [self.requestHandlers addObject:handler]; + __weak typeof(self) weakSelf = self; + [handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable response, + NSError *_Nullable error) { + FlutterError *requestError; + if (error) { + requestError = [FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error" + message:error.localizedDescription + details:error.description]; + completion(requestError); + } + completion(nil); + [weakSelf.requestHandlers removeObject:handler]; + }]; +} - (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key { id value = dictionary[key]; diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h index 87a19721250..2befbf60501 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h @@ -1,7 +1,3 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - // Autogenerated from Pigeon (v16.0.4), do not edit directly. // See also: https://pub.dev/packages/pigeon @@ -68,8 +64,7 @@ typedef NS_ENUM(NSUInteger, SKProductDiscountTypeMessage) { typedef NS_ENUM(NSUInteger, SKProductDiscountPaymentModeMessage) { /// Allows user to pay the discounted price at each payment period. SKProductDiscountPaymentModeMessagePayAsYouGo = 0, - /// Allows user to pay the discounted price upfront and receive the product for the rest of time - /// that was paid for. + /// Allows user to pay the discounted price upfront and receive the product for the rest of time that was paid for. SKProductDiscountPaymentModeMessagePayUpFront = 1, /// User pays nothing during the discounted period. SKProductDiscountPaymentModeMessageFreeTrial = 2, @@ -111,140 +106,140 @@ typedef NS_ENUM(NSUInteger, SKSubscriptionPeriodUnitMessage) { /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithPayment:(SKPaymentMessage *)payment - transactionState:(SKPaymentTransactionStateMessage)transactionState - originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction - transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp - transactionIdentifier:(nullable NSString *)transactionIdentifier - error:(nullable SKErrorMessage *)error; -@property(nonatomic, strong) SKPaymentMessage *payment; + transactionState:(SKPaymentTransactionStateMessage)transactionState + originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction + transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp + transactionIdentifier:(nullable NSString *)transactionIdentifier + error:(nullable SKErrorMessage *)error; +@property(nonatomic, strong) SKPaymentMessage * payment; @property(nonatomic, assign) SKPaymentTransactionStateMessage transactionState; -@property(nonatomic, strong, nullable) SKPaymentTransactionMessage *originalTransaction; -@property(nonatomic, strong, nullable) NSNumber *transactionTimeStamp; -@property(nonatomic, copy, nullable) NSString *transactionIdentifier; -@property(nonatomic, strong, nullable) SKErrorMessage *error; +@property(nonatomic, strong, nullable) SKPaymentTransactionMessage * originalTransaction; +@property(nonatomic, strong, nullable) NSNumber * transactionTimeStamp; +@property(nonatomic, copy, nullable) NSString * transactionIdentifier; +@property(nonatomic, strong, nullable) SKErrorMessage * error; @end @interface SKPaymentMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - applicationUsername:(nullable NSString *)applicationUsername - requestData:(nullable NSString *)requestData - quantity:(NSInteger)quantity - simulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox - paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount; -@property(nonatomic, copy) NSString *productIdentifier; -@property(nonatomic, copy, nullable) NSString *applicationUsername; -@property(nonatomic, copy, nullable) NSString *requestData; -@property(nonatomic, assign) NSInteger quantity; -@property(nonatomic, assign) BOOL simulatesAskToBuyInSandbox; -@property(nonatomic, strong, nullable) SKPaymentDiscountMessage *paymentDiscount; + applicationUsername:(nullable NSString *)applicationUsername + requestData:(nullable NSString *)requestData + quantity:(NSInteger )quantity + simulatesAskToBuyInSandbox:(BOOL )simulatesAskToBuyInSandbox + paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount; +@property(nonatomic, copy) NSString * productIdentifier; +@property(nonatomic, copy, nullable) NSString * applicationUsername; +@property(nonatomic, copy, nullable) NSString * requestData; +@property(nonatomic, assign) NSInteger quantity; +@property(nonatomic, assign) BOOL simulatesAskToBuyInSandbox; +@property(nonatomic, strong, nullable) SKPaymentDiscountMessage * paymentDiscount; @end @interface SKErrorMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithCode:(NSInteger)code - domain:(NSString *)domain - userInfo:(NSDictionary *)userInfo; -@property(nonatomic, assign) NSInteger code; -@property(nonatomic, copy) NSString *domain; -@property(nonatomic, copy) NSDictionary *userInfo; ++ (instancetype)makeWithCode:(NSInteger )code + domain:(NSString *)domain + userInfo:(NSDictionary *)userInfo; +@property(nonatomic, assign) NSInteger code; +@property(nonatomic, copy) NSString * domain; +@property(nonatomic, copy) NSDictionary * userInfo; @end @interface SKPaymentDiscountMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithIdentifier:(NSString *)identifier - keyIdentifier:(NSString *)keyIdentifier - nonce:(NSString *)nonce - signature:(NSString *)signature - timestamp:(NSInteger)timestamp; -@property(nonatomic, copy) NSString *identifier; -@property(nonatomic, copy) NSString *keyIdentifier; -@property(nonatomic, copy) NSString *nonce; -@property(nonatomic, copy) NSString *signature; -@property(nonatomic, assign) NSInteger timestamp; + keyIdentifier:(NSString *)keyIdentifier + nonce:(NSString *)nonce + signature:(NSString *)signature + timestamp:(NSInteger )timestamp; +@property(nonatomic, copy) NSString * identifier; +@property(nonatomic, copy) NSString * keyIdentifier; +@property(nonatomic, copy) NSString * nonce; +@property(nonatomic, copy) NSString * signature; +@property(nonatomic, assign) NSInteger timestamp; @end @interface SKStorefrontMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithCountryCode:(NSString *)countryCode identifier:(NSString *)identifier; -@property(nonatomic, copy) NSString *countryCode; -@property(nonatomic, copy) NSString *identifier; ++ (instancetype)makeWithCountryCode:(NSString *)countryCode + identifier:(NSString *)identifier; +@property(nonatomic, copy) NSString * countryCode; +@property(nonatomic, copy) NSString * identifier; @end @interface SKProductsResponseMessage : NSObject + (instancetype)makeWithProducts:(nullable NSArray *)products - invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers; -@property(nonatomic, copy, nullable) NSArray *products; -@property(nonatomic, copy, nullable) NSArray *invalidProductIdentifiers; + invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers; +@property(nonatomic, copy, nullable) NSArray * products; +@property(nonatomic, copy, nullable) NSArray * invalidProductIdentifiers; @end @interface SKProductMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - localizedTitle:(NSString *)localizedTitle - localizedDescription:(NSString *)localizedDescription - priceLocale:(SKPriceLocaleMessage *)priceLocale - subscriptionGroupIdentifier:(nullable NSString *)subscriptionGroupIdentifier - price:(NSString *)price - subscriptionPeriod: - (nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod - introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice - discounts:(nullable NSArray *)discounts; -@property(nonatomic, copy) NSString *productIdentifier; -@property(nonatomic, copy) NSString *localizedTitle; -@property(nonatomic, copy) NSString *localizedDescription; -@property(nonatomic, strong) SKPriceLocaleMessage *priceLocale; -@property(nonatomic, copy, nullable) NSString *subscriptionGroupIdentifier; -@property(nonatomic, copy) NSString *price; -@property(nonatomic, strong, nullable) SKProductSubscriptionPeriodMessage *subscriptionPeriod; -@property(nonatomic, strong, nullable) SKProductDiscountMessage *introductoryPrice; -@property(nonatomic, copy, nullable) NSArray *discounts; + localizedTitle:(NSString *)localizedTitle + localizedDescription:(NSString *)localizedDescription + priceLocale:(SKPriceLocaleMessage *)priceLocale + subscriptionGroupIdentifier:(nullable NSString *)subscriptionGroupIdentifier + price:(NSString *)price + subscriptionPeriod:(nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod + introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice + discounts:(nullable NSArray *)discounts; +@property(nonatomic, copy) NSString * productIdentifier; +@property(nonatomic, copy) NSString * localizedTitle; +@property(nonatomic, copy) NSString * localizedDescription; +@property(nonatomic, strong) SKPriceLocaleMessage * priceLocale; +@property(nonatomic, copy, nullable) NSString * subscriptionGroupIdentifier; +@property(nonatomic, copy) NSString * price; +@property(nonatomic, strong, nullable) SKProductSubscriptionPeriodMessage * subscriptionPeriod; +@property(nonatomic, strong, nullable) SKProductDiscountMessage * introductoryPrice; +@property(nonatomic, copy, nullable) NSArray * discounts; @end @interface SKPriceLocaleMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithCurrencySymbol:(NSString *)currencySymbol - currencyCode:(NSString *)currencyCode - countryCode:(NSString *)countryCode; -/// The currency symbol for the locale, e.g. $ for US locale. -@property(nonatomic, copy) NSString *currencySymbol; -/// The currency code for the locale, e.g. USD for US locale. -@property(nonatomic, copy) NSString *currencyCode; -/// The country code for the locale, e.g. US for US locale. -@property(nonatomic, copy) NSString *countryCode; + currencyCode:(NSString *)currencyCode + countryCode:(NSString *)countryCode; +///The currency symbol for the locale, e.g. $ for US locale. +@property(nonatomic, copy) NSString * currencySymbol; +///The currency code for the locale, e.g. USD for US locale. +@property(nonatomic, copy) NSString * currencyCode; +///The country code for the locale, e.g. US for US locale. +@property(nonatomic, copy) NSString * countryCode; @end @interface SKProductDiscountMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithPrice:(NSString *)price - priceLocale:(SKPriceLocaleMessage *)priceLocale - numberOfPeriods:(NSInteger)numberOfPeriods - paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode - subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod - identifier:(nullable NSString *)identifier - type:(SKProductDiscountTypeMessage)type; -@property(nonatomic, copy) NSString *price; -@property(nonatomic, strong) SKPriceLocaleMessage *priceLocale; -@property(nonatomic, assign) NSInteger numberOfPeriods; + priceLocale:(SKPriceLocaleMessage *)priceLocale + numberOfPeriods:(NSInteger )numberOfPeriods + paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode + subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod + identifier:(nullable NSString *)identifier + type:(SKProductDiscountTypeMessage)type; +@property(nonatomic, copy) NSString * price; +@property(nonatomic, strong) SKPriceLocaleMessage * priceLocale; +@property(nonatomic, assign) NSInteger numberOfPeriods; @property(nonatomic, assign) SKProductDiscountPaymentModeMessage paymentMode; -@property(nonatomic, strong) SKProductSubscriptionPeriodMessage *subscriptionPeriod; -@property(nonatomic, copy, nullable) NSString *identifier; +@property(nonatomic, strong) SKProductSubscriptionPeriodMessage * subscriptionPeriod; +@property(nonatomic, copy, nullable) NSString * identifier; @property(nonatomic, assign) SKProductDiscountTypeMessage type; @end @interface SKProductSubscriptionPeriodMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithNumberOfUnits:(NSInteger)numberOfUnits - unit:(SKSubscriptionPeriodUnitMessage)unit; -@property(nonatomic, assign) NSInteger numberOfUnits; ++ (instancetype)makeWithNumberOfUnits:(NSInteger )numberOfUnits + unit:(SKSubscriptionPeriodUnitMessage)unit; +@property(nonatomic, assign) NSInteger numberOfUnits; @property(nonatomic, assign) SKSubscriptionPeriodUnitMessage unit; @end @@ -257,23 +252,24 @@ NSObject *InAppPurchaseAPIGetCodec(void); /// @return `nil` only when `error != nil`. - (nullable NSNumber *)canMakePaymentsWithError:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable NSArray *)transactionsWithError: - (FlutterError *_Nullable *_Nonnull)error; +- (nullable NSArray *)transactionsWithError:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. - (nullable SKStorefrontMessage *)storefrontWithError:(FlutterError *_Nullable *_Nonnull)error; -- (void)addPaymentPaymentMap:(NSDictionary *)paymentMap - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)startProductRequestProductIdentifiers:(NSArray *)productIdentifiers - completion:(void (^)(SKProductsResponseMessage *_Nullable, - FlutterError *_Nullable))completion; -- (void)finishTransactionFinishMap:(NSDictionary *)finishMap - error:(FlutterError *_Nullable *_Nonnull)error; -- (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName - error:(FlutterError *_Nullable *_Nonnull)error; +- (void)addPaymentPaymentMap:(NSDictionary *)paymentMap error:(FlutterError *_Nullable *_Nonnull)error; +- (void)startProductRequestProductIdentifiers:(NSArray *)productIdentifiers completion:(void (^)(SKProductsResponseMessage *_Nullable, FlutterError *_Nullable))completion; +- (void)finishTransactionFinishMap:(NSDictionary *)finishMap error:(FlutterError *_Nullable *_Nonnull)error; +- (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName error:(FlutterError *_Nullable *_Nonnull)error; - (void)presentCodeRedemptionSheetWithError:(FlutterError *_Nullable *_Nonnull)error; +/// @return `nil` only when `error != nil`. +- (nullable NSString *)retrieveReceiptDataWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties completion:(void (^)(FlutterError *_Nullable))completion; +- (void)startObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)stopObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)registerPaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)removePaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable *_Nonnull)error; @end -extern void SetUpInAppPurchaseAPI(id binaryMessenger, - NSObject *_Nullable api); +extern void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m index 79599d932e0..80d6a3d0cf2 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m @@ -1,7 +1,3 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - // Autogenerated from Pigeon (v16.0.4), do not edit directly. // See also: https://pub.dev/packages/pigeon @@ -133,12 +129,12 @@ - (NSArray *)toList; @implementation SKPaymentTransactionMessage + (instancetype)makeWithPayment:(SKPaymentMessage *)payment - transactionState:(SKPaymentTransactionStateMessage)transactionState - originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction - transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp - transactionIdentifier:(nullable NSString *)transactionIdentifier - error:(nullable SKErrorMessage *)error { - SKPaymentTransactionMessage *pigeonResult = [[SKPaymentTransactionMessage alloc] init]; + transactionState:(SKPaymentTransactionStateMessage)transactionState + originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction + transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp + transactionIdentifier:(nullable NSString *)transactionIdentifier + error:(nullable SKErrorMessage *)error { + SKPaymentTransactionMessage* pigeonResult = [[SKPaymentTransactionMessage alloc] init]; pigeonResult.payment = payment; pigeonResult.transactionState = transactionState; pigeonResult.originalTransaction = originalTransaction; @@ -151,8 +147,7 @@ + (SKPaymentTransactionMessage *)fromList:(NSArray *)list { SKPaymentTransactionMessage *pigeonResult = [[SKPaymentTransactionMessage alloc] init]; pigeonResult.payment = [SKPaymentMessage nullableFromList:(GetNullableObjectAtIndex(list, 0))]; pigeonResult.transactionState = [GetNullableObjectAtIndex(list, 1) integerValue]; - pigeonResult.originalTransaction = - [SKPaymentTransactionMessage nullableFromList:(GetNullableObjectAtIndex(list, 2))]; + pigeonResult.originalTransaction = [SKPaymentTransactionMessage nullableFromList:(GetNullableObjectAtIndex(list, 2))]; pigeonResult.transactionTimeStamp = GetNullableObjectAtIndex(list, 3); pigeonResult.transactionIdentifier = GetNullableObjectAtIndex(list, 4); pigeonResult.error = [SKErrorMessage nullableFromList:(GetNullableObjectAtIndex(list, 5))]; @@ -175,12 +170,12 @@ - (NSArray *)toList { @implementation SKPaymentMessage + (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - applicationUsername:(nullable NSString *)applicationUsername - requestData:(nullable NSString *)requestData - quantity:(NSInteger)quantity - simulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox - paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount { - SKPaymentMessage *pigeonResult = [[SKPaymentMessage alloc] init]; + applicationUsername:(nullable NSString *)applicationUsername + requestData:(nullable NSString *)requestData + quantity:(NSInteger )quantity + simulatesAskToBuyInSandbox:(BOOL )simulatesAskToBuyInSandbox + paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount { + SKPaymentMessage* pigeonResult = [[SKPaymentMessage alloc] init]; pigeonResult.productIdentifier = productIdentifier; pigeonResult.applicationUsername = applicationUsername; pigeonResult.requestData = requestData; @@ -196,8 +191,7 @@ + (SKPaymentMessage *)fromList:(NSArray *)list { pigeonResult.requestData = GetNullableObjectAtIndex(list, 2); pigeonResult.quantity = [GetNullableObjectAtIndex(list, 3) integerValue]; pigeonResult.simulatesAskToBuyInSandbox = [GetNullableObjectAtIndex(list, 4) boolValue]; - pigeonResult.paymentDiscount = - [SKPaymentDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 5))]; + pigeonResult.paymentDiscount = [SKPaymentDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 5))]; return pigeonResult; } + (nullable SKPaymentMessage *)nullableFromList:(NSArray *)list { @@ -216,10 +210,10 @@ - (NSArray *)toList { @end @implementation SKErrorMessage -+ (instancetype)makeWithCode:(NSInteger)code - domain:(NSString *)domain - userInfo:(NSDictionary *)userInfo { - SKErrorMessage *pigeonResult = [[SKErrorMessage alloc] init]; ++ (instancetype)makeWithCode:(NSInteger )code + domain:(NSString *)domain + userInfo:(NSDictionary *)userInfo { + SKErrorMessage* pigeonResult = [[SKErrorMessage alloc] init]; pigeonResult.code = code; pigeonResult.domain = domain; pigeonResult.userInfo = userInfo; @@ -246,11 +240,11 @@ - (NSArray *)toList { @implementation SKPaymentDiscountMessage + (instancetype)makeWithIdentifier:(NSString *)identifier - keyIdentifier:(NSString *)keyIdentifier - nonce:(NSString *)nonce - signature:(NSString *)signature - timestamp:(NSInteger)timestamp { - SKPaymentDiscountMessage *pigeonResult = [[SKPaymentDiscountMessage alloc] init]; + keyIdentifier:(NSString *)keyIdentifier + nonce:(NSString *)nonce + signature:(NSString *)signature + timestamp:(NSInteger )timestamp { + SKPaymentDiscountMessage* pigeonResult = [[SKPaymentDiscountMessage alloc] init]; pigeonResult.identifier = identifier; pigeonResult.keyIdentifier = keyIdentifier; pigeonResult.nonce = nonce; @@ -282,8 +276,9 @@ - (NSArray *)toList { @end @implementation SKStorefrontMessage -+ (instancetype)makeWithCountryCode:(NSString *)countryCode identifier:(NSString *)identifier { - SKStorefrontMessage *pigeonResult = [[SKStorefrontMessage alloc] init]; ++ (instancetype)makeWithCountryCode:(NSString *)countryCode + identifier:(NSString *)identifier { + SKStorefrontMessage* pigeonResult = [[SKStorefrontMessage alloc] init]; pigeonResult.countryCode = countryCode; pigeonResult.identifier = identifier; return pigeonResult; @@ -307,8 +302,8 @@ - (NSArray *)toList { @implementation SKProductsResponseMessage + (instancetype)makeWithProducts:(nullable NSArray *)products - invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers { - SKProductsResponseMessage *pigeonResult = [[SKProductsResponseMessage alloc] init]; + invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers { + SKProductsResponseMessage* pigeonResult = [[SKProductsResponseMessage alloc] init]; pigeonResult.products = products; pigeonResult.invalidProductIdentifiers = invalidProductIdentifiers; return pigeonResult; @@ -331,17 +326,16 @@ - (NSArray *)toList { @end @implementation SKProductMessage -+ (instancetype) - makeWithProductIdentifier:(NSString *)productIdentifier - localizedTitle:(NSString *)localizedTitle - localizedDescription:(NSString *)localizedDescription - priceLocale:(SKPriceLocaleMessage *)priceLocale ++ (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier + localizedTitle:(NSString *)localizedTitle + localizedDescription:(NSString *)localizedDescription + priceLocale:(SKPriceLocaleMessage *)priceLocale subscriptionGroupIdentifier:(nullable NSString *)subscriptionGroupIdentifier - price:(NSString *)price - subscriptionPeriod:(nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod - introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice - discounts:(nullable NSArray *)discounts { - SKProductMessage *pigeonResult = [[SKProductMessage alloc] init]; + price:(NSString *)price + subscriptionPeriod:(nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod + introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice + discounts:(nullable NSArray *)discounts { + SKProductMessage* pigeonResult = [[SKProductMessage alloc] init]; pigeonResult.productIdentifier = productIdentifier; pigeonResult.localizedTitle = localizedTitle; pigeonResult.localizedDescription = localizedDescription; @@ -358,14 +352,11 @@ + (SKProductMessage *)fromList:(NSArray *)list { pigeonResult.productIdentifier = GetNullableObjectAtIndex(list, 0); pigeonResult.localizedTitle = GetNullableObjectAtIndex(list, 1); pigeonResult.localizedDescription = GetNullableObjectAtIndex(list, 2); - pigeonResult.priceLocale = - [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 3))]; + pigeonResult.priceLocale = [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 3))]; pigeonResult.subscriptionGroupIdentifier = GetNullableObjectAtIndex(list, 4); pigeonResult.price = GetNullableObjectAtIndex(list, 5); - pigeonResult.subscriptionPeriod = - [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 6))]; - pigeonResult.introductoryPrice = - [SKProductDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 7))]; + pigeonResult.subscriptionPeriod = [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 6))]; + pigeonResult.introductoryPrice = [SKProductDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 7))]; pigeonResult.discounts = GetNullableObjectAtIndex(list, 8); return pigeonResult; } @@ -389,9 +380,9 @@ - (NSArray *)toList { @implementation SKPriceLocaleMessage + (instancetype)makeWithCurrencySymbol:(NSString *)currencySymbol - currencyCode:(NSString *)currencyCode - countryCode:(NSString *)countryCode { - SKPriceLocaleMessage *pigeonResult = [[SKPriceLocaleMessage alloc] init]; + currencyCode:(NSString *)currencyCode + countryCode:(NSString *)countryCode { + SKPriceLocaleMessage* pigeonResult = [[SKPriceLocaleMessage alloc] init]; pigeonResult.currencySymbol = currencySymbol; pigeonResult.currencyCode = currencyCode; pigeonResult.countryCode = countryCode; @@ -418,13 +409,13 @@ - (NSArray *)toList { @implementation SKProductDiscountMessage + (instancetype)makeWithPrice:(NSString *)price - priceLocale:(SKPriceLocaleMessage *)priceLocale - numberOfPeriods:(NSInteger)numberOfPeriods - paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode - subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod - identifier:(nullable NSString *)identifier - type:(SKProductDiscountTypeMessage)type { - SKProductDiscountMessage *pigeonResult = [[SKProductDiscountMessage alloc] init]; + priceLocale:(SKPriceLocaleMessage *)priceLocale + numberOfPeriods:(NSInteger )numberOfPeriods + paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode + subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod + identifier:(nullable NSString *)identifier + type:(SKProductDiscountTypeMessage)type { + SKProductDiscountMessage* pigeonResult = [[SKProductDiscountMessage alloc] init]; pigeonResult.price = price; pigeonResult.priceLocale = priceLocale; pigeonResult.numberOfPeriods = numberOfPeriods; @@ -437,12 +428,10 @@ + (instancetype)makeWithPrice:(NSString *)price + (SKProductDiscountMessage *)fromList:(NSArray *)list { SKProductDiscountMessage *pigeonResult = [[SKProductDiscountMessage alloc] init]; pigeonResult.price = GetNullableObjectAtIndex(list, 0); - pigeonResult.priceLocale = - [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 1))]; + pigeonResult.priceLocale = [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 1))]; pigeonResult.numberOfPeriods = [GetNullableObjectAtIndex(list, 2) integerValue]; pigeonResult.paymentMode = [GetNullableObjectAtIndex(list, 3) integerValue]; - pigeonResult.subscriptionPeriod = - [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 4))]; + pigeonResult.subscriptionPeriod = [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 4))]; pigeonResult.identifier = GetNullableObjectAtIndex(list, 5); pigeonResult.type = [GetNullableObjectAtIndex(list, 6) integerValue]; return pigeonResult; @@ -464,17 +453,15 @@ - (NSArray *)toList { @end @implementation SKProductSubscriptionPeriodMessage -+ (instancetype)makeWithNumberOfUnits:(NSInteger)numberOfUnits - unit:(SKSubscriptionPeriodUnitMessage)unit { - SKProductSubscriptionPeriodMessage *pigeonResult = - [[SKProductSubscriptionPeriodMessage alloc] init]; ++ (instancetype)makeWithNumberOfUnits:(NSInteger )numberOfUnits + unit:(SKSubscriptionPeriodUnitMessage)unit { + SKProductSubscriptionPeriodMessage* pigeonResult = [[SKProductSubscriptionPeriodMessage alloc] init]; pigeonResult.numberOfUnits = numberOfUnits; pigeonResult.unit = unit; return pigeonResult; } + (SKProductSubscriptionPeriodMessage *)fromList:(NSArray *)list { - SKProductSubscriptionPeriodMessage *pigeonResult = - [[SKProductSubscriptionPeriodMessage alloc] init]; + SKProductSubscriptionPeriodMessage *pigeonResult = [[SKProductSubscriptionPeriodMessage alloc] init]; pigeonResult.numberOfUnits = [GetNullableObjectAtIndex(list, 0) integerValue]; pigeonResult.unit = [GetNullableObjectAtIndex(list, 1) integerValue]; return pigeonResult; @@ -495,25 +482,25 @@ @interface InAppPurchaseAPICodecReader : FlutterStandardReader @implementation InAppPurchaseAPICodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [SKErrorMessage fromList:[self readValue]]; - case 129: + case 129: return [SKPaymentDiscountMessage fromList:[self readValue]]; - case 130: + case 130: return [SKPaymentMessage fromList:[self readValue]]; - case 131: + case 131: return [SKPaymentTransactionMessage fromList:[self readValue]]; - case 132: + case 132: return [SKPriceLocaleMessage fromList:[self readValue]]; - case 133: + case 133: return [SKProductDiscountMessage fromList:[self readValue]]; - case 134: + case 134: return [SKProductMessage fromList:[self readValue]]; - case 135: + case 135: return [SKProductSubscriptionPeriodMessage fromList:[self readValue]]; - case 136: + case 136: return [SKProductsResponseMessage fromList:[self readValue]]; - case 137: + case 137: return [SKStorefrontMessage fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -576,27 +563,22 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - InAppPurchaseAPICodecReaderWriter *readerWriter = - [[InAppPurchaseAPICodecReaderWriter alloc] init]; + InAppPurchaseAPICodecReaderWriter *readerWriter = [[InAppPurchaseAPICodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void SetUpInAppPurchaseAPI(id binaryMessenger, - NSObject *api) { +void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject *api) { /// Returns if the current device is able to make payments { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName: - @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert( - [api respondsToSelector:@selector(canMakePaymentsWithError:)], - @"InAppPurchaseAPI api (%@) doesn't respond to @selector(canMakePaymentsWithError:)", - api); + NSCAssert([api respondsToSelector:@selector(canMakePaymentsWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(canMakePaymentsWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; NSNumber *output = [api canMakePaymentsWithError:&error]; @@ -607,14 +589,13 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(transactionsWithError:)], - @"InAppPurchaseAPI api (%@) doesn't respond to @selector(transactionsWithError:)", - api); + NSCAssert([api respondsToSelector:@selector(transactionsWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(transactionsWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; NSArray *output = [api transactionsWithError:&error]; @@ -625,14 +606,13 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(storefrontWithError:)], - @"InAppPurchaseAPI api (%@) doesn't respond to @selector(storefrontWithError:)", - api); + NSCAssert([api respondsToSelector:@selector(storefrontWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(storefrontWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; SKStorefrontMessage *output = [api storefrontWithError:&error]; @@ -643,15 +623,13 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert( - [api respondsToSelector:@selector(addPaymentPaymentMap:error:)], - @"InAppPurchaseAPI api (%@) doesn't respond to @selector(addPaymentPaymentMap:error:)", - api); + NSCAssert([api respondsToSelector:@selector(addPaymentPaymentMap:error:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(addPaymentPaymentMap:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSDictionary *arg_paymentMap = GetNullableObjectAtIndex(args, 0); @@ -664,41 +642,32 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName: - @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(startProductRequestProductIdentifiers: - completion:)], - @"InAppPurchaseAPI api (%@) doesn't respond to " - @"@selector(startProductRequestProductIdentifiers:completion:)", - api); + NSCAssert([api respondsToSelector:@selector(startProductRequestProductIdentifiers:completion:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(startProductRequestProductIdentifiers:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSArray *arg_productIdentifiers = GetNullableObjectAtIndex(args, 0); - [api startProductRequestProductIdentifiers:arg_productIdentifiers - completion:^(SKProductsResponseMessage *_Nullable output, - FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; + [api startProductRequestProductIdentifiers:arg_productIdentifiers completion:^(SKProductsResponseMessage *_Nullable output, FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; }]; } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName: - @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(finishTransactionFinishMap:error:)], - @"InAppPurchaseAPI api (%@) doesn't respond to " - @"@selector(finishTransactionFinishMap:error:)", - api); + NSCAssert([api respondsToSelector:@selector(finishTransactionFinishMap:error:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(finishTransactionFinishMap:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSDictionary *arg_finishMap = GetNullableObjectAtIndex(args, 0); @@ -711,16 +680,13 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName: - @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(restoreTransactionsApplicationUserName:error:)], - @"InAppPurchaseAPI api (%@) doesn't respond to " - @"@selector(restoreTransactionsApplicationUserName:error:)", - api); + NSCAssert([api respondsToSelector:@selector(restoreTransactionsApplicationUserName:error:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(restoreTransactionsApplicationUserName:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_applicationUserName = GetNullableObjectAtIndex(args, 0); @@ -733,16 +699,13 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, } } { - FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." - @"presentCodeRedemptionSheet" + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(presentCodeRedemptionSheetWithError:)], - @"InAppPurchaseAPI api (%@) doesn't respond to " - @"@selector(presentCodeRedemptionSheetWithError:)", - api); + NSCAssert([api respondsToSelector:@selector(presentCodeRedemptionSheetWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(presentCodeRedemptionSheetWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api presentCodeRedemptionSheetWithError:&error]; @@ -752,4 +715,125 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, [channel setMessageHandler:nil]; } } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(retrieveReceiptDataWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(retrieveReceiptDataWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + NSString *output = [api retrieveReceiptDataWithError:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(refreshReceiptReceiptProperties:completion:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(refreshReceiptReceiptProperties:completion:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + NSDictionary *arg_receiptProperties = GetNullableObjectAtIndex(args, 0); + [api refreshReceiptReceiptProperties:arg_receiptProperties completion:^(FlutterError *_Nullable error) { + callback(wrapResult(nil, error)); + }]; + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(startObservingPaymentQueueWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(startObservingPaymentQueueWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + [api startObservingPaymentQueueWithError:&error]; + callback(wrapResult(nil, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(stopObservingPaymentQueueWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(stopObservingPaymentQueueWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + [api stopObservingPaymentQueueWithError:&error]; + callback(wrapResult(nil, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(registerPaymentQueueDelegateWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(registerPaymentQueueDelegateWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + [api registerPaymentQueueDelegateWithError:&error]; + callback(wrapResult(nil, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(removePaymentQueueDelegateWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(removePaymentQueueDelegateWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + [api removePaymentQueueDelegateWithError:&error]; + callback(wrapResult(nil, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } + { + FlutterBasicMessageChannel *channel = + [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded" + binaryMessenger:binaryMessenger + codec:InAppPurchaseAPIGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(showPriceConsentIfNeededWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(showPriceConsentIfNeededWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + [api showPriceConsentIfNeededWithError:&error]; + callback(wrapResult(nil, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } } diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index d53301e54c3..fc0311b2a71 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -26,20 +26,6 @@ - (void)setUp { - (void)tearDown { } -- (void)testInvalidMethodCall { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect result to be not implemented"]; - FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"invalid" arguments:NULL]; - __block id result; - [self.plugin handleMethodCall:call - result:^(id r) { - [expectation fulfill]; - result = r; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(result, FlutterMethodNotImplemented); -} - - (void)testCanMakePayments { FlutterError *error; NSNumber *result = [self.plugin canMakePaymentsWithError:&error]; @@ -299,17 +285,8 @@ - (void)testRestoreTransactions { } - (void)testRetrieveReceiptDataSuccess { - XCTestExpectation *expectation = [self expectationWithDescription:@"receipt data retrieved"]; - FlutterMethodCall *call = [FlutterMethodCall - methodCallWithMethodName:@"-[InAppPurchasePlugin retrieveReceiptData:result:]" - arguments:nil]; - __block NSDictionary *result; - [self.plugin handleMethodCall:call - result:^(id r) { - result = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; + FlutterError *error; + id result = [self.plugin retrieveReceiptDataWithError:&error]; XCTAssertNotNil(result); XCTAssert([result isKindOfClass:[NSString class]]); } @@ -317,10 +294,10 @@ - (void)testRetrieveReceiptDataSuccess { - (void)testRetrieveReceiptDataNil { NSBundle *mockBundle = OCMPartialMock([NSBundle mainBundle]); OCMStub(mockBundle.appStoreReceiptURL).andReturn(nil); - XCTestExpectation *expectation = [self expectationWithDescription:@"nil receipt data retrieved"]; - FlutterMethodCall *call = [FlutterMethodCall - methodCallWithMethodName:@"-[InAppPurchasePlugin retrieveReceiptData:result:]" - arguments:nil]; +// XCTestExpectation *expectation = [self expectationWithDescription:@"nil receipt data retrieved"]; +// FlutterMethodCall *call = [FlutterMethodCall +// methodCallWithMethodName:@"-[InAppPurchasePlugin retrieveReceiptData:result:]" +// arguments:nil]; __block NSDictionary *result; [self.plugin handleMethodCall:call result:^(id r) { diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/messages.g.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/messages.g.dart index bfbd447de67..65e3aa5d701 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/messages.g.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/messages.g.dart @@ -15,8 +15,7 @@ PlatformException _createConnectionError(String channelName) { ); } -List wrapResponse( - {Object? result, PlatformException? error, bool empty = false}) { +List wrapResponse({Object? result, PlatformException? error, bool empty = false}) { if (empty) { return []; } @@ -33,32 +32,27 @@ enum SKPaymentTransactionStateMessage { /// transaction to update to another state. Never complete a transaction that /// is still in a purchasing state. purchasing, - /// The user's payment has been succesfully processed. /// /// You should provide the user the content that they purchased. purchased, - /// The transaction failed. /// /// Check the [PaymentTransactionWrapper.error] property from /// [PaymentTransactionWrapper] for details. failed, - /// This transaction is restoring content previously purchased by the user. /// /// The previous transaction information can be obtained in /// [PaymentTransactionWrapper.originalTransaction] from /// [PaymentTransactionWrapper]. restored, - /// The transaction is in the queue but pending external action. Wait for /// another callback to get the final state. /// /// You should update your UI to indicate that you are waiting for the /// transaction to update to another state. deferred, - /// Indicates the transaction is in an unspecified state. unspecified, } @@ -66,7 +60,6 @@ enum SKPaymentTransactionStateMessage { enum SKProductDiscountTypeMessage { /// A constant indicating the discount type is an introductory offer. introductory, - /// A constant indicating the discount type is a promotional offer. subscription, } @@ -74,13 +67,10 @@ enum SKProductDiscountTypeMessage { enum SKProductDiscountPaymentModeMessage { /// Allows user to pay the discounted price at each payment period. payAsYouGo, - /// Allows user to pay the discounted price upfront and receive the product for the rest of time that was paid for. payUpFront, - /// User pays nothing during the discounted period. freeTrial, - /// Unspecified mode. unspecified, } @@ -129,8 +119,7 @@ class SKPaymentTransactionMessage { result as List; return SKPaymentTransactionMessage( payment: SKPaymentMessage.decode(result[0]! as List), - transactionState: - SKPaymentTransactionStateMessage.values[result[1]! as int], + transactionState: SKPaymentTransactionStateMessage.values[result[1]! as int], originalTransaction: result[2] != null ? SKPaymentTransactionMessage.decode(result[2]! as List) : null, @@ -370,14 +359,12 @@ class SKProductMessage { subscriptionGroupIdentifier: result[4] as String?, price: result[5]! as String, subscriptionPeriod: result[6] != null - ? SKProductSubscriptionPeriodMessage.decode( - result[6]! as List) + ? SKProductSubscriptionPeriodMessage.decode(result[6]! as List) : null, introductoryPrice: result[7] != null ? SKProductDiscountMessage.decode(result[7]! as List) : null, - discounts: - (result[8] as List?)?.cast(), + discounts: (result[8] as List?)?.cast(), ); } } @@ -459,10 +446,8 @@ class SKProductDiscountMessage { price: result[0]! as String, priceLocale: SKPriceLocaleMessage.decode(result[1]! as List), numberOfPeriods: result[2]! as int, - paymentMode: - SKProductDiscountPaymentModeMessage.values[result[3]! as int], - subscriptionPeriod: SKProductSubscriptionPeriodMessage.decode( - result[4]! as List), + paymentMode: SKProductDiscountPaymentModeMessage.values[result[3]! as int], + subscriptionPeriod: SKProductSubscriptionPeriodMessage.decode(result[4]! as List), identifier: result[5] as String?, type: SKProductDiscountTypeMessage.values[result[6]! as int], ); @@ -537,25 +522,25 @@ class _InAppPurchaseAPICodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return SKErrorMessage.decode(readValue(buffer)!); - case 129: + case 129: return SKPaymentDiscountMessage.decode(readValue(buffer)!); - case 130: + case 130: return SKPaymentMessage.decode(readValue(buffer)!); - case 131: + case 131: return SKPaymentTransactionMessage.decode(readValue(buffer)!); - case 132: + case 132: return SKPriceLocaleMessage.decode(readValue(buffer)!); - case 133: + case 133: return SKProductDiscountMessage.decode(readValue(buffer)!); - case 134: + case 134: return SKProductMessage.decode(readValue(buffer)!); - case 135: + case 135: return SKProductSubscriptionPeriodMessage.decode(readValue(buffer)!); - case 136: + case 136: return SKProductsResponseMessage.decode(readValue(buffer)!); - case 137: + case 137: return SKStorefrontMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -571,15 +556,12 @@ class InAppPurchaseAPI { : __pigeon_binaryMessenger = binaryMessenger; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = - _InAppPurchaseAPICodec(); + static const MessageCodec pigeonChannelCodec = _InAppPurchaseAPICodec(); /// Returns if the current device is able to make payments Future canMakePayments() async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -605,10 +587,8 @@ class InAppPurchaseAPI { } Future> transactions() async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -629,16 +609,13 @@ class InAppPurchaseAPI { message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as List?)! - .cast(); + return (__pigeon_replyList[0] as List?)!.cast(); } } Future storefront() async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -664,10 +641,8 @@ class InAppPurchaseAPI { } Future addPayment(Map paymentMap) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -687,18 +662,15 @@ class InAppPurchaseAPI { } } - Future startProductRequest( - List productIdentifiers) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + Future startProductRequest(List productIdentifiers) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([productIdentifiers]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([productIdentifiers]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -718,10 +690,8 @@ class InAppPurchaseAPI { } Future finishTransaction(Map finishMap) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -742,16 +712,14 @@ class InAppPurchaseAPI { } Future restoreTransactions(String? applicationUserName) async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = await __pigeon_channel - .send([applicationUserName]) as List?; + final List? __pigeon_replyList = + await __pigeon_channel.send([applicationUserName]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -766,10 +734,167 @@ class InAppPurchaseAPI { } Future presentCodeRedemptionSheet() async { - const String __pigeon_channelName = - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet'; - final BasicMessageChannel __pigeon_channel = - BasicMessageChannel( + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future retrieveReceiptData() async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as String?)!; + } + } + + Future refreshReceipt({Map? receiptProperties}) async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([receiptProperties]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future startObservingPaymentQueue() async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future stopObservingPaymentQueue() async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future registerPaymentQueueDelegate() async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future removePaymentQueueDelegate() async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future showPriceConsentIfNeeded() async { + const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded'; + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, 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 f8fd85fcc6b..9dfd1aa864c 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 @@ -86,16 +86,14 @@ class SKPaymentQueueWrapper { /// /// Call this method when the first listener is subscribed to the /// [InAppPurchaseStoreKitPlatform.purchaseStream]. - Future startObservingTransactionQueue() => channel - .invokeMethod('-[SKPaymentQueue startObservingTransactionQueue]'); + Future startObservingTransactionQueue() => _hostApi.startObservingPaymentQueue(); /// Instructs the iOS implementation to remove the transaction observer and /// stop listening to it. /// /// Call this when there are no longer any listeners subscribed to the /// [InAppPurchaseStoreKitPlatform.purchaseStream]. - Future stopObservingTransactionQueue() => channel - .invokeMethod('-[SKPaymentQueue stopObservingTransactionQueue]'); + Future stopObservingTransactionQueue() => _hostApi.stopObservingPaymentQueue(); /// Sets an implementation of the [SKPaymentQueueDelegateWrapper]. /// @@ -109,10 +107,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 channel.invokeMethod('-[SKPaymentQueue removeDelegate]'); + await _hostApi.removePaymentQueueDelegate(); paymentQueueDelegateChannel.setMethodCallHandler(null); } else { - await channel.invokeMethod('-[SKPaymentQueue registerDelegate]'); + await _hostApi.registerPaymentQueueDelegate(); paymentQueueDelegateChannel .setMethodCallHandler(handlePaymentQueueDelegateCallbacks); } @@ -207,8 +205,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 channel - .invokeMethod('-[SKPaymentQueue showPriceConsentIfNeeded]'); + await _hostApi.showPriceConsentIfNeeded(); } /// Triage a method channel call from the platform and triggers the correct observer method. @@ -354,7 +351,7 @@ class SKError { /// /// Any key of the map must be a valid [NSErrorUserInfoKey](https://developer.apple.com/documentation/foundation/nserroruserinfokey?language=objc). @JsonKey(defaultValue: {}) - final Map userInfo; + final Map? userInfo; @override bool operator ==(Object other) { 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 b31a3d59c17..d61062bfd2b 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 @@ -5,6 +5,9 @@ import 'dart:async'; import '../channel.dart'; +import '../messages.g.dart'; + +InAppPurchaseAPI _hostApi = InAppPurchaseAPI(); // ignore: avoid_classes_with_only_static_members /// This class contains static methods to manage StoreKit receipts. @@ -17,8 +20,7 @@ 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 channel.invokeMethod( - '-[InAppPurchasePlugin retrieveReceiptData:result:]')) ?? + 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 2dc2ad7baef..564a4306238 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 @@ -54,9 +54,6 @@ class SKRequestMaker { /// * isVolumePurchase: whether the receipt is a Volume Purchase Plan receipt. Future startRefreshReceiptRequest( {Map? receiptProperties}) { - return channel.invokeMethod( - '-[InAppPurchasePlugin refreshReceipt:result:]', - receiptProperties, - ); + return _hostApi.refreshReceipt(receiptProperties: receiptProperties); } } 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 9ada32ed2e0..929bfa0f444 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 @@ -243,4 +243,19 @@ abstract class InAppPurchaseAPI { void restoreTransactions(String? applicationUserName); void presentCodeRedemptionSheet(); + + String retrieveReceiptData(); + + @async + void refreshReceipt({Map? receiptProperties}); + + void startObservingPaymentQueue(); + + void stopObservingPaymentQueue(); + + void registerPaymentQueueDelegate(); + + void removePaymentQueueDelegate(); + + void showPriceConsentIfNeeded(); } 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 48db0847bf3..b338e492e73 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 @@ -246,4 +246,41 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { return Future.value( SkProductResponseWrapper.convertToPigeon(response)); } + + @override + Future refreshReceipt({Map? receiptProperties}) { + // TODO: implement refreshReceipt + throw UnimplementedError(); + } + + @override + void registerPaymentQueueDelegate() { + // TODO: implement registerPaymentQueueDelegate + } + + @override + void removePaymentQueueDelegate() { + // TODO: implement removePaymentQueueDelegate + } + + @override + String retrieveReceiptData() { + // TODO: implement retrieveReceiptData + throw UnimplementedError(); + } + + @override + void showPriceConsentIfNeeded() { + // TODO: implement showPriceConsentIfNeeded + } + + @override + void startObservingPaymentQueue() { + // TODO: implement startObservingPaymentQueue + } + + @override + void stopObservingPaymentQueue() { + // TODO: implement stopObservingPaymentQueue + } } 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 704be83c8e2..411978a7684 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 @@ -76,10 +76,10 @@ void main() { }); test('refreshed receipt', () async { - final int receiptCountBefore = fakeStoreKitPlatform.refreshReceipt; + final int receiptCountBefore = fakeStoreKitPlatform.refreshReceiptCount; await SKRequestMaker().startRefreshReceiptRequest( receiptProperties: {'isExpired': true}); - expect(fakeStoreKitPlatform.refreshReceipt, receiptCountBefore + 1); + expect(fakeStoreKitPlatform.refreshReceiptCount, receiptCountBefore + 1); expect(fakeStoreKitPlatform.refreshReceiptParam, {'isExpired': true}); }); @@ -175,9 +175,9 @@ void main() { }); test('showPriceConsentIfNeeded should call methodChannel', () async { - expect(fakeStoreKitPlatform.showPriceConsentIfNeeded, false); + expect(fakeStoreKitPlatform.showPriceConsent, false); await SKPaymentQueueWrapper().showPriceConsentIfNeeded(); - expect(fakeStoreKitPlatform.showPriceConsentIfNeeded, true); + expect(fakeStoreKitPlatform.showPriceConsent, true); }); }); @@ -205,7 +205,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { bool getReceiptFailTest = false; // refresh receipt request - int refreshReceipt = 0; + int refreshReceiptCount = 0; late Map refreshReceiptParam; // payment queue @@ -217,7 +217,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { bool presentCodeRedemption = false; // show price consent sheet - bool showPriceConsentIfNeeded = false; + bool showPriceConsent = false; // indicate if the payment queue delegate is registered bool isPaymentQueueDelegateRegistered = false; @@ -229,7 +229,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { switch (call.method) { // request makers case '-[InAppPurchasePlugin refreshReceipt:result:]': - refreshReceipt++; + refreshReceiptCount++; refreshReceiptParam = Map.castFrom( call.arguments as Map); return Future.sync(() {}); @@ -252,7 +252,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { isPaymentQueueDelegateRegistered = false; return Future.sync(() {}); case '-[SKPaymentQueue showPriceConsentIfNeeded]': - showPriceConsentIfNeeded = true; + showPriceConsent = true; return Future.sync(() {}); } return Future.error('method not mocked'); @@ -304,6 +304,43 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } return Future.value(dummyProductResponseMessage); } + + @override + void registerPaymentQueueDelegate() { + // TODO: implement registerPaymentQueueDelegate + } + + @override + void removePaymentQueueDelegate() { + // TODO: implement removePaymentQueueDelegate + } + + @override + void startObservingPaymentQueue() { + // TODO: implement startObservingPaymentQueue + } + + @override + void stopObservingPaymentQueue() { + // TODO: implement stopObservingPaymentQueue + } + + @override + String retrieveReceiptData() { + // TODO: implement retrieveReceiptData + throw UnimplementedError(); + } + + @override + Future refreshReceipt({Map? receiptProperties}) { + // TODO: implement refreshReceipt + throw UnimplementedError(); + } + + @override + void showPriceConsentIfNeeded() { + // TODO: implement showPriceConsentIfNeeded + } } class TestPaymentQueueDelegate extends SKPaymentQueueDelegateWrapper {} 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 index 80debcebb79..0d86e5ac20a 100644 --- 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 @@ -52,25 +52,25 @@ class _TestInAppPurchaseApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return SKErrorMessage.decode(readValue(buffer)!); - case 129: + case 129: return SKPaymentDiscountMessage.decode(readValue(buffer)!); - case 130: + case 130: return SKPaymentMessage.decode(readValue(buffer)!); - case 131: + case 131: return SKPaymentTransactionMessage.decode(readValue(buffer)!); - case 132: + case 132: return SKPriceLocaleMessage.decode(readValue(buffer)!); - case 133: + case 133: return SKProductDiscountMessage.decode(readValue(buffer)!); - case 134: + case 134: return SKProductMessage.decode(readValue(buffer)!); - case 135: + case 135: return SKProductSubscriptionPeriodMessage.decode(readValue(buffer)!); - case 136: + case 136: return SKProductsResponseMessage.decode(readValue(buffer)!); - case 137: + case 137: return SKStorefrontMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -79,10 +79,8 @@ class _TestInAppPurchaseApiCodec extends StandardMessageCodec { } abstract class TestInAppPurchaseApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = - _TestInAppPurchaseApiCodec(); + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec pigeonChannelCodec = _TestInAppPurchaseApiCodec(); /// Returns if the current device is able to make payments bool canMakePayments(); @@ -93,8 +91,7 @@ abstract class TestInAppPurchaseApi { void addPayment(Map paymentMap); - Future startProductRequest( - List productIdentifiers); + Future startProductRequest(List productIdentifiers); void finishTransaction(Map finishMap); @@ -102,102 +99,90 @@ abstract class TestInAppPurchaseApi { void presentCodeRedemptionSheet(); - static void setup(TestInAppPurchaseApi? api, - {BinaryMessenger? binaryMessenger}) { + String retrieveReceiptData(); + + Future refreshReceipt({Map? receiptProperties}); + + void startObservingPaymentQueue(); + + void stopObservingPaymentQueue(); + + void registerPaymentQueueDelegate(); + + void removePaymentQueueDelegate(); + + void showPriceConsentIfNeeded(); + + static void setup(TestInAppPurchaseApi? api, {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { try { - final List output = - api.transactions(); + 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())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment was 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(); + 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 { @@ -205,64 +190,49 @@ abstract class TestInAppPurchaseApi { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest was 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(); + 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!); + 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())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction was 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(); + 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 { @@ -270,28 +240,22 @@ abstract class TestInAppPurchaseApi { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions was 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 { @@ -299,34 +263,164 @@ abstract class TestInAppPurchaseApi { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse( - error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel< - Object?>( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet', - pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet', pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(__pigeon_channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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 __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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 __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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 __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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 __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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 __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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 __pigeon_channel = BasicMessageChannel( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded', pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_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())); } }); } From 3a7fdee204f3aed51721f4573c34f183c2e9338d Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 15 Feb 2024 12:40:34 -0800 Subject: [PATCH 02/14] more tests --- .../darwin/Classes/InAppPurchasePlugin.m | 2 +- .../RunnerTests/InAppPurchasePluginTests.m | 53 ++++++------------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index 7958b57f135..2198f76507e 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -301,7 +301,7 @@ - (void)stopObservingPaymentQueueWithError:(FlutterError * _Nullable __autorelea - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties completion:(nonnull void (^)(FlutterError * _Nullable))completion { SKReceiptRefreshRequest *request; if (receiptProperties) { - // This call is for testing + // if recieptProperties is not null, this call is for testing. NSMutableDictionary *properties = [NSMutableDictionary new]; properties[SKReceiptPropertyIsExpired] = receiptProperties[@"isExpired"]; properties[SKReceiptPropertyIsRevoked] = receiptProperties[@"isRevoked"]; diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index fc0311b2a71..eade421ec0f 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -294,54 +294,35 @@ - (void)testRetrieveReceiptDataSuccess { - (void)testRetrieveReceiptDataNil { NSBundle *mockBundle = OCMPartialMock([NSBundle mainBundle]); OCMStub(mockBundle.appStoreReceiptURL).andReturn(nil); -// XCTestExpectation *expectation = [self expectationWithDescription:@"nil receipt data retrieved"]; -// FlutterMethodCall *call = [FlutterMethodCall -// methodCallWithMethodName:@"-[InAppPurchasePlugin retrieveReceiptData:result:]" -// arguments:nil]; - __block NSDictionary *result; - [self.plugin handleMethodCall:call - result:^(id r) { - result = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; + FlutterError *error; + id result = [self.plugin retrieveReceiptDataWithError:&error]; XCTAssertNil(result); } - (void)testRetrieveReceiptDataError { - XCTestExpectation *expectation = [self expectationWithDescription:@"receipt data retrieved"]; - FlutterMethodCall *call = [FlutterMethodCall - methodCallWithMethodName:@"-[InAppPurchasePlugin retrieveReceiptData:result:]" - arguments:nil]; - __block NSDictionary *result; self.receiptManagerStub.returnError = YES; - [self.plugin handleMethodCall:call - result:^(id r) { - result = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertNotNil(result); - XCTAssert([result isKindOfClass:[FlutterError class]]); - NSDictionary *details = ((FlutterError *)result).details; + + FlutterError *error; + id result = [self.plugin retrieveReceiptDataWithError:&error]; + + XCTAssertNil(result); + XCTAssertNotNil(error); + NSDictionary *details = error.details; XCTAssertNotNil(details[@"error"]); NSNumber *errorCode = (NSNumber *)details[@"error"][@"code"]; XCTAssertEqual(errorCode, [NSNumber numberWithInteger:99]); } - (void)testRefreshReceiptRequest { - XCTestExpectation *expectation = [self expectationWithDescription:@"expect success"]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin refreshReceipt:result:]" - arguments:nil]; - __block BOOL result = NO; - [self.plugin handleMethodCall:call - result:^(id r) { - result = YES; - [expectation fulfill]; - }]; + XCTestExpectation *expectation = + [self expectationWithDescription:@"completion handler successfully called"]; + FlutterError *error; + [self.plugin + refreshReceiptReceiptProperties:nil + completion:^(FlutterError *_Nullable error) { + [expectation fulfill]; + }]; [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertTrue(result); } - (void)testPresentCodeRedemptionSheet { From 08cba31be4fd16b9990bc5e4fb87c9125245c858 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 15 Feb 2024 15:05:35 -0800 Subject: [PATCH 03/14] finished native tests --- .../RunnerTests/InAppPurchasePluginTests.m | 76 +++++-------------- .../sk_methodchannel_apis_test.dart | 2 +- 2 files changed, 21 insertions(+), 57 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index eade421ec0f..98eae2b1740 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -326,19 +326,13 @@ - (void)testRefreshReceiptRequest { } - (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); + FIAPaymentQueueHandler *mockHandler = OCMClassMock([FIAPaymentQueueHandler class]); + self.plugin.paymentQueueHandler = mockHandler; + + FlutterError *error; + [self.plugin presentCodeRedemptionSheetWithError:&error]; + + OCMVerify(times(1), [mockHandler presentCodeRedemptionSheet]); } - (void)testGetPendingTransactions { @@ -378,48 +372,28 @@ - (void)testGetPendingTransactions { } - (void)testStartObservingPaymentQueue { - XCTestExpectation *expectation = - [self expectationWithDescription:@"Should return success result"]; - FlutterMethodCall *startCall = [FlutterMethodCall - methodCallWithMethodName:@"-[SKPaymentQueue startObservingTransactionQueue]" - arguments:nil]; FIAPaymentQueueHandler *mockHandler = OCMClassMock([FIAPaymentQueueHandler class]); self.plugin.paymentQueueHandler = mockHandler; - [self.plugin handleMethodCall:startCall - result:^(id _Nullable result) { - XCTAssertNil(result); - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; + FlutterError *error; + [self.plugin startObservingPaymentQueueWithError:&error]; + OCMVerify(times(1), [mockHandler startObservingPaymentQueue]); } - (void)testStopObservingPaymentQueue { - XCTestExpectation *expectation = - [self expectationWithDescription:@"Should return success result"]; - FlutterMethodCall *stopCall = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue stopObservingTransactionQueue]" - arguments:nil]; FIAPaymentQueueHandler *mockHandler = OCMClassMock([FIAPaymentQueueHandler class]); self.plugin.paymentQueueHandler = mockHandler; - [self.plugin handleMethodCall:stopCall - result:^(id _Nullable result) { - XCTAssertNil(result); - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; + FlutterError *error; + [self.plugin stopObservingPaymentQueueWithError:&error]; + OCMVerify(times(1), [mockHandler stopObservingPaymentQueue]); } #if TARGET_OS_IOS - (void)testRegisterPaymentQueueDelegate { if (@available(iOS 13, *)) { - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue registerDelegate]" - arguments:nil]; - self.plugin.paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueueStub new] transactionsUpdated:nil @@ -433,9 +407,8 @@ - (void)testRegisterPaymentQueueDelegate { // Verify the delegate is nil before we register one. XCTAssertNil(self.plugin.paymentQueueHandler.delegate); - [self.plugin handleMethodCall:call - result:^(id r){ - }]; + FlutterError *error; + [self.plugin registerPaymentQueueDelegateWithError:&error]; // Verify the delegate is not nil after we registered one. XCTAssertNotNil(self.plugin.paymentQueueHandler.delegate); @@ -445,10 +418,6 @@ - (void)testRegisterPaymentQueueDelegate { - (void)testRemovePaymentQueueDelegate { if (@available(iOS 13, *)) { - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue removeDelegate]" - arguments:nil]; - self.plugin.paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueueStub new] transactionsUpdated:nil @@ -463,9 +432,8 @@ - (void)testRemovePaymentQueueDelegate { // Verify the delegate is not nil before removing it. XCTAssertNotNil(self.plugin.paymentQueueHandler.delegate); - [self.plugin handleMethodCall:call - result:^(id r){ - }]; + FlutterError *error; + [self.plugin removePaymentQueueDelegateWithError:&error]; // Verify the delegate is nill after removing it. XCTAssertNil(self.plugin.paymentQueueHandler.delegate); @@ -474,16 +442,12 @@ - (void)testRemovePaymentQueueDelegate { #if TARGET_OS_IOS - (void)testShowPriceConsentIfNeeded { - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue showPriceConsentIfNeeded]" - arguments:nil]; - FIAPaymentQueueHandler *mockQueueHandler = OCMClassMock(FIAPaymentQueueHandler.class); self.plugin.paymentQueueHandler = mockQueueHandler; - [self.plugin handleMethodCall:call - result:^(id r){ - }]; + FlutterError *error; + [self.plugin showPriceConsentIfNeededWithError:&error]; + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpartial-availability" 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 411978a7684..90dddbdd9f5 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 @@ -333,7 +333,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override Future refreshReceipt({Map? receiptProperties}) { - // TODO: implement refreshReceipt + print("refreshReceipt"); throw UnimplementedError(); } From 9a3b25dce475929b8bcba1ea93f0d15884cca524 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Thu, 15 Feb 2024 15:51:15 -0800 Subject: [PATCH 04/14] tests --- .../darwin/Classes/InAppPurchasePlugin.m | 3 --- .../test/fakes/fake_storekit_platform.dart | 17 +++++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index 2198f76507e..0d43cb31ced 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -86,9 +86,6 @@ - (instancetype)initWithRegistrar:(NSObject *)registrar binaryMessenger:[registrar messenger]]; return self; } -- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - result(FlutterMethodNotImplemented); -} - (nullable NSNumber *)canMakePaymentsWithError: (FlutterError *_Nullable __autoreleasing *_Nonnull)error { 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 b338e492e73..6d0c4ded542 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 @@ -122,12 +122,6 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { Future onMethodCall(MethodCall call) { switch (call.method) { - case '-[InAppPurchasePlugin retrieveReceiptData:result:]': - if (receiptData != null) { - return Future.value(receiptData!); - } else { - throw PlatformException(code: 'no_receipt_data'); - } case '-[InAppPurchasePlugin refreshReceipt:result:]': receiptData = 'refreshed receipt data'; return Future.sync(() {}); @@ -249,8 +243,8 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override Future refreshReceipt({Map? receiptProperties}) { - // TODO: implement refreshReceipt - throw UnimplementedError(); + receiptData = 'refreshed receipt data'; + return Future.sync(() {}); } @override @@ -265,8 +259,11 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override String retrieveReceiptData() { - // TODO: implement retrieveReceiptData - throw UnimplementedError(); + if (receiptData != null) { + return receiptData!; + } else { + throw PlatformException(code: 'no_receipt_data'); + } } @override From ca49642a6eb42dd01f85f496a75c533ac63de3a6 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 13:17:40 -0800 Subject: [PATCH 05/14] tests passing --- .../sk_receipt_manager.dart | 1 - .../store_kit_wrappers/sk_request_maker.dart | 1 - .../sk_methodchannel_apis_test.dart | 63 ++------- .../sk_payment_queue_delegate_api_test.dart | 130 +++++++++++++++--- 4 files changed, 122 insertions(+), 73 deletions(-) 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 d61062bfd2b..b8844b445f3 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,7 +4,6 @@ import 'dart:async'; -import '../channel.dart'; import '../messages.g.dart'; InAppPurchaseAPI _hostApi = InAppPurchaseAPI(); 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 564a4306238..5a16f261cdd 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,7 +6,6 @@ import 'dart:async'; import 'package:flutter/services.dart'; -import '../channel.dart'; import '../messages.g.dart'; import 'sk_product_wrapper.dart'; 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 90dddbdd9f5..68d202255c3 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,7 +4,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:in_app_purchase_storekit/src/channel.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'; @@ -17,9 +16,6 @@ void main() { setUpAll(() { TestInAppPurchaseApi.setup(fakeStoreKitPlatform); - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler( - SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); }); setUp(() {}); @@ -192,10 +188,6 @@ void main() { } class FakeStoreKitPlatform implements TestInAppPurchaseApi { - FakeStoreKitPlatform() { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(channel, onMethodCall); - } // get product request List startProductRequestParam = []; bool getProductRequestFailTest = false; @@ -225,39 +217,6 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { // Listen to purchase updates bool? queueIsActive; - Future onMethodCall(MethodCall call) { - switch (call.method) { - // request makers - case '-[InAppPurchasePlugin refreshReceipt:result:]': - refreshReceiptCount++; - refreshReceiptParam = Map.castFrom( - call.arguments as Map); - return Future.sync(() {}); - // receipt manager - case '-[InAppPurchasePlugin retrieveReceiptData:result:]': - if (getReceiptFailTest) { - throw Exception('some arbitrary error'); - } - return Future.value('receipt data'); - case '-[SKPaymentQueue startObservingTransactionQueue]': - queueIsActive = true; - return Future.sync(() {}); - case '-[SKPaymentQueue stopObservingTransactionQueue]': - queueIsActive = false; - return Future.sync(() {}); - case '-[SKPaymentQueue registerDelegate]': - isPaymentQueueDelegateRegistered = true; - return Future.sync(() {}); - case '-[SKPaymentQueue removeDelegate]': - isPaymentQueueDelegateRegistered = false; - return Future.sync(() {}); - case '-[SKPaymentQueue showPriceConsentIfNeeded]': - showPriceConsent = true; - return Future.sync(() {}); - } - return Future.error('method not mocked'); - } - @override void addPayment(Map paymentMap) { payments @@ -307,39 +266,43 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override void registerPaymentQueueDelegate() { - // TODO: implement registerPaymentQueueDelegate + isPaymentQueueDelegateRegistered = true; } @override void removePaymentQueueDelegate() { - // TODO: implement removePaymentQueueDelegate + isPaymentQueueDelegateRegistered = false; } @override void startObservingPaymentQueue() { - // TODO: implement startObservingPaymentQueue + queueIsActive = true; } @override void stopObservingPaymentQueue() { - // TODO: implement stopObservingPaymentQueue + queueIsActive = false; } @override String retrieveReceiptData() { - // TODO: implement retrieveReceiptData - throw UnimplementedError(); + if (getReceiptFailTest) { + throw Exception('some arbitrary error'); + } + return 'receipt data'; } @override Future refreshReceipt({Map? receiptProperties}) { - print("refreshReceipt"); - throw UnimplementedError(); + refreshReceiptCount++; + refreshReceiptParam = Map.castFrom( + receiptProperties! as Map); + return Future.sync(() {}); } @override void showPriceConsentIfNeeded() { - // TODO: implement showPriceConsentIfNeeded + showPriceConsent = true; } } 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 6c23da9cb49..1925e6e4b0f 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 @@ -5,14 +5,21 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_storekit/src/channel.dart'; +import 'package:in_app_purchase_storekit/src/messages.g.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(); final FakeStoreKitPlatform fakeStoreKitPlatform = FakeStoreKitPlatform(); + setUpAll(() { + TestInAppPurchaseApi.setup(fakeStoreKitPlatform); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); @@ -147,24 +154,105 @@ class TestPaymentQueueDelegate extends SKPaymentQueueDelegateWrapper { } } -class FakeStoreKitPlatform { - FakeStoreKitPlatform() { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(channel, onMethodCall); - } - - // indicate if the payment queue delegate is registered - bool isPaymentQueueDelegateRegistered = false; - - Future onMethodCall(MethodCall call) { - switch (call.method) { - case '-[SKPaymentQueue registerDelegate]': - isPaymentQueueDelegateRegistered = true; - return Future.sync(() {}); - case '-[SKPaymentQueue removeDelegate]': - isPaymentQueueDelegateRegistered = false; - return Future.sync(() {}); - } - return Future.error('method not mocked'); - } -} +// class FakeStoreKitPlatform implements TestInAppPurchaseApi { +// FakeStoreKitPlatform() { +// TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger +// .setMockMethodCallHandler(channel, onMethodCall); +// } +// +// // indicate if the payment queue delegate is registered +// bool isPaymentQueueDelegateRegistered = false; +// +// Future onMethodCall(MethodCall call) { +// switch (call.method) { +// case '-[SKPaymentQueue registerDelegate]': +// isPaymentQueueDelegateRegistered = true; +// return Future.sync(() {}); +// case '-[SKPaymentQueue removeDelegate]': +// isPaymentQueueDelegateRegistered = false; +// return Future.sync(() {}); +// } +// return Future.error('method not mocked'); +// } +// +// @override +// void addPayment(Map paymentMap) { +// // TODO: implement addPayment +// } +// +// @override +// bool canMakePayments() { +// // TODO: implement canMakePayments +// throw UnimplementedError(); +// } +// +// @override +// void finishTransaction(Map finishMap) { +// // TODO: implement finishTransaction +// } +// +// @override +// void presentCodeRedemptionSheet() { +// // TODO: implement presentCodeRedemptionSheet +// } +// +// @override +// Future refreshReceipt({Map? receiptProperties}) { +// // TODO: implement refreshReceipt +// throw UnimplementedError(); +// } +// +// @override +// void registerPaymentQueueDelegate() { +// // TODO: implement registerPaymentQueueDelegate +// } +// +// @override +// void removePaymentQueueDelegate() { +// // TODO: implement removePaymentQueueDelegate +// } +// +// @override +// void restoreTransactions(String? applicationUserName) { +// // TODO: implement restoreTransactions +// } +// +// @override +// String retrieveReceiptData() { +// // TODO: implement retrieveReceiptData +// throw UnimplementedError(); +// } +// +// @override +// void showPriceConsentIfNeeded() { +// // TODO: implement showPriceConsentIfNeeded +// } +// +// @override +// void startObservingPaymentQueue() { +// // TODO: implement startObservingPaymentQueue +// } +// +// @override +// Future startProductRequest(List productIdentifiers) { +// // TODO: implement startProductRequest +// throw UnimplementedError(); +// } +// +// @override +// void stopObservingPaymentQueue() { +// // TODO: implement stopObservingPaymentQueue +// } +// +// @override +// SKStorefrontMessage storefront() { +// // TODO: implement storefront +// throw UnimplementedError(); +// } +// +// @override +// List transactions() { +// // TODO: implement transactions +// throw UnimplementedError(); +// } +// } From bff4b77c19720d10025af141315e16d804e5cf49 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 13:41:56 -0800 Subject: [PATCH 06/14] removing a bunch of unused code --- .../RunnerTests/InAppPurchasePluginTests.m | 1 - .../pigeons/messages.dart | 2 +- .../test/fakes/fake_storekit_platform.dart | 29 ++--- ...rchase_storekit_platform_addtion_test.dart | 4 - ...n_app_purchase_storekit_platform_test.dart | 6 +- .../sk_payment_queue_delegate_api_test.dart | 109 ------------------ 6 files changed, 12 insertions(+), 139 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index 98eae2b1740..acc59c1e6c7 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -316,7 +316,6 @@ - (void)testRetrieveReceiptDataError { - (void)testRefreshReceiptRequest { XCTestExpectation *expectation = [self expectationWithDescription:@"completion handler successfully called"]; - FlutterError *error; [self.plugin refreshReceiptReceiptProperties:nil completion:^(FlutterError *_Nullable error) { 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 929bfa0f444..8b8fb90c965 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 @@ -244,7 +244,7 @@ abstract class InAppPurchaseAPI { void presentCodeRedemptionSheet(); - String retrieveReceiptData(); + String? retrieveReceiptData(); @async void refreshReceipt({Map? receiptProperties}); 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 6d0c4ded542..a25055cc2f2 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 @@ -5,7 +5,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart'; -import 'package:in_app_purchase_storekit/src/channel.dart'; import 'package:in_app_purchase_storekit/src/messages.g.dart'; import 'package:in_app_purchase_storekit/store_kit_wrappers.dart'; @@ -14,8 +13,8 @@ import '../test_api.g.dart'; class FakeStoreKitPlatform implements TestInAppPurchaseApi { FakeStoreKitPlatform() { - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler(channel, onMethodCall); + // TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + // .setMockMethodCallHandler(channel, onMethodCall); } // pre-configured store information @@ -32,6 +31,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { SKError? testRestoredError; bool queueIsActive = false; Map discountReceived = {}; + bool isPaymentQueueDelegateRegistered = false; void reset() { transactionList = []; @@ -57,6 +57,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { testRestoredError = null; queueIsActive = false; discountReceived = {}; + isPaymentQueueDelegateRegistered = false; } SKPaymentTransactionWrapper createPendingTransaction(String id, @@ -120,19 +121,6 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { transactionIdentifier: transactionId); } - Future onMethodCall(MethodCall call) { - switch (call.method) { - case '-[InAppPurchasePlugin refreshReceipt:result:]': - receiptData = 'refreshed receipt data'; - return Future.sync(() {}); - case '-[SKPaymentQueue startObservingTransactionQueue]': - queueIsActive = true; - case '-[SKPaymentQueue stopObservingTransactionQueue]': - queueIsActive = false; - } - return Future.sync(() {}); - } - @override bool canMakePayments() { return true; @@ -249,12 +237,12 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override void registerPaymentQueueDelegate() { - // TODO: implement registerPaymentQueueDelegate + isPaymentQueueDelegateRegistered = true; } @override void removePaymentQueueDelegate() { - // TODO: implement removePaymentQueueDelegate + isPaymentQueueDelegateRegistered = false; } @override @@ -268,16 +256,15 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override void showPriceConsentIfNeeded() { - // TODO: implement showPriceConsentIfNeeded } @override void startObservingPaymentQueue() { - // TODO: implement startObservingPaymentQueue + queueIsActive = true; } @override void stopObservingPaymentQueue() { - // TODO: implement stopObservingPaymentQueue + queueIsActive = false; } } 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 99fd49d03a3..40068db75a7 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 @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -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'; @@ -17,9 +16,6 @@ void main() { setUpAll(() { TestInAppPurchaseApi.setup(fakeStoreKitPlatform); - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler( - SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); }); 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 278a6918446..d5170d26317 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 @@ -23,9 +23,9 @@ void main() { setUpAll(() { TestInAppPurchaseApi.setup(fakeStoreKitPlatform); - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler( - SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); + // TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + // .setMockMethodCallHandler( + // SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); }); setUp(() { 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 1925e6e4b0f..a83c66cf79e 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,8 +4,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:in_app_purchase_storekit/src/channel.dart'; -import 'package:in_app_purchase_storekit/src/messages.g.dart'; import 'package:in_app_purchase_storekit/store_kit_wrappers.dart'; import '../fakes/fake_storekit_platform.dart'; @@ -19,10 +17,6 @@ void main() { setUpAll(() { TestInAppPurchaseApi.setup(fakeStoreKitPlatform); - - TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - .setMockMethodCallHandler( - SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); }); test( @@ -153,106 +147,3 @@ class TestPaymentQueueDelegate extends SKPaymentQueueDelegateWrapper { return false; } } - -// class FakeStoreKitPlatform implements TestInAppPurchaseApi { -// FakeStoreKitPlatform() { -// TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger -// .setMockMethodCallHandler(channel, onMethodCall); -// } -// -// // indicate if the payment queue delegate is registered -// bool isPaymentQueueDelegateRegistered = false; -// -// Future onMethodCall(MethodCall call) { -// switch (call.method) { -// case '-[SKPaymentQueue registerDelegate]': -// isPaymentQueueDelegateRegistered = true; -// return Future.sync(() {}); -// case '-[SKPaymentQueue removeDelegate]': -// isPaymentQueueDelegateRegistered = false; -// return Future.sync(() {}); -// } -// return Future.error('method not mocked'); -// } -// -// @override -// void addPayment(Map paymentMap) { -// // TODO: implement addPayment -// } -// -// @override -// bool canMakePayments() { -// // TODO: implement canMakePayments -// throw UnimplementedError(); -// } -// -// @override -// void finishTransaction(Map finishMap) { -// // TODO: implement finishTransaction -// } -// -// @override -// void presentCodeRedemptionSheet() { -// // TODO: implement presentCodeRedemptionSheet -// } -// -// @override -// Future refreshReceipt({Map? receiptProperties}) { -// // TODO: implement refreshReceipt -// throw UnimplementedError(); -// } -// -// @override -// void registerPaymentQueueDelegate() { -// // TODO: implement registerPaymentQueueDelegate -// } -// -// @override -// void removePaymentQueueDelegate() { -// // TODO: implement removePaymentQueueDelegate -// } -// -// @override -// void restoreTransactions(String? applicationUserName) { -// // TODO: implement restoreTransactions -// } -// -// @override -// String retrieveReceiptData() { -// // TODO: implement retrieveReceiptData -// throw UnimplementedError(); -// } -// -// @override -// void showPriceConsentIfNeeded() { -// // TODO: implement showPriceConsentIfNeeded -// } -// -// @override -// void startObservingPaymentQueue() { -// // TODO: implement startObservingPaymentQueue -// } -// -// @override -// Future startProductRequest(List productIdentifiers) { -// // TODO: implement startProductRequest -// throw UnimplementedError(); -// } -// -// @override -// void stopObservingPaymentQueue() { -// // TODO: implement stopObservingPaymentQueue -// } -// -// @override -// SKStorefrontMessage storefront() { -// // TODO: implement storefront -// throw UnimplementedError(); -// } -// -// @override -// List transactions() { -// // TODO: implement transactions -// throw UnimplementedError(); -// } -// } From c38d2f3c78a107796a6ab65f73f4b2204af4a4da Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 13:51:33 -0800 Subject: [PATCH 07/14] specify ios only test --- .../example/shared/RunnerTests/InAppPurchasePluginTests.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index acc59c1e6c7..4f1da0798e7 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -324,6 +324,7 @@ - (void)testRefreshReceiptRequest { [self waitForExpectations:@[ expectation ] timeout:5]; } +#if TARGET_OS_IOS - (void)testPresentCodeRedemptionSheet { FIAPaymentQueueHandler *mockHandler = OCMClassMock([FIAPaymentQueueHandler class]); self.plugin.paymentQueueHandler = mockHandler; @@ -333,6 +334,7 @@ - (void)testPresentCodeRedemptionSheet { OCMVerify(times(1), [mockHandler presentCodeRedemptionSheet]); } +#endif - (void)testGetPendingTransactions { SKPaymentQueue *mockQueue = OCMClassMock(SKPaymentQueue.class); From e6d10545918d681f6feb79db94191afa6e57f33b Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 14:35:03 -0800 Subject: [PATCH 08/14] format, pubspec, and copyright --- .../in_app_purchase_storekit/CHANGELOG.md | 4 + .../darwin/Classes/InAppPurchasePlugin.m | 25 +- .../darwin/Classes/messages.g.h | 193 +++++----- .../darwin/Classes/messages.g.m | 356 ++++++++++-------- .../xcshareddata/xcschemes/Runner.xcscheme | 3 +- .../RunnerTests/InAppPurchasePluginTests.m | 14 +- .../lib/src/messages.g.dart | 173 +++++---- .../sk_payment_queue_wrapper.dart | 6 +- .../sk_receipt_manager.dart | 3 +- .../pigeons/copyright.txt | 3 + .../in_app_purchase_storekit/pubspec.yaml | 2 +- .../test/fakes/fake_storekit_platform.dart | 3 +- .../sk_payment_queue_delegate_api_test.dart | 1 - .../test/test_api.g.dart | 337 +++++++++++------ 14 files changed, 676 insertions(+), 447 deletions(-) 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 67ff21186e7..583269b6b60 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.3.11 + +* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`, `registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon. + ## 0.3.10 * Converts `startProductRequest()`, `finishTransaction()`, `restoreTransactions()`, `presentCodeRedemptionSheet()` to pigeon. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index 0d43cb31ced..f38cc27030d 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -246,7 +246,8 @@ - (void)presentCodeRedemptionSheetWithError: #endif } -- (void)registerPaymentQueueDelegateWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +- (void)registerPaymentQueueDelegateWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { #if TARGET_OS_IOS if (@available(iOS 13.0, *)) { _paymentQueueDelegateCallbackChannel = [FlutterMethodChannel @@ -260,7 +261,8 @@ - (void)registerPaymentQueueDelegateWithError:(FlutterError * _Nullable __autore #endif } -- (void)removePaymentQueueDelegateWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +- (void)removePaymentQueueDelegateWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { if (@available(iOS 13.0, *)) { _paymentQueueHandler.delegate = nil; } @@ -268,8 +270,8 @@ - (void)removePaymentQueueDelegateWithError:(FlutterError * _Nullable __autorele _paymentQueueDelegateCallbackChannel = nil; } - -- (NSString * _Nullable)retrieveReceiptDataWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +- (NSString *_Nullable)retrieveReceiptDataWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { FlutterError *flutterError; NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&flutterError]; if (flutterError) { @@ -279,7 +281,7 @@ - (NSString * _Nullable)retrieveReceiptDataWithError:(FlutterError * _Nullable _ return receiptData; } -- (void)showPriceConsentIfNeededWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { #if TARGET_OS_IOS if (@available(iOS 13.4, *)) { [_paymentQueueHandler showPriceConsentIfNeeded]; @@ -287,15 +289,18 @@ - (void)showPriceConsentIfNeededWithError:(FlutterError * _Nullable __autoreleas #endif } -- (void)startObservingPaymentQueueWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +- (void)startObservingPaymentQueueWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { [_paymentQueueHandler startObservingPaymentQueue]; } -- (void)stopObservingPaymentQueueWithError:(FlutterError * _Nullable __autoreleasing * _Nonnull)error { +- (void)stopObservingPaymentQueueWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { [_paymentQueueHandler stopObservingPaymentQueue]; } -- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties completion:(nonnull void (^)(FlutterError * _Nullable))completion { +- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties + completion:(nonnull void (^)(FlutterError *_Nullable))completion { SKReceiptRefreshRequest *request; if (receiptProperties) { // if recieptProperties is not null, this call is for testing. @@ -316,8 +321,8 @@ - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperti FlutterError *requestError; if (error) { requestError = [FlutterError errorWithCode:@"storekit_refreshreceiptrequest_platform_error" - message:error.localizedDescription - details:error.description]; + message:error.localizedDescription + details:error.description]; completion(requestError); } completion(nil); diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h index 2befbf60501..b2acba8fc1b 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.h @@ -1,3 +1,6 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // Autogenerated from Pigeon (v16.0.4), do not edit directly. // See also: https://pub.dev/packages/pigeon @@ -64,7 +67,8 @@ typedef NS_ENUM(NSUInteger, SKProductDiscountTypeMessage) { typedef NS_ENUM(NSUInteger, SKProductDiscountPaymentModeMessage) { /// Allows user to pay the discounted price at each payment period. SKProductDiscountPaymentModeMessagePayAsYouGo = 0, - /// Allows user to pay the discounted price upfront and receive the product for the rest of time that was paid for. + /// Allows user to pay the discounted price upfront and receive the product for the rest of time + /// that was paid for. SKProductDiscountPaymentModeMessagePayUpFront = 1, /// User pays nothing during the discounted period. SKProductDiscountPaymentModeMessageFreeTrial = 2, @@ -106,140 +110,140 @@ typedef NS_ENUM(NSUInteger, SKSubscriptionPeriodUnitMessage) { /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithPayment:(SKPaymentMessage *)payment - transactionState:(SKPaymentTransactionStateMessage)transactionState - originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction - transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp - transactionIdentifier:(nullable NSString *)transactionIdentifier - error:(nullable SKErrorMessage *)error; -@property(nonatomic, strong) SKPaymentMessage * payment; + transactionState:(SKPaymentTransactionStateMessage)transactionState + originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction + transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp + transactionIdentifier:(nullable NSString *)transactionIdentifier + error:(nullable SKErrorMessage *)error; +@property(nonatomic, strong) SKPaymentMessage *payment; @property(nonatomic, assign) SKPaymentTransactionStateMessage transactionState; -@property(nonatomic, strong, nullable) SKPaymentTransactionMessage * originalTransaction; -@property(nonatomic, strong, nullable) NSNumber * transactionTimeStamp; -@property(nonatomic, copy, nullable) NSString * transactionIdentifier; -@property(nonatomic, strong, nullable) SKErrorMessage * error; +@property(nonatomic, strong, nullable) SKPaymentTransactionMessage *originalTransaction; +@property(nonatomic, strong, nullable) NSNumber *transactionTimeStamp; +@property(nonatomic, copy, nullable) NSString *transactionIdentifier; +@property(nonatomic, strong, nullable) SKErrorMessage *error; @end @interface SKPaymentMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - applicationUsername:(nullable NSString *)applicationUsername - requestData:(nullable NSString *)requestData - quantity:(NSInteger )quantity - simulatesAskToBuyInSandbox:(BOOL )simulatesAskToBuyInSandbox - paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount; -@property(nonatomic, copy) NSString * productIdentifier; -@property(nonatomic, copy, nullable) NSString * applicationUsername; -@property(nonatomic, copy, nullable) NSString * requestData; -@property(nonatomic, assign) NSInteger quantity; -@property(nonatomic, assign) BOOL simulatesAskToBuyInSandbox; -@property(nonatomic, strong, nullable) SKPaymentDiscountMessage * paymentDiscount; + applicationUsername:(nullable NSString *)applicationUsername + requestData:(nullable NSString *)requestData + quantity:(NSInteger)quantity + simulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox + paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount; +@property(nonatomic, copy) NSString *productIdentifier; +@property(nonatomic, copy, nullable) NSString *applicationUsername; +@property(nonatomic, copy, nullable) NSString *requestData; +@property(nonatomic, assign) NSInteger quantity; +@property(nonatomic, assign) BOOL simulatesAskToBuyInSandbox; +@property(nonatomic, strong, nullable) SKPaymentDiscountMessage *paymentDiscount; @end @interface SKErrorMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithCode:(NSInteger )code - domain:(NSString *)domain - userInfo:(NSDictionary *)userInfo; -@property(nonatomic, assign) NSInteger code; -@property(nonatomic, copy) NSString * domain; -@property(nonatomic, copy) NSDictionary * userInfo; ++ (instancetype)makeWithCode:(NSInteger)code + domain:(NSString *)domain + userInfo:(NSDictionary *)userInfo; +@property(nonatomic, assign) NSInteger code; +@property(nonatomic, copy) NSString *domain; +@property(nonatomic, copy) NSDictionary *userInfo; @end @interface SKPaymentDiscountMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithIdentifier:(NSString *)identifier - keyIdentifier:(NSString *)keyIdentifier - nonce:(NSString *)nonce - signature:(NSString *)signature - timestamp:(NSInteger )timestamp; -@property(nonatomic, copy) NSString * identifier; -@property(nonatomic, copy) NSString * keyIdentifier; -@property(nonatomic, copy) NSString * nonce; -@property(nonatomic, copy) NSString * signature; -@property(nonatomic, assign) NSInteger timestamp; + keyIdentifier:(NSString *)keyIdentifier + nonce:(NSString *)nonce + signature:(NSString *)signature + timestamp:(NSInteger)timestamp; +@property(nonatomic, copy) NSString *identifier; +@property(nonatomic, copy) NSString *keyIdentifier; +@property(nonatomic, copy) NSString *nonce; +@property(nonatomic, copy) NSString *signature; +@property(nonatomic, assign) NSInteger timestamp; @end @interface SKStorefrontMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithCountryCode:(NSString *)countryCode - identifier:(NSString *)identifier; -@property(nonatomic, copy) NSString * countryCode; -@property(nonatomic, copy) NSString * identifier; ++ (instancetype)makeWithCountryCode:(NSString *)countryCode identifier:(NSString *)identifier; +@property(nonatomic, copy) NSString *countryCode; +@property(nonatomic, copy) NSString *identifier; @end @interface SKProductsResponseMessage : NSObject + (instancetype)makeWithProducts:(nullable NSArray *)products - invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers; -@property(nonatomic, copy, nullable) NSArray * products; -@property(nonatomic, copy, nullable) NSArray * invalidProductIdentifiers; + invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers; +@property(nonatomic, copy, nullable) NSArray *products; +@property(nonatomic, copy, nullable) NSArray *invalidProductIdentifiers; @end @interface SKProductMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - localizedTitle:(NSString *)localizedTitle - localizedDescription:(NSString *)localizedDescription - priceLocale:(SKPriceLocaleMessage *)priceLocale - subscriptionGroupIdentifier:(nullable NSString *)subscriptionGroupIdentifier - price:(NSString *)price - subscriptionPeriod:(nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod - introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice - discounts:(nullable NSArray *)discounts; -@property(nonatomic, copy) NSString * productIdentifier; -@property(nonatomic, copy) NSString * localizedTitle; -@property(nonatomic, copy) NSString * localizedDescription; -@property(nonatomic, strong) SKPriceLocaleMessage * priceLocale; -@property(nonatomic, copy, nullable) NSString * subscriptionGroupIdentifier; -@property(nonatomic, copy) NSString * price; -@property(nonatomic, strong, nullable) SKProductSubscriptionPeriodMessage * subscriptionPeriod; -@property(nonatomic, strong, nullable) SKProductDiscountMessage * introductoryPrice; -@property(nonatomic, copy, nullable) NSArray * discounts; + localizedTitle:(NSString *)localizedTitle + localizedDescription:(NSString *)localizedDescription + priceLocale:(SKPriceLocaleMessage *)priceLocale + subscriptionGroupIdentifier:(nullable NSString *)subscriptionGroupIdentifier + price:(NSString *)price + subscriptionPeriod: + (nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod + introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice + discounts:(nullable NSArray *)discounts; +@property(nonatomic, copy) NSString *productIdentifier; +@property(nonatomic, copy) NSString *localizedTitle; +@property(nonatomic, copy) NSString *localizedDescription; +@property(nonatomic, strong) SKPriceLocaleMessage *priceLocale; +@property(nonatomic, copy, nullable) NSString *subscriptionGroupIdentifier; +@property(nonatomic, copy) NSString *price; +@property(nonatomic, strong, nullable) SKProductSubscriptionPeriodMessage *subscriptionPeriod; +@property(nonatomic, strong, nullable) SKProductDiscountMessage *introductoryPrice; +@property(nonatomic, copy, nullable) NSArray *discounts; @end @interface SKPriceLocaleMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithCurrencySymbol:(NSString *)currencySymbol - currencyCode:(NSString *)currencyCode - countryCode:(NSString *)countryCode; -///The currency symbol for the locale, e.g. $ for US locale. -@property(nonatomic, copy) NSString * currencySymbol; -///The currency code for the locale, e.g. USD for US locale. -@property(nonatomic, copy) NSString * currencyCode; -///The country code for the locale, e.g. US for US locale. -@property(nonatomic, copy) NSString * countryCode; + currencyCode:(NSString *)currencyCode + countryCode:(NSString *)countryCode; +/// The currency symbol for the locale, e.g. $ for US locale. +@property(nonatomic, copy) NSString *currencySymbol; +/// The currency code for the locale, e.g. USD for US locale. +@property(nonatomic, copy) NSString *currencyCode; +/// The country code for the locale, e.g. US for US locale. +@property(nonatomic, copy) NSString *countryCode; @end @interface SKProductDiscountMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; + (instancetype)makeWithPrice:(NSString *)price - priceLocale:(SKPriceLocaleMessage *)priceLocale - numberOfPeriods:(NSInteger )numberOfPeriods - paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode - subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod - identifier:(nullable NSString *)identifier - type:(SKProductDiscountTypeMessage)type; -@property(nonatomic, copy) NSString * price; -@property(nonatomic, strong) SKPriceLocaleMessage * priceLocale; -@property(nonatomic, assign) NSInteger numberOfPeriods; + priceLocale:(SKPriceLocaleMessage *)priceLocale + numberOfPeriods:(NSInteger)numberOfPeriods + paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode + subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod + identifier:(nullable NSString *)identifier + type:(SKProductDiscountTypeMessage)type; +@property(nonatomic, copy) NSString *price; +@property(nonatomic, strong) SKPriceLocaleMessage *priceLocale; +@property(nonatomic, assign) NSInteger numberOfPeriods; @property(nonatomic, assign) SKProductDiscountPaymentModeMessage paymentMode; -@property(nonatomic, strong) SKProductSubscriptionPeriodMessage * subscriptionPeriod; -@property(nonatomic, copy, nullable) NSString * identifier; +@property(nonatomic, strong) SKProductSubscriptionPeriodMessage *subscriptionPeriod; +@property(nonatomic, copy, nullable) NSString *identifier; @property(nonatomic, assign) SKProductDiscountTypeMessage type; @end @interface SKProductSubscriptionPeriodMessage : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithNumberOfUnits:(NSInteger )numberOfUnits - unit:(SKSubscriptionPeriodUnitMessage)unit; -@property(nonatomic, assign) NSInteger numberOfUnits; ++ (instancetype)makeWithNumberOfUnits:(NSInteger)numberOfUnits + unit:(SKSubscriptionPeriodUnitMessage)unit; +@property(nonatomic, assign) NSInteger numberOfUnits; @property(nonatomic, assign) SKSubscriptionPeriodUnitMessage unit; @end @@ -252,17 +256,23 @@ NSObject *InAppPurchaseAPIGetCodec(void); /// @return `nil` only when `error != nil`. - (nullable NSNumber *)canMakePaymentsWithError:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. -- (nullable NSArray *)transactionsWithError:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSArray *)transactionsWithError: + (FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. - (nullable SKStorefrontMessage *)storefrontWithError:(FlutterError *_Nullable *_Nonnull)error; -- (void)addPaymentPaymentMap:(NSDictionary *)paymentMap error:(FlutterError *_Nullable *_Nonnull)error; -- (void)startProductRequestProductIdentifiers:(NSArray *)productIdentifiers completion:(void (^)(SKProductsResponseMessage *_Nullable, FlutterError *_Nullable))completion; -- (void)finishTransactionFinishMap:(NSDictionary *)finishMap error:(FlutterError *_Nullable *_Nonnull)error; -- (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName error:(FlutterError *_Nullable *_Nonnull)error; +- (void)addPaymentPaymentMap:(NSDictionary *)paymentMap + error:(FlutterError *_Nullable *_Nonnull)error; +- (void)startProductRequestProductIdentifiers:(NSArray *)productIdentifiers + completion:(void (^)(SKProductsResponseMessage *_Nullable, + FlutterError *_Nullable))completion; +- (void)finishTransactionFinishMap:(NSDictionary *)finishMap + error:(FlutterError *_Nullable *_Nonnull)error; +- (void)restoreTransactionsApplicationUserName:(nullable NSString *)applicationUserName + error:(FlutterError *_Nullable *_Nonnull)error; - (void)presentCodeRedemptionSheetWithError:(FlutterError *_Nullable *_Nonnull)error; -/// @return `nil` only when `error != nil`. - (nullable NSString *)retrieveReceiptDataWithError:(FlutterError *_Nullable *_Nonnull)error; -- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties completion:(void (^)(FlutterError *_Nullable))completion; +- (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties + completion:(void (^)(FlutterError *_Nullable))completion; - (void)startObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)stopObservingPaymentQueueWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)registerPaymentQueueDelegateWithError:(FlutterError *_Nullable *_Nonnull)error; @@ -270,6 +280,7 @@ NSObject *InAppPurchaseAPIGetCodec(void); - (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable *_Nonnull)error; @end -extern void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject *_Nullable api); +extern void SetUpInAppPurchaseAPI(id binaryMessenger, + NSObject *_Nullable api); NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m index 80d6a3d0cf2..c9b20b7a93c 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/messages.g.m @@ -1,3 +1,6 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // Autogenerated from Pigeon (v16.0.4), do not edit directly. // See also: https://pub.dev/packages/pigeon @@ -129,12 +132,12 @@ - (NSArray *)toList; @implementation SKPaymentTransactionMessage + (instancetype)makeWithPayment:(SKPaymentMessage *)payment - transactionState:(SKPaymentTransactionStateMessage)transactionState - originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction - transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp - transactionIdentifier:(nullable NSString *)transactionIdentifier - error:(nullable SKErrorMessage *)error { - SKPaymentTransactionMessage* pigeonResult = [[SKPaymentTransactionMessage alloc] init]; + transactionState:(SKPaymentTransactionStateMessage)transactionState + originalTransaction:(nullable SKPaymentTransactionMessage *)originalTransaction + transactionTimeStamp:(nullable NSNumber *)transactionTimeStamp + transactionIdentifier:(nullable NSString *)transactionIdentifier + error:(nullable SKErrorMessage *)error { + SKPaymentTransactionMessage *pigeonResult = [[SKPaymentTransactionMessage alloc] init]; pigeonResult.payment = payment; pigeonResult.transactionState = transactionState; pigeonResult.originalTransaction = originalTransaction; @@ -147,7 +150,8 @@ + (SKPaymentTransactionMessage *)fromList:(NSArray *)list { SKPaymentTransactionMessage *pigeonResult = [[SKPaymentTransactionMessage alloc] init]; pigeonResult.payment = [SKPaymentMessage nullableFromList:(GetNullableObjectAtIndex(list, 0))]; pigeonResult.transactionState = [GetNullableObjectAtIndex(list, 1) integerValue]; - pigeonResult.originalTransaction = [SKPaymentTransactionMessage nullableFromList:(GetNullableObjectAtIndex(list, 2))]; + pigeonResult.originalTransaction = + [SKPaymentTransactionMessage nullableFromList:(GetNullableObjectAtIndex(list, 2))]; pigeonResult.transactionTimeStamp = GetNullableObjectAtIndex(list, 3); pigeonResult.transactionIdentifier = GetNullableObjectAtIndex(list, 4); pigeonResult.error = [SKErrorMessage nullableFromList:(GetNullableObjectAtIndex(list, 5))]; @@ -170,12 +174,12 @@ - (NSArray *)toList { @implementation SKPaymentMessage + (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - applicationUsername:(nullable NSString *)applicationUsername - requestData:(nullable NSString *)requestData - quantity:(NSInteger )quantity - simulatesAskToBuyInSandbox:(BOOL )simulatesAskToBuyInSandbox - paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount { - SKPaymentMessage* pigeonResult = [[SKPaymentMessage alloc] init]; + applicationUsername:(nullable NSString *)applicationUsername + requestData:(nullable NSString *)requestData + quantity:(NSInteger)quantity + simulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox + paymentDiscount:(nullable SKPaymentDiscountMessage *)paymentDiscount { + SKPaymentMessage *pigeonResult = [[SKPaymentMessage alloc] init]; pigeonResult.productIdentifier = productIdentifier; pigeonResult.applicationUsername = applicationUsername; pigeonResult.requestData = requestData; @@ -191,7 +195,8 @@ + (SKPaymentMessage *)fromList:(NSArray *)list { pigeonResult.requestData = GetNullableObjectAtIndex(list, 2); pigeonResult.quantity = [GetNullableObjectAtIndex(list, 3) integerValue]; pigeonResult.simulatesAskToBuyInSandbox = [GetNullableObjectAtIndex(list, 4) boolValue]; - pigeonResult.paymentDiscount = [SKPaymentDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 5))]; + pigeonResult.paymentDiscount = + [SKPaymentDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 5))]; return pigeonResult; } + (nullable SKPaymentMessage *)nullableFromList:(NSArray *)list { @@ -210,10 +215,10 @@ - (NSArray *)toList { @end @implementation SKErrorMessage -+ (instancetype)makeWithCode:(NSInteger )code - domain:(NSString *)domain - userInfo:(NSDictionary *)userInfo { - SKErrorMessage* pigeonResult = [[SKErrorMessage alloc] init]; ++ (instancetype)makeWithCode:(NSInteger)code + domain:(NSString *)domain + userInfo:(NSDictionary *)userInfo { + SKErrorMessage *pigeonResult = [[SKErrorMessage alloc] init]; pigeonResult.code = code; pigeonResult.domain = domain; pigeonResult.userInfo = userInfo; @@ -240,11 +245,11 @@ - (NSArray *)toList { @implementation SKPaymentDiscountMessage + (instancetype)makeWithIdentifier:(NSString *)identifier - keyIdentifier:(NSString *)keyIdentifier - nonce:(NSString *)nonce - signature:(NSString *)signature - timestamp:(NSInteger )timestamp { - SKPaymentDiscountMessage* pigeonResult = [[SKPaymentDiscountMessage alloc] init]; + keyIdentifier:(NSString *)keyIdentifier + nonce:(NSString *)nonce + signature:(NSString *)signature + timestamp:(NSInteger)timestamp { + SKPaymentDiscountMessage *pigeonResult = [[SKPaymentDiscountMessage alloc] init]; pigeonResult.identifier = identifier; pigeonResult.keyIdentifier = keyIdentifier; pigeonResult.nonce = nonce; @@ -276,9 +281,8 @@ - (NSArray *)toList { @end @implementation SKStorefrontMessage -+ (instancetype)makeWithCountryCode:(NSString *)countryCode - identifier:(NSString *)identifier { - SKStorefrontMessage* pigeonResult = [[SKStorefrontMessage alloc] init]; ++ (instancetype)makeWithCountryCode:(NSString *)countryCode identifier:(NSString *)identifier { + SKStorefrontMessage *pigeonResult = [[SKStorefrontMessage alloc] init]; pigeonResult.countryCode = countryCode; pigeonResult.identifier = identifier; return pigeonResult; @@ -302,8 +306,8 @@ - (NSArray *)toList { @implementation SKProductsResponseMessage + (instancetype)makeWithProducts:(nullable NSArray *)products - invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers { - SKProductsResponseMessage* pigeonResult = [[SKProductsResponseMessage alloc] init]; + invalidProductIdentifiers:(nullable NSArray *)invalidProductIdentifiers { + SKProductsResponseMessage *pigeonResult = [[SKProductsResponseMessage alloc] init]; pigeonResult.products = products; pigeonResult.invalidProductIdentifiers = invalidProductIdentifiers; return pigeonResult; @@ -326,16 +330,17 @@ - (NSArray *)toList { @end @implementation SKProductMessage -+ (instancetype)makeWithProductIdentifier:(NSString *)productIdentifier - localizedTitle:(NSString *)localizedTitle - localizedDescription:(NSString *)localizedDescription - priceLocale:(SKPriceLocaleMessage *)priceLocale ++ (instancetype) + makeWithProductIdentifier:(NSString *)productIdentifier + localizedTitle:(NSString *)localizedTitle + localizedDescription:(NSString *)localizedDescription + priceLocale:(SKPriceLocaleMessage *)priceLocale subscriptionGroupIdentifier:(nullable NSString *)subscriptionGroupIdentifier - price:(NSString *)price - subscriptionPeriod:(nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod - introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice - discounts:(nullable NSArray *)discounts { - SKProductMessage* pigeonResult = [[SKProductMessage alloc] init]; + price:(NSString *)price + subscriptionPeriod:(nullable SKProductSubscriptionPeriodMessage *)subscriptionPeriod + introductoryPrice:(nullable SKProductDiscountMessage *)introductoryPrice + discounts:(nullable NSArray *)discounts { + SKProductMessage *pigeonResult = [[SKProductMessage alloc] init]; pigeonResult.productIdentifier = productIdentifier; pigeonResult.localizedTitle = localizedTitle; pigeonResult.localizedDescription = localizedDescription; @@ -352,11 +357,14 @@ + (SKProductMessage *)fromList:(NSArray *)list { pigeonResult.productIdentifier = GetNullableObjectAtIndex(list, 0); pigeonResult.localizedTitle = GetNullableObjectAtIndex(list, 1); pigeonResult.localizedDescription = GetNullableObjectAtIndex(list, 2); - pigeonResult.priceLocale = [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 3))]; + pigeonResult.priceLocale = + [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 3))]; pigeonResult.subscriptionGroupIdentifier = GetNullableObjectAtIndex(list, 4); pigeonResult.price = GetNullableObjectAtIndex(list, 5); - pigeonResult.subscriptionPeriod = [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 6))]; - pigeonResult.introductoryPrice = [SKProductDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 7))]; + pigeonResult.subscriptionPeriod = + [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 6))]; + pigeonResult.introductoryPrice = + [SKProductDiscountMessage nullableFromList:(GetNullableObjectAtIndex(list, 7))]; pigeonResult.discounts = GetNullableObjectAtIndex(list, 8); return pigeonResult; } @@ -380,9 +388,9 @@ - (NSArray *)toList { @implementation SKPriceLocaleMessage + (instancetype)makeWithCurrencySymbol:(NSString *)currencySymbol - currencyCode:(NSString *)currencyCode - countryCode:(NSString *)countryCode { - SKPriceLocaleMessage* pigeonResult = [[SKPriceLocaleMessage alloc] init]; + currencyCode:(NSString *)currencyCode + countryCode:(NSString *)countryCode { + SKPriceLocaleMessage *pigeonResult = [[SKPriceLocaleMessage alloc] init]; pigeonResult.currencySymbol = currencySymbol; pigeonResult.currencyCode = currencyCode; pigeonResult.countryCode = countryCode; @@ -409,13 +417,13 @@ - (NSArray *)toList { @implementation SKProductDiscountMessage + (instancetype)makeWithPrice:(NSString *)price - priceLocale:(SKPriceLocaleMessage *)priceLocale - numberOfPeriods:(NSInteger )numberOfPeriods - paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode - subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod - identifier:(nullable NSString *)identifier - type:(SKProductDiscountTypeMessage)type { - SKProductDiscountMessage* pigeonResult = [[SKProductDiscountMessage alloc] init]; + priceLocale:(SKPriceLocaleMessage *)priceLocale + numberOfPeriods:(NSInteger)numberOfPeriods + paymentMode:(SKProductDiscountPaymentModeMessage)paymentMode + subscriptionPeriod:(SKProductSubscriptionPeriodMessage *)subscriptionPeriod + identifier:(nullable NSString *)identifier + type:(SKProductDiscountTypeMessage)type { + SKProductDiscountMessage *pigeonResult = [[SKProductDiscountMessage alloc] init]; pigeonResult.price = price; pigeonResult.priceLocale = priceLocale; pigeonResult.numberOfPeriods = numberOfPeriods; @@ -428,10 +436,12 @@ + (instancetype)makeWithPrice:(NSString *)price + (SKProductDiscountMessage *)fromList:(NSArray *)list { SKProductDiscountMessage *pigeonResult = [[SKProductDiscountMessage alloc] init]; pigeonResult.price = GetNullableObjectAtIndex(list, 0); - pigeonResult.priceLocale = [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 1))]; + pigeonResult.priceLocale = + [SKPriceLocaleMessage nullableFromList:(GetNullableObjectAtIndex(list, 1))]; pigeonResult.numberOfPeriods = [GetNullableObjectAtIndex(list, 2) integerValue]; pigeonResult.paymentMode = [GetNullableObjectAtIndex(list, 3) integerValue]; - pigeonResult.subscriptionPeriod = [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 4))]; + pigeonResult.subscriptionPeriod = + [SKProductSubscriptionPeriodMessage nullableFromList:(GetNullableObjectAtIndex(list, 4))]; pigeonResult.identifier = GetNullableObjectAtIndex(list, 5); pigeonResult.type = [GetNullableObjectAtIndex(list, 6) integerValue]; return pigeonResult; @@ -453,15 +463,17 @@ - (NSArray *)toList { @end @implementation SKProductSubscriptionPeriodMessage -+ (instancetype)makeWithNumberOfUnits:(NSInteger )numberOfUnits - unit:(SKSubscriptionPeriodUnitMessage)unit { - SKProductSubscriptionPeriodMessage* pigeonResult = [[SKProductSubscriptionPeriodMessage alloc] init]; ++ (instancetype)makeWithNumberOfUnits:(NSInteger)numberOfUnits + unit:(SKSubscriptionPeriodUnitMessage)unit { + SKProductSubscriptionPeriodMessage *pigeonResult = + [[SKProductSubscriptionPeriodMessage alloc] init]; pigeonResult.numberOfUnits = numberOfUnits; pigeonResult.unit = unit; return pigeonResult; } + (SKProductSubscriptionPeriodMessage *)fromList:(NSArray *)list { - SKProductSubscriptionPeriodMessage *pigeonResult = [[SKProductSubscriptionPeriodMessage alloc] init]; + SKProductSubscriptionPeriodMessage *pigeonResult = + [[SKProductSubscriptionPeriodMessage alloc] init]; pigeonResult.numberOfUnits = [GetNullableObjectAtIndex(list, 0) integerValue]; pigeonResult.unit = [GetNullableObjectAtIndex(list, 1) integerValue]; return pigeonResult; @@ -482,25 +494,25 @@ @interface InAppPurchaseAPICodecReader : FlutterStandardReader @implementation InAppPurchaseAPICodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: + case 128: return [SKErrorMessage fromList:[self readValue]]; - case 129: + case 129: return [SKPaymentDiscountMessage fromList:[self readValue]]; - case 130: + case 130: return [SKPaymentMessage fromList:[self readValue]]; - case 131: + case 131: return [SKPaymentTransactionMessage fromList:[self readValue]]; - case 132: + case 132: return [SKPriceLocaleMessage fromList:[self readValue]]; - case 133: + case 133: return [SKProductDiscountMessage fromList:[self readValue]]; - case 134: + case 134: return [SKProductMessage fromList:[self readValue]]; - case 135: + case 135: return [SKProductSubscriptionPeriodMessage fromList:[self readValue]]; - case 136: + case 136: return [SKProductsResponseMessage fromList:[self readValue]]; - case 137: + case 137: return [SKStorefrontMessage fromList:[self readValue]]; default: return [super readValueOfType:type]; @@ -563,22 +575,27 @@ - (FlutterStandardReader *)readerWithData:(NSData *)data { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - InAppPurchaseAPICodecReaderWriter *readerWriter = [[InAppPurchaseAPICodecReaderWriter alloc] init]; + InAppPurchaseAPICodecReaderWriter *readerWriter = + [[InAppPurchaseAPICodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } -void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject *api) { +void SetUpInAppPurchaseAPI(id binaryMessenger, + NSObject *api) { /// Returns if the current device is able to make payments { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(canMakePaymentsWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(canMakePaymentsWithError:)", api); + NSCAssert( + [api respondsToSelector:@selector(canMakePaymentsWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to @selector(canMakePaymentsWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; NSNumber *output = [api canMakePaymentsWithError:&error]; @@ -589,13 +606,14 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(transactionsWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(transactionsWithError:)", api); + NSCAssert([api respondsToSelector:@selector(transactionsWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to @selector(transactionsWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; NSArray *output = [api transactionsWithError:&error]; @@ -606,13 +624,14 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(storefrontWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(storefrontWithError:)", api); + NSCAssert([api respondsToSelector:@selector(storefrontWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to @selector(storefrontWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; SKStorefrontMessage *output = [api storefrontWithError:&error]; @@ -623,13 +642,15 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(addPaymentPaymentMap:error:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(addPaymentPaymentMap:error:)", api); + NSCAssert( + [api respondsToSelector:@selector(addPaymentPaymentMap:error:)], + @"InAppPurchaseAPI api (%@) doesn't respond to @selector(addPaymentPaymentMap:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSDictionary *arg_paymentMap = GetNullableObjectAtIndex(args, 0); @@ -642,32 +663,41 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(startProductRequestProductIdentifiers:completion:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(startProductRequestProductIdentifiers:completion:)", api); + NSCAssert([api respondsToSelector:@selector(startProductRequestProductIdentifiers: + completion:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(startProductRequestProductIdentifiers:completion:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSArray *arg_productIdentifiers = GetNullableObjectAtIndex(args, 0); - [api startProductRequestProductIdentifiers:arg_productIdentifiers completion:^(SKProductsResponseMessage *_Nullable output, FlutterError *_Nullable error) { - callback(wrapResult(output, error)); - }]; + [api startProductRequestProductIdentifiers:arg_productIdentifiers + completion:^(SKProductsResponseMessage *_Nullable output, + FlutterError *_Nullable error) { + callback(wrapResult(output, error)); + }]; }]; } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(finishTransactionFinishMap:error:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(finishTransactionFinishMap:error:)", api); + NSCAssert([api respondsToSelector:@selector(finishTransactionFinishMap:error:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(finishTransactionFinishMap:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSDictionary *arg_finishMap = GetNullableObjectAtIndex(args, 0); @@ -680,13 +710,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(restoreTransactionsApplicationUserName:error:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(restoreTransactionsApplicationUserName:error:)", api); + NSCAssert([api respondsToSelector:@selector(restoreTransactionsApplicationUserName:error:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(restoreTransactionsApplicationUserName:error:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSString *arg_applicationUserName = GetNullableObjectAtIndex(args, 0); @@ -699,13 +732,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." + @"presentCodeRedemptionSheet" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(presentCodeRedemptionSheetWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(presentCodeRedemptionSheetWithError:)", api); + NSCAssert([api respondsToSelector:@selector(presentCodeRedemptionSheetWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(presentCodeRedemptionSheetWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api presentCodeRedemptionSheetWithError:&error]; @@ -716,13 +752,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(retrieveReceiptDataWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(retrieveReceiptDataWithError:)", api); + NSCAssert( + [api respondsToSelector:@selector(retrieveReceiptDataWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to @selector(retrieveReceiptDataWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; NSString *output = [api retrieveReceiptDataWithError:&error]; @@ -733,32 +772,39 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName: + @"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(refreshReceiptReceiptProperties:completion:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(refreshReceiptReceiptProperties:completion:)", api); + NSCAssert([api respondsToSelector:@selector(refreshReceiptReceiptProperties:completion:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(refreshReceiptReceiptProperties:completion:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; NSDictionary *arg_receiptProperties = GetNullableObjectAtIndex(args, 0); - [api refreshReceiptReceiptProperties:arg_receiptProperties completion:^(FlutterError *_Nullable error) { - callback(wrapResult(nil, error)); - }]; + [api refreshReceiptReceiptProperties:arg_receiptProperties + completion:^(FlutterError *_Nullable error) { + callback(wrapResult(nil, error)); + }]; }]; } else { [channel setMessageHandler:nil]; } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." + @"startObservingPaymentQueue" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(startObservingPaymentQueueWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(startObservingPaymentQueueWithError:)", api); + NSCAssert([api respondsToSelector:@selector(startObservingPaymentQueueWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(startObservingPaymentQueueWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api startObservingPaymentQueueWithError:&error]; @@ -769,13 +815,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." + @"stopObservingPaymentQueue" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(stopObservingPaymentQueueWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(stopObservingPaymentQueueWithError:)", api); + NSCAssert([api respondsToSelector:@selector(stopObservingPaymentQueueWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(stopObservingPaymentQueueWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api stopObservingPaymentQueueWithError:&error]; @@ -786,13 +835,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." + @"registerPaymentQueueDelegate" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(registerPaymentQueueDelegateWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(registerPaymentQueueDelegateWithError:)", api); + NSCAssert([api respondsToSelector:@selector(registerPaymentQueueDelegateWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(registerPaymentQueueDelegateWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api registerPaymentQueueDelegateWithError:&error]; @@ -803,13 +855,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." + @"removePaymentQueueDelegate" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(removePaymentQueueDelegateWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(removePaymentQueueDelegateWithError:)", api); + NSCAssert([api respondsToSelector:@selector(removePaymentQueueDelegateWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(removePaymentQueueDelegateWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api removePaymentQueueDelegateWithError:&error]; @@ -820,13 +875,16 @@ void SetUpInAppPurchaseAPI(id binaryMessenger, NSObject< } } { - FlutterBasicMessageChannel *channel = - [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded" + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI." + @"showPriceConsentIfNeeded" binaryMessenger:binaryMessenger - codec:InAppPurchaseAPIGetCodec()]; + codec:InAppPurchaseAPIGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(showPriceConsentIfNeededWithError:)], @"InAppPurchaseAPI api (%@) doesn't respond to @selector(showPriceConsentIfNeededWithError:)", api); + NSCAssert([api respondsToSelector:@selector(showPriceConsentIfNeededWithError:)], + @"InAppPurchaseAPI api (%@) doesn't respond to " + @"@selector(showPriceConsentIfNeededWithError:)", + api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api showPriceConsentIfNeededWithError:&error]; diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 102a865d991..477131feb69 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -26,7 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> wrapResponse({Object? result, PlatformException? error, bool empty = false}) { +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { if (empty) { return []; } @@ -32,27 +36,32 @@ enum SKPaymentTransactionStateMessage { /// transaction to update to another state. Never complete a transaction that /// is still in a purchasing state. purchasing, + /// The user's payment has been succesfully processed. /// /// You should provide the user the content that they purchased. purchased, + /// The transaction failed. /// /// Check the [PaymentTransactionWrapper.error] property from /// [PaymentTransactionWrapper] for details. failed, + /// This transaction is restoring content previously purchased by the user. /// /// The previous transaction information can be obtained in /// [PaymentTransactionWrapper.originalTransaction] from /// [PaymentTransactionWrapper]. restored, + /// The transaction is in the queue but pending external action. Wait for /// another callback to get the final state. /// /// You should update your UI to indicate that you are waiting for the /// transaction to update to another state. deferred, + /// Indicates the transaction is in an unspecified state. unspecified, } @@ -60,6 +69,7 @@ enum SKPaymentTransactionStateMessage { enum SKProductDiscountTypeMessage { /// A constant indicating the discount type is an introductory offer. introductory, + /// A constant indicating the discount type is a promotional offer. subscription, } @@ -67,10 +77,13 @@ enum SKProductDiscountTypeMessage { enum SKProductDiscountPaymentModeMessage { /// Allows user to pay the discounted price at each payment period. payAsYouGo, + /// Allows user to pay the discounted price upfront and receive the product for the rest of time that was paid for. payUpFront, + /// User pays nothing during the discounted period. freeTrial, + /// Unspecified mode. unspecified, } @@ -119,7 +132,8 @@ class SKPaymentTransactionMessage { result as List; return SKPaymentTransactionMessage( payment: SKPaymentMessage.decode(result[0]! as List), - transactionState: SKPaymentTransactionStateMessage.values[result[1]! as int], + transactionState: + SKPaymentTransactionStateMessage.values[result[1]! as int], originalTransaction: result[2] != null ? SKPaymentTransactionMessage.decode(result[2]! as List) : null, @@ -359,12 +373,14 @@ class SKProductMessage { subscriptionGroupIdentifier: result[4] as String?, price: result[5]! as String, subscriptionPeriod: result[6] != null - ? SKProductSubscriptionPeriodMessage.decode(result[6]! as List) + ? SKProductSubscriptionPeriodMessage.decode( + result[6]! as List) : null, introductoryPrice: result[7] != null ? SKProductDiscountMessage.decode(result[7]! as List) : null, - discounts: (result[8] as List?)?.cast(), + discounts: + (result[8] as List?)?.cast(), ); } } @@ -446,8 +462,10 @@ class SKProductDiscountMessage { price: result[0]! as String, priceLocale: SKPriceLocaleMessage.decode(result[1]! as List), numberOfPeriods: result[2]! as int, - paymentMode: SKProductDiscountPaymentModeMessage.values[result[3]! as int], - subscriptionPeriod: SKProductSubscriptionPeriodMessage.decode(result[4]! as List), + paymentMode: + SKProductDiscountPaymentModeMessage.values[result[3]! as int], + subscriptionPeriod: SKProductSubscriptionPeriodMessage.decode( + result[4]! as List), identifier: result[5] as String?, type: SKProductDiscountTypeMessage.values[result[6]! as int], ); @@ -522,25 +540,25 @@ class _InAppPurchaseAPICodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return SKErrorMessage.decode(readValue(buffer)!); - case 129: + case 129: return SKPaymentDiscountMessage.decode(readValue(buffer)!); - case 130: + case 130: return SKPaymentMessage.decode(readValue(buffer)!); - case 131: + case 131: return SKPaymentTransactionMessage.decode(readValue(buffer)!); - case 132: + case 132: return SKPriceLocaleMessage.decode(readValue(buffer)!); - case 133: + case 133: return SKProductDiscountMessage.decode(readValue(buffer)!); - case 134: + case 134: return SKProductMessage.decode(readValue(buffer)!); - case 135: + case 135: return SKProductSubscriptionPeriodMessage.decode(readValue(buffer)!); - case 136: + case 136: return SKProductsResponseMessage.decode(readValue(buffer)!); - case 137: + case 137: return SKStorefrontMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -556,12 +574,15 @@ class InAppPurchaseAPI { : __pigeon_binaryMessenger = binaryMessenger; final BinaryMessenger? __pigeon_binaryMessenger; - static const MessageCodec pigeonChannelCodec = _InAppPurchaseAPICodec(); + static const MessageCodec pigeonChannelCodec = + _InAppPurchaseAPICodec(); /// Returns if the current device is able to make payments Future canMakePayments() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -587,8 +608,10 @@ class InAppPurchaseAPI { } Future> transactions() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -609,13 +632,16 @@ class InAppPurchaseAPI { message: 'Host platform returned null value for non-null return value.', ); } else { - return (__pigeon_replyList[0] as List?)!.cast(); + return (__pigeon_replyList[0] as List?)! + .cast(); } } Future storefront() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -641,8 +667,10 @@ class InAppPurchaseAPI { } Future addPayment(Map paymentMap) async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -662,15 +690,18 @@ class InAppPurchaseAPI { } } - Future startProductRequest(List productIdentifiers) async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future startProductRequest( + List productIdentifiers) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([productIdentifiers]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([productIdentifiers]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -690,8 +721,10 @@ class InAppPurchaseAPI { } Future finishTransaction(Map finishMap) async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -712,14 +745,16 @@ class InAppPurchaseAPI { } Future restoreTransactions(String? applicationUserName) async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([applicationUserName]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([applicationUserName]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -734,8 +769,10 @@ class InAppPurchaseAPI { } Future presentCodeRedemptionSheet() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -755,9 +792,11 @@ class InAppPurchaseAPI { } } - Future retrieveReceiptData() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future retrieveReceiptData() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -772,25 +811,23 @@ class InAppPurchaseAPI { message: __pigeon_replyList[1] as String?, details: __pigeon_replyList[2], ); - } else if (__pigeon_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); } else { - return (__pigeon_replyList[0] as String?)!; + return (__pigeon_replyList[0] as String?); } } - Future refreshReceipt({Map? receiptProperties}) async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + Future refreshReceipt( + {Map? receiptProperties}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, ); - final List? __pigeon_replyList = - await __pigeon_channel.send([receiptProperties]) as List?; + final List? __pigeon_replyList = await __pigeon_channel + .send([receiptProperties]) as List?; if (__pigeon_replyList == null) { throw _createConnectionError(__pigeon_channelName); } else if (__pigeon_replyList.length > 1) { @@ -805,8 +842,10 @@ class InAppPurchaseAPI { } Future startObservingPaymentQueue() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -827,8 +866,10 @@ class InAppPurchaseAPI { } Future stopObservingPaymentQueue() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -849,8 +890,10 @@ class InAppPurchaseAPI { } Future registerPaymentQueueDelegate() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -871,8 +914,10 @@ class InAppPurchaseAPI { } Future removePaymentQueueDelegate() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, @@ -893,8 +938,10 @@ class InAppPurchaseAPI { } Future showPriceConsentIfNeeded() async { - const String __pigeon_channelName = 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded'; - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( + const String __pigeon_channelName = + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( __pigeon_channelName, pigeonChannelCodec, binaryMessenger: __pigeon_binaryMessenger, 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 9dfd1aa864c..a9f1e8ca8d0 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 @@ -86,14 +86,16 @@ class SKPaymentQueueWrapper { /// /// Call this method when the first listener is subscribed to the /// [InAppPurchaseStoreKitPlatform.purchaseStream]. - Future startObservingTransactionQueue() => _hostApi.startObservingPaymentQueue(); + Future startObservingTransactionQueue() => + _hostApi.startObservingPaymentQueue(); /// Instructs the iOS implementation to remove the transaction observer and /// stop listening to it. /// /// Call this when there are no longer any listeners subscribed to the /// [InAppPurchaseStoreKitPlatform.purchaseStream]. - Future stopObservingTransactionQueue() => _hostApi.stopObservingPaymentQueue(); + Future stopObservingTransactionQueue() => + _hostApi.stopObservingPaymentQueue(); /// Sets an implementation of the [SKPaymentQueueDelegateWrapper]. /// 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 b8844b445f3..f61105aa213 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 @@ -19,7 +19,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/pigeons/copyright.txt b/packages/in_app_purchase/in_app_purchase_storekit/pigeons/copyright.txt index e69de29bb2d..fb682b1ab96 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pigeons/copyright.txt +++ b/packages/in_app_purchase/in_app_purchase_storekit/pigeons/copyright.txt @@ -0,0 +1,3 @@ +Copyright 2013 The Flutter Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. \ No newline at end of file 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 97fa1dbd186..920873e6527 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.3.10 +version: 0.3.11 environment: sdk: ^3.2.3 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 a25055cc2f2..7dede05c697 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 @@ -255,8 +255,7 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { } @override - void showPriceConsentIfNeeded() { - } + void showPriceConsentIfNeeded() {} @override void startObservingPaymentQueue() { 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 a83c66cf79e..03c9fda381c 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 @@ -13,7 +13,6 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); final FakeStoreKitPlatform fakeStoreKitPlatform = FakeStoreKitPlatform(); - setUpAll(() { TestInAppPurchaseApi.setup(fakeStoreKitPlatform); 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 index 0d86e5ac20a..65cd6e0bcc2 100644 --- 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 @@ -1,3 +1,6 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // Autogenerated from Pigeon (v16.0.4), 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 @@ -52,25 +55,25 @@ class _TestInAppPurchaseApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return SKErrorMessage.decode(readValue(buffer)!); - case 129: + case 129: return SKPaymentDiscountMessage.decode(readValue(buffer)!); - case 130: + case 130: return SKPaymentMessage.decode(readValue(buffer)!); - case 131: + case 131: return SKPaymentTransactionMessage.decode(readValue(buffer)!); - case 132: + case 132: return SKPriceLocaleMessage.decode(readValue(buffer)!); - case 133: + case 133: return SKProductDiscountMessage.decode(readValue(buffer)!); - case 134: + case 134: return SKProductMessage.decode(readValue(buffer)!); - case 135: + case 135: return SKProductSubscriptionPeriodMessage.decode(readValue(buffer)!); - case 136: + case 136: return SKProductsResponseMessage.decode(readValue(buffer)!); - case 137: + case 137: return SKStorefrontMessage.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -79,8 +82,10 @@ class _TestInAppPurchaseApiCodec extends StandardMessageCodec { } abstract class TestInAppPurchaseApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec pigeonChannelCodec = _TestInAppPurchaseApiCodec(); + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec pigeonChannelCodec = + _TestInAppPurchaseApiCodec(); /// Returns if the current device is able to make payments bool canMakePayments(); @@ -91,7 +96,8 @@ abstract class TestInAppPurchaseApi { void addPayment(Map paymentMap); - Future startProductRequest(List productIdentifiers); + Future startProductRequest( + List productIdentifiers); void finishTransaction(Map finishMap); @@ -99,7 +105,7 @@ abstract class TestInAppPurchaseApi { void presentCodeRedemptionSheet(); - String retrieveReceiptData(); + String? retrieveReceiptData(); Future refreshReceipt({Map? receiptProperties}); @@ -113,76 +119,102 @@ abstract class TestInAppPurchaseApi { void showPriceConsentIfNeeded(); - static void setup(TestInAppPurchaseApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestInAppPurchaseApi? api, + {BinaryMessenger? binaryMessenger}) { { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.canMakePayments', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.transactions', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { try { - final List output = api.transactions(); + 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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.storefront', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.addPayment was 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(); + 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 { @@ -190,49 +222,64 @@ abstract class TestInAppPurchaseApi { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startProductRequest was 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(); + 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!); + 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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.finishTransaction was 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(); + 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 { @@ -240,22 +287,28 @@ abstract class TestInAppPurchaseApi { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.restoreTransactions was 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 { @@ -263,164 +316,214 @@ abstract class TestInAppPurchaseApi { return wrapResponse(empty: true); } on PlatformException catch (e) { return wrapResponse(error: e); - } catch (e) { - return wrapResponse(error: PlatformException(code: 'error', message: e.toString())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.presentCodeRedemptionSheet', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.retrieveReceiptData', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { try { - final String output = api.retrieveReceiptData(); + 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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, + (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.refreshReceipt was 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(); + 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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.startObservingPaymentQueue', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.stopObservingPaymentQueue', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.registerPaymentQueueDelegate', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.removePaymentQueueDelegate', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } } { - final BasicMessageChannel __pigeon_channel = BasicMessageChannel( - 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded', pigeonChannelCodec, + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchaseAPI.showPriceConsentIfNeeded', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(__pigeon_channel, (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(__pigeon_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())); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); } }); } From 6dae4e50696bc3281c876c959b5ad656f89768a1 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 14:48:59 -0800 Subject: [PATCH 09/14] warnings --- .../test/store_kit_wrappers/sk_methodchannel_apis_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 68d202255c3..82775f6b2e2 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 @@ -295,8 +295,8 @@ class FakeStoreKitPlatform implements TestInAppPurchaseApi { @override Future refreshReceipt({Map? receiptProperties}) { refreshReceiptCount++; - refreshReceiptParam = Map.castFrom( - receiptProperties! as Map); + refreshReceiptParam = + Map.castFrom(receiptProperties!); return Future.sync(() {}); } From 4f941c5dad8d285ab587c7d0418adfefc1d2a818 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 15:51:17 -0800 Subject: [PATCH 10/14] move things around for nicer diff --- .../darwin/Classes/InAppPurchasePlugin.m | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index f38cc27030d..583fdefc2b0 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -246,30 +246,6 @@ - (void)presentCodeRedemptionSheetWithError: #endif } -- (void)registerPaymentQueueDelegateWithError: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { -#if TARGET_OS_IOS - if (@available(iOS 13.0, *)) { - _paymentQueueDelegateCallbackChannel = [FlutterMethodChannel - methodChannelWithName:@"plugins.flutter.io/in_app_purchase_payment_queue_delegate" - binaryMessenger:[_registrar messenger]]; - - _paymentQueueDelegate = [[FIAPPaymentQueueDelegate alloc] - initWithMethodChannel:_paymentQueueDelegateCallbackChannel]; - _paymentQueueHandler.delegate = _paymentQueueDelegate; - } -#endif -} - -- (void)removePaymentQueueDelegateWithError: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - if (@available(iOS 13.0, *)) { - _paymentQueueHandler.delegate = nil; - } - _paymentQueueDelegate = nil; - _paymentQueueDelegateCallbackChannel = nil; -} - - (NSString *_Nullable)retrieveReceiptDataWithError: (FlutterError *_Nullable __autoreleasing *_Nonnull)error { FlutterError *flutterError; @@ -281,24 +257,6 @@ - (NSString *_Nullable)retrieveReceiptDataWithError: return receiptData; } -- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { -#if TARGET_OS_IOS - if (@available(iOS 13.4, *)) { - [_paymentQueueHandler showPriceConsentIfNeeded]; - } -#endif -} - -- (void)startObservingPaymentQueueWithError: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [_paymentQueueHandler startObservingPaymentQueue]; -} - -- (void)stopObservingPaymentQueueWithError: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [_paymentQueueHandler stopObservingPaymentQueue]; -} - - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperties completion:(nonnull void (^)(FlutterError *_Nullable))completion { SKReceiptRefreshRequest *request; @@ -330,6 +288,48 @@ - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperti }]; } +- (void)registerPaymentQueueDelegateWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { +#if TARGET_OS_IOS + if (@available(iOS 13.0, *)) { + _paymentQueueDelegateCallbackChannel = [FlutterMethodChannel + methodChannelWithName:@"plugins.flutter.io/in_app_purchase_payment_queue_delegate" + binaryMessenger:[_registrar messenger]]; + + _paymentQueueDelegate = [[FIAPPaymentQueueDelegate alloc] + initWithMethodChannel:_paymentQueueDelegateCallbackChannel]; + _paymentQueueHandler.delegate = _paymentQueueDelegate; + } +#endif +} + +- (void)removePaymentQueueDelegateWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { + if (@available(iOS 13.0, *)) { + _paymentQueueHandler.delegate = nil; + } + _paymentQueueDelegate = nil; + _paymentQueueDelegateCallbackChannel = nil; +} + +- (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { +#if TARGET_OS_IOS + if (@available(iOS 13.4, *)) { + [_paymentQueueHandler showPriceConsentIfNeeded]; + } +#endif +} + +- (void)startObservingPaymentQueueWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { + [_paymentQueueHandler startObservingPaymentQueue]; +} + +- (void)stopObservingPaymentQueueWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { + [_paymentQueueHandler stopObservingPaymentQueue]; +} + - (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key { id value = dictionary[key]; return [value isKindOfClass:[NSNull class]] ? nil : value; From fb644f8868b5da303e7657489fb71dd754171ba1 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 16:03:47 -0800 Subject: [PATCH 11/14] nice diffs, very beautiful diffs --- .../darwin/Classes/InAppPurchasePlugin.m | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index 583fdefc2b0..b8f84a2447b 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -288,6 +288,16 @@ - (void)refreshReceiptReceiptProperties:(nullable NSDictionary *)receiptProperti }]; } +- (void)startObservingPaymentQueueWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { + [_paymentQueueHandler startObservingPaymentQueue]; +} + +- (void)stopObservingPaymentQueueWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { + [_paymentQueueHandler stopObservingPaymentQueue]; +} + - (void)registerPaymentQueueDelegateWithError: (FlutterError *_Nullable __autoreleasing *_Nonnull)error { #if TARGET_OS_IOS @@ -320,16 +330,6 @@ - (void)showPriceConsentIfNeededWithError:(FlutterError *_Nullable __autoreleasi #endif } -- (void)startObservingPaymentQueueWithError: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [_paymentQueueHandler startObservingPaymentQueue]; -} - -- (void)stopObservingPaymentQueueWithError: - (FlutterError *_Nullable __autoreleasing *_Nonnull)error { - [_paymentQueueHandler stopObservingPaymentQueue]; -} - - (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key { id value = dictionary[key]; return [value isKindOfClass:[NSNull class]] ? nil : value; From 03cd82a346b16e7653696e06b743abbede0e0176 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 20 Feb 2024 16:32:16 -0800 Subject: [PATCH 12/14] versioning conflict --- .../in_app_purchase/in_app_purchase_storekit/CHANGELOG.md | 6 +++++- .../in_app_purchase/in_app_purchase_storekit/pubspec.yaml | 2 +- .../test/fakes/fake_storekit_platform.dart | 5 ----- .../test/in_app_purchase_storekit_platform_test.dart | 3 --- 4 files changed, 6 insertions(+), 10 deletions(-) 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 583269b6b60..e680a23cb42 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md @@ -1,7 +1,11 @@ -## 0.3.11 +## 0.3.12 * Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`, `registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon. +## 0.3.11 + +* Fixes SKError.userInfo not being nullable. + ## 0.3.10 * Converts `startProductRequest()`, `finishTransaction()`, `restoreTransactions()`, `presentCodeRedemptionSheet()` to pigeon. 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 920873e6527..ee7422b1000 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.3.11 +version: 0.3.12 environment: sdk: ^3.2.3 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 7dede05c697..8fff5754eb7 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 @@ -12,11 +12,6 @@ import '../store_kit_wrappers/sk_test_stub_objects.dart'; import '../test_api.g.dart'; class FakeStoreKitPlatform implements TestInAppPurchaseApi { - FakeStoreKitPlatform() { - // TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - // .setMockMethodCallHandler(channel, onMethodCall); - } - // pre-configured store information String? receiptData; late Set validProductIDs; 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 d5170d26317..e268c23bdaa 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 @@ -23,9 +23,6 @@ void main() { setUpAll(() { TestInAppPurchaseApi.setup(fakeStoreKitPlatform); - // TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger - // .setMockMethodCallHandler( - // SystemChannels.platform, fakeStoreKitPlatform.onMethodCall); }); setUp(() { From b0aa7cc2df16e94df220cf36d6162844787cfb67 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 21 Feb 2024 11:14:45 -0800 Subject: [PATCH 13/14] pr comments --- .../darwin/Classes/InAppPurchasePlugin.m | 2 +- .../example/shared/RunnerTests/InAppPurchasePluginTests.m | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m index b8f84a2447b..0a8b162bf1a 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/InAppPurchasePlugin.m @@ -246,7 +246,7 @@ - (void)presentCodeRedemptionSheetWithError: #endif } -- (NSString *_Nullable)retrieveReceiptDataWithError: +- (nullable NSString *)retrieveReceiptDataWithError: (FlutterError *_Nullable __autoreleasing *_Nonnull)error { FlutterError *flutterError; NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&flutterError]; diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index bde73d2cd6a..a663cea58bf 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -286,7 +286,7 @@ - (void)testRestoreTransactions { - (void)testRetrieveReceiptDataSuccess { FlutterError *error; - id result = [self.plugin retrieveReceiptDataWithError:&error]; + NSString *result = [self.plugin retrieveReceiptDataWithError:&error]; XCTAssertNotNil(result); XCTAssert([result isKindOfClass:[NSString class]]); } @@ -295,7 +295,7 @@ - (void)testRetrieveReceiptDataNil { NSBundle *mockBundle = OCMPartialMock([NSBundle mainBundle]); OCMStub(mockBundle.appStoreReceiptURL).andReturn(nil); FlutterError *error; - id result = [self.plugin retrieveReceiptDataWithError:&error]; + NSString *result = [self.plugin retrieveReceiptDataWithError:&error]; XCTAssertNil(result); } @@ -303,7 +303,7 @@ - (void)testRetrieveReceiptDataError { self.receiptManagerStub.returnError = YES; FlutterError *error; - id result = [self.plugin retrieveReceiptDataWithError:&error]; + NSString *result = [self.plugin retrieveReceiptDataWithError:&error]; XCTAssertNil(result); XCTAssertNotNil(error); @@ -324,6 +324,7 @@ - (void)testRefreshReceiptRequest { } #if TARGET_OS_IOS +/// presentCodeRedemptionSheetWithError:error is only available on iOS - (void)testPresentCodeRedemptionSheet { FIAPaymentQueueHandler *mockHandler = OCMClassMock([FIAPaymentQueueHandler class]); self.plugin.paymentQueueHandler = mockHandler; From f5b07df1ea8b98a51a0a8949f811f9befdd0d82e Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 21 Feb 2024 13:55:04 -0800 Subject: [PATCH 14/14] pr comments --- packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md | 3 ++- .../example/shared/RunnerTests/InAppPurchasePluginTests.m | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 e680a23cb42..309510b3af5 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md +++ b/packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.3.12 -* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`, `registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon. +* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`, +`registerPaymentQueueDelegate()`, `removePaymentQueueDelegate()`, `showPriceConsentIfNeeded()` to pigeon. ## 0.3.11 diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m index a663cea58bf..1c0f734bc01 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -323,8 +323,8 @@ - (void)testRefreshReceiptRequest { [self waitForExpectations:@[ expectation ] timeout:5]; } -#if TARGET_OS_IOS /// presentCodeRedemptionSheetWithError:error is only available on iOS +#if TARGET_OS_IOS - (void)testPresentCodeRedemptionSheet { FIAPaymentQueueHandler *mockHandler = OCMClassMock([FIAPaymentQueueHandler class]); self.plugin.paymentQueueHandler = mockHandler;