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 324e0608b7f9..3839419a32cf 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.4 + +* Adds macOS as a supported platform. + ## 0.3.3 * Supports adding discount information to AppStorePurchaseParam. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/README.md b/packages/in_app_purchase/in_app_purchase_storekit/README.md index 76e2854c26e1..d58efd1e298c 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/README.md +++ b/packages/in_app_purchase/in_app_purchase_storekit/README.md @@ -1,6 +1,6 @@ # in\_app\_purchase\_storekit -The iOS implementation of [`in_app_purchase`][1]. +The iOS and macOS implementation of [`in_app_purchase`][1]. ## Usage diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIAPPaymentQueueDeleteTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIAPPaymentQueueDeleteTests.m deleted file mode 100644 index ea8787f55a0a..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIAPPaymentQueueDeleteTests.m +++ /dev/null @@ -1,120 +0,0 @@ -// 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. - -#import -#import -#import "FIAObjectTranslator.h" -#import "FIAPaymentQueueHandler.h" -#import "Stubs.h" - -@import in_app_purchase_storekit; - -API_AVAILABLE(ios(13.0)) -@interface FIAPPaymentQueueDelegateTests : XCTestCase - -@property(strong, nonatomic) FlutterMethodChannel *channel; -@property(strong, nonatomic) SKPaymentTransaction *transaction; -@property(strong, nonatomic) SKStorefront *storefront; - -@end - -@implementation FIAPPaymentQueueDelegateTests - -- (void)setUp { - self.channel = OCMClassMock(FlutterMethodChannel.class); - - NSDictionary *transactionMap = @{ - @"transactionIdentifier" : [NSNull null], - @"transactionState" : @(SKPaymentTransactionStatePurchasing), - @"payment" : [NSNull null], - @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" - code:123 - userInfo:@{}]], - @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), - @"originalTransaction" : [NSNull null], - }; - self.transaction = [[SKPaymentTransactionStub alloc] initWithMap:transactionMap]; - - NSDictionary *storefrontMap = @{ - @"countryCode" : @"USA", - @"identifier" : @"unique_identifier", - }; - self.storefront = [[SKStorefrontStub alloc] initWithMap:storefrontMap]; -} - -- (void)tearDown { - self.channel = nil; -} - -- (void)testShouldContinueTransaction { - if (@available(iOS 13.0, *)) { - FIAPPaymentQueueDelegate *delegate = - [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; - - OCMStub([self.channel - invokeMethod:@"shouldContinueTransaction" - arguments:[FIAObjectTranslator getMapFromSKStorefront:self.storefront - andSKPaymentTransaction:self.transaction] - result:([OCMArg invokeBlockWithArgs:[NSNumber numberWithBool:NO], nil])]); - - BOOL shouldContinue = [delegate paymentQueue:OCMClassMock(SKPaymentQueue.class) - shouldContinueTransaction:self.transaction - inStorefront:self.storefront]; - - XCTAssertFalse(shouldContinue); - } -} - -- (void)testShouldContinueTransaction_should_default_to_yes { - if (@available(iOS 13.0, *)) { - FIAPPaymentQueueDelegate *delegate = - [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; - - OCMStub([self.channel invokeMethod:@"shouldContinueTransaction" - arguments:[FIAObjectTranslator getMapFromSKStorefront:self.storefront - andSKPaymentTransaction:self.transaction] - result:[OCMArg any]]); - - BOOL shouldContinue = [delegate paymentQueue:OCMClassMock(SKPaymentQueue.class) - shouldContinueTransaction:self.transaction - inStorefront:self.storefront]; - - XCTAssertTrue(shouldContinue); - } -} - -- (void)testShouldShowPriceConsentIfNeeded { - if (@available(iOS 13.4, *)) { - FIAPPaymentQueueDelegate *delegate = - [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; - - OCMStub([self.channel - invokeMethod:@"shouldShowPriceConsent" - arguments:nil - result:([OCMArg invokeBlockWithArgs:[NSNumber numberWithBool:NO], nil])]); - - BOOL shouldShow = - [delegate paymentQueueShouldShowPriceConsent:OCMClassMock(SKPaymentQueue.class)]; - - XCTAssertFalse(shouldShow); - } -} - -- (void)testShouldShowPriceConsentIfNeeded_should_default_to_yes { - if (@available(iOS 13.4, *)) { - FIAPPaymentQueueDelegate *delegate = - [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; - - OCMStub([self.channel invokeMethod:@"shouldShowPriceConsent" - arguments:nil - result:[OCMArg any]]); - - BOOL shouldShow = - [delegate paymentQueueShouldShowPriceConsent:OCMClassMock(SKPaymentQueue.class)]; - - XCTAssertTrue(shouldShow); - } -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIAPPaymentQueueDeleteTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIAPPaymentQueueDeleteTests.m new file mode 120000 index 000000000000..7c8e7691c6d4 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIAPPaymentQueueDeleteTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/FIAPPaymentQueueDeleteTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIATransactionCacheTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIATransactionCacheTests.m deleted file mode 100644 index 1ba0aea76e39..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIATransactionCacheTests.m +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -#import - -@import in_app_purchase_storekit; - -@interface FIATransactionCacheTests : XCTestCase - -@end - -@implementation FIATransactionCacheTests - -- (void)testAddObjectsForNewKey { - NSArray *dummyArray = @[ @1, @2, @3 ]; - FIATransactionCache *cache = [[FIATransactionCache alloc] init]; - [cache addObjects:dummyArray forKey:TransactionCacheKeyUpdatedTransactions]; - - XCTAssertEqual(dummyArray, [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); -} - -- (void)testAddObjectsForExistingKey { - NSArray *dummyArray = @[ @1, @2, @3 ]; - FIATransactionCache *cache = [[FIATransactionCache alloc] init]; - [cache addObjects:dummyArray forKey:TransactionCacheKeyUpdatedTransactions]; - - XCTAssertEqual(dummyArray, [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); - - [cache addObjects:@[ @4, @5, @6 ] forKey:TransactionCacheKeyUpdatedTransactions]; - - NSArray *expected = @[ @1, @2, @3, @4, @5, @6 ]; - XCTAssertEqualObjects(expected, [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); -} - -- (void)testGetObjectsForNonExistingKey { - FIATransactionCache *cache = [[FIATransactionCache alloc] init]; - XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); -} - -- (void)testClear { - NSArray *fakeUpdatedTransactions = @[ @1, @2, @3 ]; - NSArray *fakeRemovedTransactions = @[ @"Remove 1", @"Remove 2", @"Remove 3" ]; - NSArray *fakeUpdatedDownloads = @[ @"Download 1", @"Download 2" ]; - FIATransactionCache *cache = [[FIATransactionCache alloc] init]; - [cache addObjects:fakeUpdatedTransactions forKey:TransactionCacheKeyUpdatedTransactions]; - [cache addObjects:fakeRemovedTransactions forKey:TransactionCacheKeyRemovedTransactions]; - [cache addObjects:fakeUpdatedDownloads forKey:TransactionCacheKeyUpdatedDownloads]; - - XCTAssertEqual(fakeUpdatedTransactions, - [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); - XCTAssertEqual(fakeRemovedTransactions, - [cache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); - XCTAssertEqual(fakeUpdatedDownloads, - [cache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); - - [cache clear]; - - XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); - XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); - XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); -} -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIATransactionCacheTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIATransactionCacheTests.m new file mode 120000 index 000000000000..5c7c87fd1aea --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/FIATransactionCacheTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/FIATransactionCacheTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/InAppPurchasePluginTests.m deleted file mode 100644 index c89589c6a9e5..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/InAppPurchasePluginTests.m +++ /dev/null @@ -1,520 +0,0 @@ -// 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. - -#import -#import -#import "FIAPaymentQueueHandler.h" -#import "Stubs.h" - -@import in_app_purchase_storekit; - -@interface InAppPurchasePluginTest : XCTestCase - -@property(strong, nonatomic) FIAPReceiptManagerStub *receiptManagerStub; -@property(strong, nonatomic) InAppPurchasePlugin *plugin; - -@end - -@implementation InAppPurchasePluginTest - -- (void)setUp { - self.receiptManagerStub = [FIAPReceiptManagerStub new]; - self.plugin = [[InAppPurchasePluginStub alloc] initWithReceiptManager:self.receiptManagerStub]; -} - -- (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 { - XCTestExpectation *expectation = [self expectationWithDescription:@"expect result to be YES"]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue canMakePayments:]" - arguments:NULL]; - __block id result; - [self.plugin handleMethodCall:call - result:^(id r) { - [expectation fulfill]; - result = r; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(result, @YES); -} - -- (void)testGetProductResponse { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect response contains 1 item"]; - FlutterMethodCall *call = [FlutterMethodCall - methodCallWithMethodName:@"-[InAppPurchasePlugin startProductRequest:result:]" - arguments:@[ @"123" ]]; - __block id result; - [self.plugin handleMethodCall:call - result:^(id r) { - [expectation fulfill]; - result = r; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssert([result isKindOfClass:[NSDictionary class]]); - NSArray *resultArray = [result objectForKey:@"products"]; - XCTAssertEqual(resultArray.count, 1); - XCTAssertTrue([resultArray.firstObject[@"productIdentifier"] isEqualToString:@"123"]); -} - -- (void)testAddPaymentShouldReturnFlutterErrorWhenArgumentsAreInvalid { - XCTestExpectation *expectation = - [self expectationWithDescription: - @"Result should contain a FlutterError when invalid parameters are passed in."]; - NSString *argument = @"Invalid argument"; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" - arguments:argument]; - [self.plugin handleMethodCall:call - result:^(id _Nullable result) { - FlutterError *error = result; - XCTAssertEqualObjects(@"storekit_invalid_argument", error.code); - XCTAssertEqualObjects(@"Argument type of addPayment is not a Dictionary", - error.message); - XCTAssertEqualObjects(argument, error.details); - [expectation fulfill]; - }]; - - [self waitForExpectations:@[ expectation ] timeout:5]; -} - -- (void)testAddPaymentShouldReturnFlutterErrorWhenPaymentFails { - NSDictionary *arguments = @{ - @"productIdentifier" : @"123", - @"quantity" : @(1), - @"simulatesAskToBuyInSandbox" : @YES, - }; - XCTestExpectation *expectation = - [self expectationWithDescription:@"Result should return failed state."]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" - arguments:arguments]; - - FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); - OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(NO); - self.plugin.paymentQueueHandler = mockHandler; - - [self.plugin handleMethodCall:call - result:^(id _Nullable result) { - FlutterError *error = result; - XCTAssertEqualObjects(@"storekit_duplicate_product_object", error.code); - XCTAssertEqualObjects( - @"There is a pending transaction for the same product identifier. " - @"Please either wait for it to be finished or finish it manually " - @"using `completePurchase` to avoid edge cases.", - error.message); - XCTAssertEqualObjects(arguments, error.details); - [expectation fulfill]; - }]; - - [self waitForExpectations:@[ expectation ] timeout:5]; - OCMVerify(times(1), [mockHandler addPayment:[OCMArg any]]); -} - -- (void)testAddPaymentSuccessWithoutPaymentDiscount { - XCTestExpectation *expectation = - [self expectationWithDescription:@"Result should return success state"]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" - arguments:@{ - @"productIdentifier" : @"123", - @"quantity" : @(1), - @"simulatesAskToBuyInSandbox" : @YES, - }]; - FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); - OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(YES); - self.plugin.paymentQueueHandler = mockHandler; - [self.plugin handleMethodCall:call - result:^(id _Nullable result) { - XCTAssertNil(result); - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; -} - -- (void)testAddPaymentSuccessWithPaymentDiscount { - XCTestExpectation *expectation = - [self expectationWithDescription:@"Result should return success state"]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" - arguments:@{ - @"productIdentifier" : @"123", - @"quantity" : @(1), - @"simulatesAskToBuyInSandbox" : @YES, - @"paymentDiscount" : @{ - @"identifier" : @"test_identifier", - @"keyIdentifier" : @"test_key_identifier", - @"nonce" : @"4a11a9cc-3bc3-11ec-8d3d-0242ac130003", - @"signature" : @"test_signature", - @"timestamp" : @(1635847102), - } - }]; - - FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); - OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(YES); - self.plugin.paymentQueueHandler = mockHandler; - [self.plugin handleMethodCall:call - result:^(id _Nullable result) { - XCTAssertNil(result); - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - OCMVerify( - times(1), - [mockHandler - addPayment:[OCMArg checkWithBlock:^BOOL(id obj) { - SKPayment *payment = obj; - if (@available(iOS 12.2, *)) { - SKPaymentDiscount *discount = payment.paymentDiscount; - - return [discount.identifier isEqual:@"test_identifier"] && - [discount.keyIdentifier isEqual:@"test_key_identifier"] && - [discount.nonce - isEqual:[[NSUUID alloc] - initWithUUIDString:@"4a11a9cc-3bc3-11ec-8d3d-0242ac130003"]] && - [discount.signature isEqual:@"test_signature"] && - [discount.timestamp isEqual:@(1635847102)]; - } - - return YES; - }]]); -} - -- (void)testAddPaymentFailureWithInvalidPaymentDiscount { - // Support for payment discount is only available on iOS 12.2 and higher. - if (@available(iOS 12.2, *)) { - XCTestExpectation *expectation = - [self expectationWithDescription:@"Result should return success state"]; - NSDictionary *arguments = @{ - @"productIdentifier" : @"123", - @"quantity" : @(1), - @"simulatesAskToBuyInSandbox" : @YES, - @"paymentDiscount" : @{ - @"keyIdentifier" : @"test_key_identifier", - @"nonce" : @"4a11a9cc-3bc3-11ec-8d3d-0242ac130003", - @"signature" : @"test_signature", - @"timestamp" : @(1635847102), - } - }; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" - arguments:arguments]; - - FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); - id translator = OCMClassMock(FIAObjectTranslator.class); - - NSString *error = @"Some error occurred"; - OCMStub(ClassMethod([translator - getSKPaymentDiscountFromMap:[OCMArg any] - withError:(NSString __autoreleasing **)[OCMArg setTo:error]])) - .andReturn(nil); - self.plugin.paymentQueueHandler = mockHandler; - [self.plugin - handleMethodCall:call - result:^(id _Nullable result) { - FlutterError *error = result; - XCTAssertEqualObjects(@"storekit_invalid_payment_discount_object", error.code); - XCTAssertEqualObjects( - @"You have requested a payment and specified a " - @"payment discount with invalid properties. Some error occurred", - error.message); - XCTAssertEqualObjects(arguments, error.details); - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - OCMVerify(never(), [mockHandler addPayment:[OCMArg any]]); - } -} - -- (void)testAddPaymentWithNullSandboxArgument { - XCTestExpectation *expectation = - [self expectationWithDescription:@"result should return success state"]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" - arguments:@{ - @"productIdentifier" : @"123", - @"quantity" : @(1), - @"simulatesAskToBuyInSandbox" : [NSNull null], - }]; - FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); - OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(YES); - self.plugin.paymentQueueHandler = mockHandler; - [self.plugin handleMethodCall:call - result:^(id _Nullable result) { - XCTAssertNil(result); - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - OCMVerify(times(1), [mockHandler addPayment:[OCMArg checkWithBlock:^BOOL(id obj) { - SKPayment *payment = obj; - return !payment.simulatesAskToBuyInSandbox; - }]]); -} - -- (void)testRestoreTransactions { - XCTestExpectation *expectation = - [self expectationWithDescription:@"result successfully restore transactions"]; - FlutterMethodCall *call = [FlutterMethodCall - methodCallWithMethodName:@"-[InAppPurchasePlugin restoreTransactions:result:]" - arguments:nil]; - SKPaymentQueueStub *queue = [SKPaymentQueueStub new]; - queue.testState = SKPaymentTransactionStatePurchased; - __block BOOL callbackInvoked = NO; - self.plugin.paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - } - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:^() { - callbackInvoked = YES; - [expectation fulfill]; - } - shouldAddStorePayment:nil - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - [queue addTransactionObserver:self.plugin.paymentQueueHandler]; - [self.plugin handleMethodCall:call - result:^(id r){ - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertTrue(callbackInvoked); -} - -- (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]; - XCTAssertNotNil(result); - XCTAssert([result isKindOfClass:[NSString class]]); -} - -- (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; - 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]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertTrue(result); -} - -- (void)testPresentCodeRedemptionSheet { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect successfully present Code Redemption Sheet"]; - FlutterMethodCall *call = [FlutterMethodCall - methodCallWithMethodName:@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" - arguments:nil]; - __block BOOL callbackInvoked = NO; - [self.plugin handleMethodCall:call - result:^(id r) { - callbackInvoked = YES; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertTrue(callbackInvoked); -} - -- (void)testGetPendingTransactions { - XCTestExpectation *expectation = [self expectationWithDescription:@"expect success"]; - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue transactions]" arguments:nil]; - SKPaymentQueue *mockQueue = OCMClassMock(SKPaymentQueue.class); - NSDictionary *transactionMap = @{ - @"transactionIdentifier" : [NSNull null], - @"transactionState" : @(SKPaymentTransactionStatePurchasing), - @"payment" : [NSNull null], - @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" - code:123 - userInfo:@{}]], - @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), - @"originalTransaction" : [NSNull null], - }; - OCMStub(mockQueue.transactions).andReturn(@[ [[SKPaymentTransactionStub alloc] - initWithMap:transactionMap] ]); - - __block NSArray *resultArray; - self.plugin.paymentQueueHandler = - [[FIAPaymentQueueHandler alloc] initWithQueue:mockQueue - transactionsUpdated:nil - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:nil - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - [self.plugin handleMethodCall:call - result:^(id r) { - resultArray = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqualObjects(resultArray, @[ transactionMap ]); -} - -- (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]; - 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]; - OCMVerify(times(1), [mockHandler stopObservingPaymentQueue]); -} - -- (void)testRegisterPaymentQueueDelegate { - if (@available(iOS 13, *)) { - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue registerDelegate]" - arguments:nil]; - - self.plugin.paymentQueueHandler = - [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueueStub new] - transactionsUpdated:nil - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:nil - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - - // Verify the delegate is nil before we register one. - XCTAssertNil(self.plugin.paymentQueueHandler.delegate); - - [self.plugin handleMethodCall:call - result:^(id r){ - }]; - - // Verify the delegate is not nil after we registered one. - XCTAssertNotNil(self.plugin.paymentQueueHandler.delegate); - } -} - -- (void)testRemovePaymentQueueDelegate { - if (@available(iOS 13, *)) { - FlutterMethodCall *call = - [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue removeDelegate]" - arguments:nil]; - - self.plugin.paymentQueueHandler = - [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueueStub new] - transactionsUpdated:nil - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:nil - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - self.plugin.paymentQueueHandler.delegate = OCMProtocolMock(@protocol(SKPaymentQueueDelegate)); - - // Verify the delegate is not nil before removing it. - XCTAssertNotNil(self.plugin.paymentQueueHandler.delegate); - - [self.plugin handleMethodCall:call - result:^(id r){ - }]; - - // Verify the delegate is nill after removing it. - XCTAssertNil(self.plugin.paymentQueueHandler.delegate); - } -} - -- (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){ - }]; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpartial-availability" - if (@available(iOS 13.4, *)) { - OCMVerify(times(1), [mockQueueHandler showPriceConsentIfNeeded]); - } else { - OCMVerify(never(), [mockQueueHandler showPriceConsentIfNeeded]); - } -#pragma clang diagnostic pop -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/InAppPurchasePluginTests.m new file mode 120000 index 000000000000..495146dde20b --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/InAppPurchasePluginTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/InAppPurchasePluginTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Info.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Info.plist deleted file mode 100644 index 6c40a6cd0c4a..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Info.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - - diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Info.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Info.plist new file mode 120000 index 000000000000..55acf210929a --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Info.plist @@ -0,0 +1 @@ +../../shared/RunnerTests/Info.plist \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/PaymentQueueTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/PaymentQueueTests.m deleted file mode 100644 index 2f8d5857c8d8..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/PaymentQueueTests.m +++ /dev/null @@ -1,420 +0,0 @@ -// 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. - -#import -#import -#import "Stubs.h" - -@import in_app_purchase_storekit; - -@interface PaymentQueueTest : XCTestCase - -@property(strong, nonatomic) NSDictionary *periodMap; -@property(strong, nonatomic) NSDictionary *discountMap; -@property(strong, nonatomic) NSDictionary *productMap; -@property(strong, nonatomic) NSDictionary *productResponseMap; - -@end - -@implementation PaymentQueueTest - -- (void)setUp { - self.periodMap = @{@"numberOfUnits" : @(0), @"unit" : @(0)}; - self.discountMap = @{ - @"price" : @1.0, - @"currencyCode" : @"USD", - @"numberOfPeriods" : @1, - @"subscriptionPeriod" : self.periodMap, - @"paymentMode" : @1 - }; - self.productMap = @{ - @"price" : @1.0, - @"currencyCode" : @"USD", - @"productIdentifier" : @"123", - @"localizedTitle" : @"title", - @"localizedDescription" : @"des", - @"subscriptionPeriod" : self.periodMap, - @"introductoryPrice" : self.discountMap, - @"subscriptionGroupIdentifier" : @"com.group" - }; - self.productResponseMap = - @{@"products" : @[ self.productMap ], @"invalidProductIdentifiers" : [NSNull null]}; -} - -- (void)testTransactionPurchased { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get purchased transcation."]; - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStatePurchased; - __block SKPaymentTransactionStub *tran; - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - SKPaymentTransaction *transaction = transactions[0]; - tran = (SKPaymentTransactionStub *)transaction; - [expectation fulfill]; - } - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler startObservingPaymentQueue]; - [handler addPayment:payment]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(tran.transactionState, SKPaymentTransactionStatePurchased); - XCTAssertEqual(tran.transactionIdentifier, @"fakeID"); -} - -- (void)testTransactionFailed { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get failed transcation."]; - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStateFailed; - __block SKPaymentTransactionStub *tran; - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - SKPaymentTransaction *transaction = transactions[0]; - tran = (SKPaymentTransactionStub *)transaction; - [expectation fulfill]; - } - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler startObservingPaymentQueue]; - [handler addPayment:payment]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(tran.transactionState, SKPaymentTransactionStateFailed); - XCTAssertEqual(tran.transactionIdentifier, nil); -} - -- (void)testTransactionRestored { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get restored transcation."]; - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStateRestored; - __block SKPaymentTransactionStub *tran; - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - SKPaymentTransaction *transaction = transactions[0]; - tran = (SKPaymentTransactionStub *)transaction; - [expectation fulfill]; - } - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler startObservingPaymentQueue]; - [handler addPayment:payment]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(tran.transactionState, SKPaymentTransactionStateRestored); - XCTAssertEqual(tran.transactionIdentifier, @"fakeID"); -} - -- (void)testTransactionPurchasing { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get purchasing transcation."]; - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStatePurchasing; - __block SKPaymentTransactionStub *tran; - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - SKPaymentTransaction *transaction = transactions[0]; - tran = (SKPaymentTransactionStub *)transaction; - [expectation fulfill]; - } - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler startObservingPaymentQueue]; - [handler addPayment:payment]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(tran.transactionState, SKPaymentTransactionStatePurchasing); - XCTAssertEqual(tran.transactionIdentifier, nil); -} - -- (void)testTransactionDeferred { - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get deffered transcation."]; - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStateDeferred; - __block SKPaymentTransactionStub *tran; - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - SKPaymentTransaction *transaction = transactions[0]; - tran = (SKPaymentTransactionStub *)transaction; - [expectation fulfill]; - } - transactionRemoved:nil - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler startObservingPaymentQueue]; - [handler addPayment:payment]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertEqual(tran.transactionState, SKPaymentTransactionStateDeferred); - XCTAssertEqual(tran.transactionIdentifier, nil); -} - -- (void)testFinishTransaction { - XCTestExpectation *expectation = - [self expectationWithDescription:@"handler.transactions should be empty."]; - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStateDeferred; - __block FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - XCTAssertEqual(transactions.count, 1); - SKPaymentTransaction *transaction = transactions[0]; - [handler finishTransaction:transaction]; - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - XCTAssertEqual(transactions.count, 1); - [expectation fulfill]; - } - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:nil - transactionCache:OCMClassMock(FIATransactionCache.class)]; - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler startObservingPaymentQueue]; - [handler addPayment:payment]; - [self waitForExpectations:@[ expectation ] timeout:5]; -} - -- (void)testStartObservingPaymentQueueShouldNotProcessTransactionsWhenCacheIsEmpty { - FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); - FIAPaymentQueueHandler *handler = - [[FIAPaymentQueueHandler alloc] initWithQueue:[[SKPaymentQueueStub alloc] init] - transactionsUpdated:^(NSArray *_Nonnull transactions) { - XCTFail("transactionsUpdated callback should not be called when cache is empty."); - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - XCTFail("transactionRemoved callback should not be called when cache is empty."); - } - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:^(NSArray *_Nonnull downloads) { - XCTFail("updatedDownloads callback should not be called when cache is empty."); - } - transactionCache:mockCache]; - - [handler startObservingPaymentQueue]; - - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); -} - -- (void) - testStartObservingPaymentQueueShouldNotProcessTransactionsWhenCacheContainsEmptyTransactionArrays { - FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); - FIAPaymentQueueHandler *handler = - [[FIAPaymentQueueHandler alloc] initWithQueue:[[SKPaymentQueueStub alloc] init] - transactionsUpdated:^(NSArray *_Nonnull transactions) { - XCTFail("transactionsUpdated callback should not be called when cache is empty."); - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - XCTFail("transactionRemoved callback should not be called when cache is empty."); - } - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:^(NSArray *_Nonnull downloads) { - XCTFail("updatedDownloads callback should not be called when cache is empty."); - } - transactionCache:mockCache]; - - OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]).andReturn(@[]); - OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]).andReturn(@[]); - OCMStub([mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]).andReturn(@[]); - - [handler startObservingPaymentQueue]; - - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); -} - -- (void)testStartObservingPaymentQueueShouldProcessTransactionsForItemsInCache { - XCTestExpectation *updateTransactionsExpectation = - [self expectationWithDescription: - @"transactionsUpdated callback should be called with one transaction."]; - XCTestExpectation *removeTransactionsExpectation = - [self expectationWithDescription: - @"transactionsRemoved callback should be called with one transaction."]; - XCTestExpectation *updateDownloadsExpectation = - [self expectationWithDescription: - @"downloadsUpdated callback should be called with one transaction."]; - SKPaymentTransaction *mockTransaction = OCMClassMock(SKPaymentTransaction.class); - SKDownload *mockDownload = OCMClassMock(SKDownload.class); - FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); - FIAPaymentQueueHandler *handler = - [[FIAPaymentQueueHandler alloc] initWithQueue:[[SKPaymentQueueStub alloc] init] - transactionsUpdated:^(NSArray *_Nonnull transactions) { - XCTAssertEqualObjects(transactions, @[ mockTransaction ]); - [updateTransactionsExpectation fulfill]; - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - XCTAssertEqualObjects(transactions, @[ mockTransaction ]); - [removeTransactionsExpectation fulfill]; - } - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:^(NSArray *_Nonnull downloads) { - XCTAssertEqualObjects(downloads, @[ mockDownload ]); - [updateDownloadsExpectation fulfill]; - } - transactionCache:mockCache]; - - OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]).andReturn(@[ - mockTransaction - ]); - OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]).andReturn(@[ - mockDownload - ]); - OCMStub([mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]).andReturn(@[ - mockTransaction - ]); - - [handler startObservingPaymentQueue]; - - [self waitForExpectations:@[ - updateTransactionsExpectation, removeTransactionsExpectation, updateDownloadsExpectation - ] - timeout:5]; - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); - OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); - OCMVerify(times(1), [mockCache clear]); -} - -- (void)testTransactionsShouldBeCachedWhenNotObserving { - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - XCTFail("transactionsUpdated callback should not be called when cache is empty."); - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - XCTFail("transactionRemoved callback should not be called when cache is empty."); - } - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:^(NSArray *_Nonnull downloads) { - XCTFail("updatedDownloads callback should not be called when cache is empty."); - } - transactionCache:mockCache]; - - SKPayment *payment = - [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; - [handler addPayment:payment]; - - OCMVerify(times(1), [mockCache addObjects:[OCMArg any] - forKey:TransactionCacheKeyUpdatedTransactions]); - OCMVerify(never(), [mockCache addObjects:[OCMArg any] - forKey:TransactionCacheKeyUpdatedDownloads]); - OCMVerify(never(), [mockCache addObjects:[OCMArg any] - forKey:TransactionCacheKeyRemovedTransactions]); -} - -- (void)testTransactionsShouldNotBeCachedWhenObserving { - XCTestExpectation *updateTransactionsExpectation = - [self expectationWithDescription: - @"transactionsUpdated callback should be called with one transaction."]; - XCTestExpectation *removeTransactionsExpectation = - [self expectationWithDescription: - @"transactionsRemoved callback should be called with one transaction."]; - XCTestExpectation *updateDownloadsExpectation = - [self expectationWithDescription: - @"downloadsUpdated callback should be called with one transaction."]; - SKPaymentTransaction *mockTransaction = OCMClassMock(SKPaymentTransaction.class); - SKDownload *mockDownload = OCMClassMock(SKDownload.class); - SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; - queue.testState = SKPaymentTransactionStatePurchased; - FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); - FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:^(NSArray *_Nonnull transactions) { - XCTAssertEqualObjects(transactions, @[ mockTransaction ]); - [updateTransactionsExpectation fulfill]; - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - XCTAssertEqualObjects(transactions, @[ mockTransaction ]); - [removeTransactionsExpectation fulfill]; - } - restoreTransactionFailed:nil - restoreCompletedTransactionsFinished:nil - shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { - return YES; - } - updatedDownloads:^(NSArray *_Nonnull downloads) { - XCTAssertEqualObjects(downloads, @[ mockDownload ]); - [updateDownloadsExpectation fulfill]; - } - transactionCache:mockCache]; - - [handler startObservingPaymentQueue]; - [handler paymentQueue:queue updatedTransactions:@[ mockTransaction ]]; - [handler paymentQueue:queue removedTransactions:@[ mockTransaction ]]; - [handler paymentQueue:queue updatedDownloads:@[ mockDownload ]]; - - [self waitForExpectations:@[ - updateTransactionsExpectation, removeTransactionsExpectation, updateDownloadsExpectation - ] - timeout:5]; - OCMVerify(never(), [mockCache addObjects:[OCMArg any] - forKey:TransactionCacheKeyUpdatedTransactions]); - OCMVerify(never(), [mockCache addObjects:[OCMArg any] - forKey:TransactionCacheKeyUpdatedDownloads]); - OCMVerify(never(), [mockCache addObjects:[OCMArg any] - forKey:TransactionCacheKeyRemovedTransactions]); -} -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/PaymentQueueTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/PaymentQueueTests.m new file mode 120000 index 000000000000..f207cda68945 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/PaymentQueueTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/PaymentQueueTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/ProductRequestHandlerTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/ProductRequestHandlerTests.m deleted file mode 100644 index ac36aae5acb5..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/ProductRequestHandlerTests.m +++ /dev/null @@ -1,89 +0,0 @@ -// 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. - -#import -#import "Stubs.h" - -@import in_app_purchase_storekit; - -#pragma tests start here - -@interface RequestHandlerTest : XCTestCase - -@end - -@implementation RequestHandlerTest - -- (void)testRequestHandlerWithProductRequestSuccess { - SKProductRequestStub *request = - [[SKProductRequestStub alloc] initWithProductIdentifiers:[NSSet setWithArray:@[ @"123" ]]]; - FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get response with 1 product"]; - __block SKProductsResponse *response; - [handler - startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *error) { - response = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertNotNil(response); - XCTAssertEqual(response.products.count, 1); - SKProduct *product = response.products.firstObject; - XCTAssertTrue([product.productIdentifier isEqualToString:@"123"]); -} - -- (void)testRequestHandlerWithProductRequestFailure { - SKProductRequestStub *request = [[SKProductRequestStub alloc] - initWithFailureError:[NSError errorWithDomain:@"test" code:123 userInfo:@{}]]; - FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; - XCTestExpectation *expectation = - [self expectationWithDescription:@"expect to get response with 1 product"]; - __block NSError *error; - __block SKProductsResponse *response; - [handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *e) { - error = e; - response = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertNotNil(error); - XCTAssertEqual(error.domain, @"test"); - XCTAssertNil(response); -} - -- (void)testRequestHandlerWithRefreshReceiptSuccess { - SKReceiptRefreshRequestStub *request = - [[SKReceiptRefreshRequestStub alloc] initWithReceiptProperties:nil]; - FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; - XCTestExpectation *expectation = [self expectationWithDescription:@"expect no error"]; - __block NSError *e; - [handler - startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *error) { - e = error; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertNil(e); -} - -- (void)testRequestHandlerWithRefreshReceiptFailure { - SKReceiptRefreshRequestStub *request = [[SKReceiptRefreshRequestStub alloc] - initWithFailureError:[NSError errorWithDomain:@"test" code:123 userInfo:@{}]]; - FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; - XCTestExpectation *expectation = [self expectationWithDescription:@"expect error"]; - __block NSError *error; - __block SKProductsResponse *response; - [handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *e) { - error = e; - response = r; - [expectation fulfill]; - }]; - [self waitForExpectations:@[ expectation ] timeout:5]; - XCTAssertNotNil(error); - XCTAssertEqual(error.domain, @"test"); - XCTAssertNil(response); -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/ProductRequestHandlerTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/ProductRequestHandlerTests.m new file mode 120000 index 000000000000..f186e1122526 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/ProductRequestHandlerTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/ProductRequestHandlerTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.h b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.h deleted file mode 100644 index d4e8df3eba72..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.h +++ /dev/null @@ -1,71 +0,0 @@ -// 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. - -#import -#import - -@import in_app_purchase_storekit; - -NS_ASSUME_NONNULL_BEGIN -API_AVAILABLE(ios(11.2), macos(10.13.2)) -@interface SKProductSubscriptionPeriodStub : SKProductSubscriptionPeriod -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -API_AVAILABLE(ios(11.2), macos(10.13.2)) -@interface SKProductDiscountStub : SKProductDiscount -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -@interface SKProductStub : SKProduct -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -@interface SKProductRequestStub : SKProductsRequest -- (instancetype)initWithProductIdentifiers:(NSSet *)productIdentifiers; -- (instancetype)initWithFailureError:(NSError *)error; -@end - -@interface SKProductsResponseStub : SKProductsResponse -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -@interface InAppPurchasePluginStub : InAppPurchasePlugin -@end - -@interface SKPaymentQueueStub : SKPaymentQueue -@property(assign, nonatomic) SKPaymentTransactionState testState; -@property(strong, nonatomic, nullable) id observer; -@end - -@interface SKPaymentTransactionStub : SKPaymentTransaction -- (instancetype)initWithMap:(NSDictionary *)map; -- (instancetype)initWithState:(SKPaymentTransactionState)state; -- (instancetype)initWithState:(SKPaymentTransactionState)state payment:(SKPayment *)payment; -@end - -@interface SKMutablePaymentStub : SKMutablePayment -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -@interface NSErrorStub : NSError -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -@interface FIAPReceiptManagerStub : FIAPReceiptManager -// Indicates whether getReceiptData of this stub is going to return an error. -// Setting this to true will let getReceiptData give a basic NSError and return nil. -@property(assign, nonatomic) BOOL returnError; -@end - -@interface SKReceiptRefreshRequestStub : SKReceiptRefreshRequest -- (instancetype)initWithFailureError:(NSError *)error; -@end - -API_AVAILABLE(ios(13.0), macos(10.15)) -@interface SKStorefrontStub : SKStorefront -- (instancetype)initWithMap:(NSDictionary *)map; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.h b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.h new file mode 120000 index 000000000000..420bd56538d1 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.h @@ -0,0 +1 @@ +../../shared/RunnerTests/Stubs.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.m deleted file mode 100644 index f5e44d78b157..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.m +++ /dev/null @@ -1,330 +0,0 @@ -// 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. - -#import "Stubs.h" - -@implementation SKProductSubscriptionPeriodStub - -- (instancetype)initWithMap:(NSDictionary *)map { - self = [super init]; - if (self) { - [self setValue:map[@"numberOfUnits"] ?: @(0) forKey:@"numberOfUnits"]; - [self setValue:map[@"unit"] ?: @(0) forKey:@"unit"]; - } - return self; -} - -@end - -@implementation SKProductDiscountStub - -- (instancetype)initWithMap:(NSDictionary *)map { - self = [super init]; - if (self) { - [self setValue:[[NSDecimalNumber alloc] initWithString:map[@"price"]] ?: [NSNull null] - forKey:@"price"]; - NSLocale *locale = NSLocale.systemLocale; - [self setValue:locale ?: [NSNull null] forKey:@"priceLocale"]; - [self setValue:map[@"numberOfPeriods"] ?: @(0) forKey:@"numberOfPeriods"]; - SKProductSubscriptionPeriodStub *subscriptionPeriodSub = - [[SKProductSubscriptionPeriodStub alloc] initWithMap:map[@"subscriptionPeriod"]]; - [self setValue:subscriptionPeriodSub forKey:@"subscriptionPeriod"]; - [self setValue:map[@"paymentMode"] ?: @(0) forKey:@"paymentMode"]; - if (@available(iOS 12.2, *)) { - [self setValue:map[@"identifier"] ?: [NSNull null] forKey:@"identifier"]; - [self setValue:map[@"type"] ?: @(0) forKey:@"type"]; - } - } - return self; -} - -@end - -@implementation SKProductStub - -- (instancetype)initWithMap:(NSDictionary *)map { - self = [super init]; - if (self) { - [self setValue:map[@"productIdentifier"] ?: [NSNull null] forKey:@"productIdentifier"]; - [self setValue:map[@"localizedDescription"] ?: [NSNull null] forKey:@"localizedDescription"]; - [self setValue:map[@"localizedTitle"] ?: [NSNull null] forKey:@"localizedTitle"]; - [self setValue:map[@"downloadable"] ?: @NO forKey:@"downloadable"]; - [self setValue:[[NSDecimalNumber alloc] initWithString:map[@"price"]] ?: [NSNull null] - forKey:@"price"]; - NSLocale *locale = NSLocale.systemLocale; - [self setValue:locale ?: [NSNull null] forKey:@"priceLocale"]; - [self setValue:map[@"downloadContentLengths"] ?: @(0) forKey:@"downloadContentLengths"]; - if (@available(iOS 11.2, *)) { - SKProductSubscriptionPeriodStub *period = - [[SKProductSubscriptionPeriodStub alloc] initWithMap:map[@"subscriptionPeriod"]]; - [self setValue:period ?: [NSNull null] forKey:@"subscriptionPeriod"]; - SKProductDiscountStub *discount = - [[SKProductDiscountStub alloc] initWithMap:map[@"introductoryPrice"]]; - [self setValue:discount ?: [NSNull null] forKey:@"introductoryPrice"]; - [self setValue:map[@"subscriptionGroupIdentifier"] ?: [NSNull null] - forKey:@"subscriptionGroupIdentifier"]; - } - if (@available(iOS 12.2, *)) { - NSMutableArray *discounts = [[NSMutableArray alloc] init]; - for (NSDictionary *discountMap in map[@"discounts"]) { - [discounts addObject:[[SKProductDiscountStub alloc] initWithMap:discountMap]]; - } - - [self setValue:discounts forKey:@"discounts"]; - } - } - return self; -} - -- (instancetype)initWithProductID:(NSString *)productIdentifier { - self = [super init]; - if (self) { - [self setValue:productIdentifier forKey:@"productIdentifier"]; - } - return self; -} - -@end - -@interface SKProductRequestStub () - -@property(strong, nonatomic) NSSet *identifers; -@property(strong, nonatomic) NSError *error; - -@end - -@implementation SKProductRequestStub - -- (instancetype)initWithProductIdentifiers:(NSSet *)productIdentifiers { - self = [super initWithProductIdentifiers:productIdentifiers]; - self.identifers = productIdentifiers; - return self; -} - -- (instancetype)initWithFailureError:(NSError *)error { - self = [super init]; - self.error = error; - return self; -} - -- (void)start { - NSMutableArray *productArray = [NSMutableArray new]; - for (NSString *identifier in self.identifers) { - [productArray addObject:@{@"productIdentifier" : identifier}]; - } - SKProductsResponseStub *response = - [[SKProductsResponseStub alloc] initWithMap:@{@"products" : productArray}]; - if (self.error) { - [self.delegate request:self didFailWithError:self.error]; - } else { - [self.delegate productsRequest:self didReceiveResponse:response]; - } -} - -@end - -@implementation SKProductsResponseStub - -- (instancetype)initWithMap:(NSDictionary *)map { - self = [super init]; - if (self) { - NSMutableArray *products = [NSMutableArray new]; - for (NSDictionary *productMap in map[@"products"]) { - SKProductStub *product = [[SKProductStub alloc] initWithMap:productMap]; - [products addObject:product]; - } - [self setValue:products forKey:@"products"]; - } - return self; -} - -@end - -@interface InAppPurchasePluginStub () - -@end - -@implementation InAppPurchasePluginStub - -- (SKProductRequestStub *)getProductRequestWithIdentifiers:(NSSet *)identifiers { - return [[SKProductRequestStub alloc] initWithProductIdentifiers:identifiers]; -} - -- (SKProduct *)getProduct:(NSString *)productID { - return [[SKProductStub alloc] initWithProductID:productID]; -} - -- (SKReceiptRefreshRequestStub *)getRefreshReceiptRequest:(NSDictionary *)properties { - return [[SKReceiptRefreshRequestStub alloc] initWithReceiptProperties:properties]; -} - -@end - -@interface SKPaymentQueueStub () - -@end - -@implementation SKPaymentQueueStub - -- (void)addTransactionObserver:(id)observer { - self.observer = observer; -} - -- (void)removeTransactionObserver:(id)observer { - self.observer = nil; -} - -- (void)addPayment:(SKPayment *)payment { - SKPaymentTransactionStub *transaction = - [[SKPaymentTransactionStub alloc] initWithState:self.testState payment:payment]; - [self.observer paymentQueue:self updatedTransactions:@[ transaction ]]; -} - -- (void)restoreCompletedTransactions { - if ([self.observer - respondsToSelector:@selector(paymentQueueRestoreCompletedTransactionsFinished:)]) { - [self.observer paymentQueueRestoreCompletedTransactionsFinished:self]; - } -} - -- (void)finishTransaction:(SKPaymentTransaction *)transaction { - if ([self.observer respondsToSelector:@selector(paymentQueue:removedTransactions:)]) { - [self.observer paymentQueue:self removedTransactions:@[ transaction ]]; - } -} - -@end - -@implementation SKPaymentTransactionStub { - SKPayment *_payment; -} - -- (instancetype)initWithID:(NSString *)identifier { - self = [super init]; - if (self) { - [self setValue:identifier forKey:@"transactionIdentifier"]; - } - return self; -} - -- (instancetype)initWithMap:(NSDictionary *)map { - self = [super init]; - if (self) { - [self setValue:map[@"transactionIdentifier"] forKey:@"transactionIdentifier"]; - [self setValue:map[@"transactionState"] forKey:@"transactionState"]; - if (![map[@"originalTransaction"] isKindOfClass:[NSNull class]] && - map[@"originalTransaction"]) { - [self setValue:[[SKPaymentTransactionStub alloc] initWithMap:map[@"originalTransaction"]] - forKey:@"originalTransaction"]; - } - [self setValue:map[@"error"] ? [[NSErrorStub alloc] initWithMap:map[@"error"]] : [NSNull null] - forKey:@"error"]; - [self setValue:[NSDate dateWithTimeIntervalSince1970:[map[@"transactionTimeStamp"] doubleValue]] - forKey:@"transactionDate"]; - } - return self; -} - -- (instancetype)initWithState:(SKPaymentTransactionState)state { - self = [super init]; - if (self) { - // Only purchased and restored transactions have transactionIdentifier: - // https://developer.apple.com/documentation/storekit/skpaymenttransaction/1411288-transactionidentifier?language=objc - if (state == SKPaymentTransactionStatePurchased || state == SKPaymentTransactionStateRestored) { - [self setValue:@"fakeID" forKey:@"transactionIdentifier"]; - } - [self setValue:@(state) forKey:@"transactionState"]; - } - return self; -} - -- (instancetype)initWithState:(SKPaymentTransactionState)state payment:(SKPayment *)payment { - self = [super init]; - if (self) { - // Only purchased and restored transactions have transactionIdentifier: - // https://developer.apple.com/documentation/storekit/skpaymenttransaction/1411288-transactionidentifier?language=objc - if (state == SKPaymentTransactionStatePurchased || state == SKPaymentTransactionStateRestored) { - [self setValue:@"fakeID" forKey:@"transactionIdentifier"]; - } - [self setValue:@(state) forKey:@"transactionState"]; - _payment = payment; - } - return self; -} - -- (SKPayment *)payment { - return _payment; -} - -@end - -@implementation NSErrorStub - -- (instancetype)initWithMap:(NSDictionary *)map { - return [self initWithDomain:[map objectForKey:@"domain"] - code:[[map objectForKey:@"code"] integerValue] - userInfo:[map objectForKey:@"userInfo"]]; -} - -@end - -@implementation FIAPReceiptManagerStub : FIAPReceiptManager - -- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error { - if (self.returnError) { - *error = [NSError errorWithDomain:@"test" - code:1 - userInfo:@{ - @"name" : @"test", - @"houseNr" : @5, - @"error" : [[NSError alloc] initWithDomain:@"internalTestDomain" - code:99 - userInfo:nil] - }]; - return nil; - } - NSString *originalString = [NSString stringWithFormat:@"test"]; - return [[NSData alloc] initWithBase64EncodedString:originalString options:kNilOptions]; -} - -@end - -@implementation SKReceiptRefreshRequestStub { - NSError *_error; -} - -- (instancetype)initWithReceiptProperties:(NSDictionary *)properties { - self = [super initWithReceiptProperties:properties]; - return self; -} - -- (instancetype)initWithFailureError:(NSError *)error { - self = [super init]; - _error = error; - return self; -} - -- (void)start { - if (_error) { - [self.delegate request:self didFailWithError:_error]; - } else { - [self.delegate requestDidFinish:self]; - } -} - -@end - -@implementation SKStorefrontStub - -- (instancetype)initWithMap:(NSDictionary *)map { - self = [super init]; - if (self) { - // Set stub values - [self setValue:map[@"countryCode"] forKey:@"countryCode"]; - [self setValue:map[@"identifier"] forKey:@"identifier"]; - } - return self; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.m new file mode 120000 index 000000000000..eee9d6b331a9 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/Stubs.m @@ -0,0 +1 @@ +../../shared/RunnerTests/Stubs.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/TranslatorTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/TranslatorTests.m deleted file mode 100644 index 34d686753762..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/TranslatorTests.m +++ /dev/null @@ -1,416 +0,0 @@ -// 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. - -#import -#import "Stubs.h" - -@import in_app_purchase_storekit; - -@interface TranslatorTest : XCTestCase - -@property(strong, nonatomic) NSDictionary *periodMap; -@property(strong, nonatomic) NSMutableDictionary *discountMap; -@property(strong, nonatomic) NSMutableDictionary *discountMissingIdentifierMap; -@property(strong, nonatomic) NSMutableDictionary *productMap; -@property(strong, nonatomic) NSDictionary *productResponseMap; -@property(strong, nonatomic) NSDictionary *paymentMap; -@property(copy, nonatomic) NSDictionary *paymentDiscountMap; -@property(strong, nonatomic) NSDictionary *transactionMap; -@property(strong, nonatomic) NSDictionary *errorMap; -@property(strong, nonatomic) NSDictionary *localeMap; -@property(strong, nonatomic) NSDictionary *storefrontMap; -@property(strong, nonatomic) NSDictionary *storefrontAndPaymentTransactionMap; - -@end - -@implementation TranslatorTest - -- (void)setUp { - self.periodMap = @{@"numberOfUnits" : @(0), @"unit" : @(0)}; - - self.discountMap = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"price" : @"1", - @"priceLocale" : [FIAObjectTranslator getMapFromNSLocale:NSLocale.systemLocale], - @"numberOfPeriods" : @1, - @"subscriptionPeriod" : self.periodMap, - @"paymentMode" : @1, - }]; - if (@available(iOS 12.2, *)) { - self.discountMap[@"identifier"] = @"test offer id"; - self.discountMap[@"type"] = @(SKProductDiscountTypeIntroductory); - } - self.discountMissingIdentifierMap = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"price" : @"1", - @"priceLocale" : [FIAObjectTranslator getMapFromNSLocale:NSLocale.systemLocale], - @"numberOfPeriods" : @1, - @"subscriptionPeriod" : self.periodMap, - @"paymentMode" : @1, - @"identifier" : [NSNull null], - @"type" : @0, - }]; - - self.productMap = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"price" : @"1", - @"priceLocale" : [FIAObjectTranslator getMapFromNSLocale:NSLocale.systemLocale], - @"productIdentifier" : @"123", - @"localizedTitle" : @"title", - @"localizedDescription" : @"des", - }]; - if (@available(iOS 11.2, *)) { - self.productMap[@"subscriptionPeriod"] = self.periodMap; - self.productMap[@"introductoryPrice"] = self.discountMap; - } - if (@available(iOS 12.2, *)) { - self.productMap[@"discounts"] = @[ self.discountMap ]; - } - - if (@available(iOS 12.0, *)) { - self.productMap[@"subscriptionGroupIdentifier"] = @"com.group"; - } - - self.productResponseMap = - @{@"products" : @[ self.productMap ], @"invalidProductIdentifiers" : @[]}; - self.paymentMap = @{ - @"productIdentifier" : @"123", - @"requestData" : @"abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh", - @"quantity" : @(2), - @"applicationUsername" : @"app user name", - @"simulatesAskToBuyInSandbox" : @(NO) - }; - self.paymentDiscountMap = @{ - @"identifier" : @"payment_discount_identifier", - @"keyIdentifier" : @"payment_discount_key_identifier", - @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", - @"signature" : @"this is a encrypted signature", - @"timestamp" : @([NSDate date].timeIntervalSince1970), - }; - NSDictionary *originalTransactionMap = @{ - @"transactionIdentifier" : @"567", - @"transactionState" : @(SKPaymentTransactionStatePurchasing), - @"payment" : [NSNull null], - @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" - code:123 - userInfo:@{}]], - @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), - @"originalTransaction" : [NSNull null], - }; - self.transactionMap = @{ - @"transactionIdentifier" : @"567", - @"transactionState" : @(SKPaymentTransactionStatePurchasing), - @"payment" : [NSNull null], - @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" - code:123 - userInfo:@{}]], - @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), - @"originalTransaction" : originalTransactionMap, - }; - self.errorMap = @{ - @"code" : @(123), - @"domain" : @"test_domain", - @"userInfo" : @{ - @"key" : @"value", - } - }; - self.storefrontMap = @{ - @"countryCode" : @"USA", - @"identifier" : @"unique_identifier", - }; - - self.storefrontAndPaymentTransactionMap = @{ - @"storefront" : self.storefrontMap, - @"transaction" : self.transactionMap, - }; -} - -- (void)testSKProductSubscriptionPeriodStubToMap { - if (@available(iOS 11.2, *)) { - SKProductSubscriptionPeriodStub *period = - [[SKProductSubscriptionPeriodStub alloc] initWithMap:self.periodMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKProductSubscriptionPeriod:period]; - XCTAssertEqualObjects(map, self.periodMap); - } -} - -- (void)testSKProductDiscountStubToMap { - if (@available(iOS 11.2, *)) { - SKProductDiscountStub *discount = [[SKProductDiscountStub alloc] initWithMap:self.discountMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKProductDiscount:discount]; - XCTAssertEqualObjects(map, self.discountMap); - } -} - -- (void)testProductToMap { - SKProductStub *product = [[SKProductStub alloc] initWithMap:self.productMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKProduct:product]; - XCTAssertEqualObjects(map, self.productMap); -} - -- (void)testProductResponseToMap { - SKProductsResponseStub *response = - [[SKProductsResponseStub alloc] initWithMap:self.productResponseMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKProductsResponse:response]; - XCTAssertEqualObjects(map, self.productResponseMap); -} - -- (void)testPaymentToMap { - SKMutablePayment *payment = [FIAObjectTranslator getSKMutablePaymentFromMap:self.paymentMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKPayment:payment]; - XCTAssertEqualObjects(map, self.paymentMap); -} - -- (void)testPaymentTransactionToMap { - // payment is not KVC, cannot test payment field. - SKPaymentTransactionStub *paymentTransaction = - [[SKPaymentTransactionStub alloc] initWithMap:self.transactionMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKPaymentTransaction:paymentTransaction]; - XCTAssertEqualObjects(map, self.transactionMap); -} - -- (void)testError { - NSErrorStub *error = [[NSErrorStub alloc] initWithMap:self.errorMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error]; - XCTAssertEqualObjects(map, self.errorMap); -} - -- (void)testErrorWithNSNumberAsUserInfo { - NSError *error = [NSError errorWithDomain:SKErrorDomain code:3 userInfo:@{@"key" : @42}]; - NSDictionary *expectedMap = - @{@"domain" : SKErrorDomain, @"code" : @3, @"userInfo" : @{@"key" : @42}}; - NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error]; - XCTAssertEqualObjects(expectedMap, map); -} - -- (void)testErrorWithMultipleUnderlyingErrors { - NSError *underlyingErrorOne = [NSError errorWithDomain:SKErrorDomain code:2 userInfo:nil]; - NSError *underlyingErrorTwo = [NSError errorWithDomain:SKErrorDomain code:1 userInfo:nil]; - NSError *mainError = [NSError - errorWithDomain:SKErrorDomain - code:3 - userInfo:@{@"underlyingErrors" : @[ underlyingErrorOne, underlyingErrorTwo ]}]; - NSDictionary *expectedMap = @{ - @"domain" : SKErrorDomain, - @"code" : @3, - @"userInfo" : @{ - @"underlyingErrors" : @[ - @{@"domain" : SKErrorDomain, @"code" : @2, @"userInfo" : @{}}, - @{@"domain" : SKErrorDomain, @"code" : @1, @"userInfo" : @{}} - ] - } - }; - NSDictionary *map = [FIAObjectTranslator getMapFromNSError:mainError]; - XCTAssertEqualObjects(expectedMap, map); -} - -- (void)testErrorWithUnsupportedUserInfo { - NSError *error = [NSError errorWithDomain:SKErrorDomain - code:3 - userInfo:@{@"user_info" : [[NSObject alloc] init]}]; - NSDictionary *expectedMap = @{ - @"domain" : SKErrorDomain, - @"code" : @3, - @"userInfo" : @{ - @"user_info" : [NSString - stringWithFormat: - @"Unable to encode native userInfo object of type %@ to map. Please submit an " - @"issue at https://github.com/flutter/flutter/issues/new with the title " - @"\"[in_app_purchase_storekit] Unable to encode userInfo of type %@\" and add " - @"reproduction steps and the error details in the description field.", - [NSObject class], [NSObject class]] - } - }; - NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error]; - XCTAssertEqualObjects(expectedMap, map); -} - -- (void)testLocaleToMap { - if (@available(iOS 10.0, *)) { - NSLocale *system = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; - NSDictionary *map = [FIAObjectTranslator getMapFromNSLocale:system]; - XCTAssertEqualObjects(map[@"currencySymbol"], system.currencySymbol); - XCTAssertEqualObjects(map[@"countryCode"], system.countryCode); - } -} - -- (void)testSKStorefrontToMap { - if (@available(iOS 13.0, *)) { - SKStorefront *storefront = [[SKStorefrontStub alloc] initWithMap:self.storefrontMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKStorefront:storefront]; - XCTAssertEqualObjects(map, self.storefrontMap); - } -} - -- (void)testSKStorefrontAndSKPaymentTransactionToMap { - if (@available(iOS 13.0, *)) { - SKStorefront *storefront = [[SKStorefrontStub alloc] initWithMap:self.storefrontMap]; - SKPaymentTransaction *transaction = - [[SKPaymentTransactionStub alloc] initWithMap:self.transactionMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKStorefront:storefront - andSKPaymentTransaction:transaction]; - XCTAssertEqualObjects(map, self.storefrontAndPaymentTransactionMap); - } -} - -- (void)testSKPaymentDiscountFromMap { - if (@available(iOS 12.2, *)) { - NSString *error = nil; - SKPaymentDiscount *paymentDiscount = - [FIAObjectTranslator getSKPaymentDiscountFromMap:self.paymentDiscountMap withError:&error]; - - XCTAssertEqual(paymentDiscount.identifier, self.paymentDiscountMap[@"identifier"]); - XCTAssertEqual(paymentDiscount.keyIdentifier, self.paymentDiscountMap[@"keyIdentifier"]); - XCTAssertEqualObjects(paymentDiscount.nonce, - [[NSUUID alloc] initWithUUIDString:self.paymentDiscountMap[@"nonce"]]); - XCTAssertEqual(paymentDiscount.signature, self.paymentDiscountMap[@"signature"]); - XCTAssertEqual(paymentDiscount.timestamp, self.paymentDiscountMap[@"timestamp"]); - } -} - -- (void)testSKPaymentDiscountFromMapMissingIdentifier { - if (@available(iOS 12.2, *)) { - NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; - - for (id value in invalidValues) { - NSDictionary *discountMap = @{ - @"identifier" : value, - @"keyIdentifier" : @"payment_discount_key_identifier", - @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", - @"signature" : @"this is a encrypted signature", - @"timestamp" : @([NSDate date].timeIntervalSince1970), - }; - - NSString *error = nil; - [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; - - XCTAssertNotNil(error); - XCTAssertEqualObjects( - error, @"When specifying a payment discount the 'identifier' field is mandatory."); - } - } -} - -- (void)testGetMapFromSKProductDiscountMissingIdentifier { - if (@available(iOS 12.2, *)) { - SKProductDiscountStub *discount = - [[SKProductDiscountStub alloc] initWithMap:self.discountMissingIdentifierMap]; - NSDictionary *map = [FIAObjectTranslator getMapFromSKProductDiscount:discount]; - XCTAssertEqualObjects(map, self.discountMissingIdentifierMap); - } -} - -- (void)testSKPaymentDiscountFromMapMissingKeyIdentifier { - if (@available(iOS 12.2, *)) { - NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; - - for (id value in invalidValues) { - NSDictionary *discountMap = @{ - @"identifier" : @"payment_discount_identifier", - @"keyIdentifier" : value, - @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", - @"signature" : @"this is a encrypted signature", - @"timestamp" : @([NSDate date].timeIntervalSince1970), - }; - - NSString *error = nil; - [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; - - XCTAssertNotNil(error); - XCTAssertEqualObjects( - error, @"When specifying a payment discount the 'keyIdentifier' field is mandatory."); - } - } -} - -- (void)testSKPaymentDiscountFromMapMissingNonce { - if (@available(iOS 12.2, *)) { - NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; - - for (id value in invalidValues) { - NSDictionary *discountMap = @{ - @"identifier" : @"payment_discount_identifier", - @"keyIdentifier" : @"payment_discount_key_identifier", - @"nonce" : value, - @"signature" : @"this is a encrypted signature", - @"timestamp" : @([NSDate date].timeIntervalSince1970), - }; - - NSString *error = nil; - [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; - - XCTAssertNotNil(error); - XCTAssertEqualObjects(error, - @"When specifying a payment discount the 'nonce' field is mandatory."); - } - } -} - -- (void)testSKPaymentDiscountFromMapMissingSignature { - if (@available(iOS 12.2, *)) { - NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; - - for (id value in invalidValues) { - NSDictionary *discountMap = @{ - @"identifier" : @"payment_discount_identifier", - @"keyIdentifier" : @"payment_discount_key_identifier", - @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", - @"signature" : value, - @"timestamp" : @([NSDate date].timeIntervalSince1970), - }; - - NSString *error = nil; - [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; - - XCTAssertNotNil(error); - XCTAssertEqualObjects( - error, @"When specifying a payment discount the 'signature' field is mandatory."); - } - } -} - -- (void)testSKPaymentDiscountFromMapMissingTimestamp { - if (@available(iOS 12.2, *)) { - NSArray *invalidValues = @[ [NSNull null], @"", @(-1) ]; - - for (id value in invalidValues) { - NSDictionary *discountMap = @{ - @"identifier" : @"payment_discount_identifier", - @"keyIdentifier" : @"payment_discount_key_identifier", - @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", - @"signature" : @"this is a encrypted signature", - @"timestamp" : value, - }; - - NSString *error = nil; - [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; - - XCTAssertNotNil(error); - XCTAssertEqualObjects( - error, @"When specifying a payment discount the 'timestamp' field is mandatory."); - } - } -} - -- (void)testSKPaymentDiscountFromMapOverflowingTimestamp { - if (@available(iOS 12.2, *)) { - NSDictionary *discountMap = @{ - @"identifier" : @"payment_discount_identifier", - @"keyIdentifier" : @"payment_discount_key_identifier", - @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", - @"signature" : @"this is a encrypted signature", - @"timestamp" : @1665044583595, // timestamp 2022 Oct - }; - NSString *error = nil; - SKPaymentDiscount *paymentDiscount = - [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; - XCTAssertNil(error); - XCTAssertNotNil(paymentDiscount); - XCTAssertEqual(paymentDiscount.identifier, discountMap[@"identifier"]); - XCTAssertEqual(paymentDiscount.keyIdentifier, discountMap[@"keyIdentifier"]); - XCTAssertEqualObjects(paymentDiscount.nonce, - [[NSUUID alloc] initWithUUIDString:discountMap[@"nonce"]]); - XCTAssertEqual(paymentDiscount.signature, discountMap[@"signature"]); - XCTAssertEqual(paymentDiscount.timestamp, discountMap[@"timestamp"]); - } -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/TranslatorTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/TranslatorTests.m new file mode 120000 index 000000000000..ac58ed96972e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/ios/RunnerTests/TranslatorTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/TranslatorTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Flutter/Flutter-Debug.xcconfig b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 000000000000..4b81f9b2d200 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Flutter/Flutter-Release.xcconfig b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 000000000000..5caa9d1579e4 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Podfile b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Podfile new file mode 100644 index 000000000000..04238b6a5f2c --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Podfile @@ -0,0 +1,46 @@ +platform :osx, '10.15' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) + + target 'RunnerTests' do + inherit! :search_paths + + pod 'OCMock', '~> 3.6' + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 000000000000..7e30d1fa4c1d --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,883 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; + A2C6CD5797E6A6721FDBCA1C /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36DEEA66738F64D983F76848 /* Pods_Runner.framework */; }; + C51E64432925727D7AC7BBFF /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE8A421F08C80BE6E90142D5 /* Pods_RunnerTests.framework */; }; + F79BDC102905FBE300E3999D /* FIAPPaymentQueueDeleteTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC0F2905FBE300E3999D /* FIAPPaymentQueueDeleteTests.m */; }; + F79BDC122905FBF700E3999D /* FIATransactionCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC112905FBF700E3999D /* FIATransactionCacheTests.m */; }; + F79BDC142905FBFE00E3999D /* InAppPurchasePluginTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC132905FBFE00E3999D /* InAppPurchasePluginTests.m */; }; + F79BDC182905FC1800E3999D /* PaymentQueueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC172905FC1800E3999D /* PaymentQueueTests.m */; }; + F79BDC1A2905FC1F00E3999D /* ProductRequestHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC192905FC1F00E3999D /* ProductRequestHandlerTests.m */; }; + F79BDC1C2905FC3200E3999D /* Stubs.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC1B2905FC3200E3999D /* Stubs.m */; }; + F79BDC1E2905FC3900E3999D /* TranslatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F79BDC1D2905FC3900E3999D /* TranslatorTests.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; + F700DD0628E652A10004836B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC10EC2044A3C60003C045; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 36DEEA66738F64D983F76848 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4E423AE82F466005587C3567 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; + 5E5D46173E3025B0DB32A1BE /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; + 5EBC5A8BA44B08330BA605AB /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; + 62F1680C5AE033907C1DF7AB /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; + 9A4FEABF1DEF0D106FEB7974 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + B6C8FD76BB3278AA51FED870 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + EE8A421F08C80BE6E90142D5 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + F700DD0228E652A10004836B /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + F79BDC0F2905FBE300E3999D /* FIAPPaymentQueueDeleteTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FIAPPaymentQueueDeleteTests.m; path = ../../shared/RunnerTests/FIAPPaymentQueueDeleteTests.m; sourceTree = ""; }; + F79BDC112905FBF700E3999D /* FIATransactionCacheTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FIATransactionCacheTests.m; path = ../../shared/RunnerTests/FIATransactionCacheTests.m; sourceTree = ""; }; + F79BDC132905FBFE00E3999D /* InAppPurchasePluginTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InAppPurchasePluginTests.m; path = ../../shared/RunnerTests/InAppPurchasePluginTests.m; sourceTree = ""; }; + F79BDC152905FC0500E3999D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../../shared/RunnerTests/Info.plist; sourceTree = ""; }; + F79BDC172905FC1800E3999D /* PaymentQueueTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PaymentQueueTests.m; path = ../../shared/RunnerTests/PaymentQueueTests.m; sourceTree = ""; }; + F79BDC192905FC1F00E3999D /* ProductRequestHandlerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ProductRequestHandlerTests.m; path = ../../shared/RunnerTests/ProductRequestHandlerTests.m; sourceTree = ""; }; + F79BDC1B2905FC3200E3999D /* Stubs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Stubs.m; path = ../../shared/RunnerTests/Stubs.m; sourceTree = ""; }; + F79BDC1D2905FC3900E3999D /* TranslatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TranslatorTests.m; path = ../../shared/RunnerTests/TranslatorTests.m; sourceTree = ""; }; + F79BDC1F2906023C00E3999D /* Stubs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Stubs.h; path = ../../shared/RunnerTests/Stubs.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A2C6CD5797E6A6721FDBCA1C /* Pods_Runner.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F700DCFF28E652A10004836B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C51E64432925727D7AC7BBFF /* Pods_RunnerTests.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 09D47623A8E19B84FF0453EE /* Pods */ = { + isa = PBXGroup; + children = ( + B6C8FD76BB3278AA51FED870 /* Pods-Runner.debug.xcconfig */, + 9A4FEABF1DEF0D106FEB7974 /* Pods-Runner.release.xcconfig */, + 62F1680C5AE033907C1DF7AB /* Pods-Runner.profile.xcconfig */, + 5E5D46173E3025B0DB32A1BE /* Pods-RunnerTests.debug.xcconfig */, + 5EBC5A8BA44B08330BA605AB /* Pods-RunnerTests.release.xcconfig */, + 4E423AE82F466005587C3567 /* Pods-RunnerTests.profile.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + F700DD0328E652A10004836B /* RunnerTests */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + 09D47623A8E19B84FF0453EE /* Pods */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* example.app */, + F700DD0228E652A10004836B /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 36DEEA66738F64D983F76848 /* Pods_Runner.framework */, + EE8A421F08C80BE6E90142D5 /* Pods_RunnerTests.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + F700DD0328E652A10004836B /* RunnerTests */ = { + isa = PBXGroup; + children = ( + F79BDC0F2905FBE300E3999D /* FIAPPaymentQueueDeleteTests.m */, + F79BDC132905FBFE00E3999D /* InAppPurchasePluginTests.m */, + F79BDC172905FC1800E3999D /* PaymentQueueTests.m */, + F79BDC1F2906023C00E3999D /* Stubs.h */, + F79BDC152905FC0500E3999D /* Info.plist */, + F79BDC1B2905FC3200E3999D /* Stubs.m */, + F79BDC1D2905FC3900E3999D /* TranslatorTests.m */, + F79BDC192905FC1F00E3999D /* ProductRequestHandlerTests.m */, + F79BDC112905FBF700E3999D /* FIATransactionCacheTests.m */, + ); + path = RunnerTests; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 377E3E3C5CA24E98C4B6A4BB /* [CP] Check Pods Manifest.lock */, + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + 23A80E9A6DAA80757416464A /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* example.app */; + productType = "com.apple.product-type.application"; + }; + F700DD0128E652A10004836B /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = F700DD0B28E652A10004836B /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 959FA4942EA5DA018C52D3DA /* [CP] Check Pods Manifest.lock */, + F700DCFE28E652A10004836B /* Sources */, + F700DCFF28E652A10004836B /* Frameworks */, + F700DD0028E652A10004836B /* Resources */, + 1FAA0D39365CA43DED71E657 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + F700DD0728E652A10004836B /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = F700DD0228E652A10004836B /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1400; + LastUpgradeCheck = 1300; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + F700DD0128E652A10004836B = { + CreatedOnToolsVersion = 14.0.1; + LastSwiftMigration = 1400; + TestTargetID = 33CC10EC2044A3C60003C045; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + F700DD0128E652A10004836B /* RunnerTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F700DD0028E652A10004836B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 1FAA0D39365CA43DED71E657 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-RunnerTests/Pods-RunnerTests-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-RunnerTests/Pods-RunnerTests-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RunnerTests/Pods-RunnerTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 23A80E9A6DAA80757416464A /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; + 377E3E3C5CA24E98C4B6A4BB /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 959FA4942EA5DA018C52D3DA /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F700DCFE28E652A10004836B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + F79BDC1A2905FC1F00E3999D /* ProductRequestHandlerTests.m in Sources */, + F79BDC1E2905FC3900E3999D /* TranslatorTests.m in Sources */, + F79BDC182905FC1800E3999D /* PaymentQueueTests.m in Sources */, + F79BDC1C2905FC3200E3999D /* Stubs.m in Sources */, + F79BDC102905FBE300E3999D /* FIAPPaymentQueueDeleteTests.m in Sources */, + F79BDC142905FBFE00E3999D /* InAppPurchasePluginTests.m in Sources */, + F79BDC122905FBF700E3999D /* FIATransactionCacheTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; + F700DD0728E652A10004836B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC10EC2044A3C60003C045 /* Runner */; + targetProxy = F700DD0628E652A10004836B /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.15; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.15; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.15; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + F700DD0828E652A10004836B /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5E5D46173E3025B0DB32A1BE /* Pods-RunnerTests.debug.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = NO; + INFOPLIST_FILE = RunnerTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/in_app_purchase_storekit/in_app_purchase_storekit.modulemap\" -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/integration_test/integration_test.modulemap\" -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/shared_preferences_macos/shared_preferences_macos.modulemap\""; + PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/example"; + }; + name = Debug; + }; + F700DD0928E652A10004836B /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5EBC5A8BA44B08330BA605AB /* Pods-RunnerTests.release.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = NO; + INFOPLIST_FILE = RunnerTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.0; + MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/in_app_purchase_storekit/in_app_purchase_storekit.modulemap\" -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/integration_test/integration_test.modulemap\" -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/shared_preferences_macos/shared_preferences_macos.modulemap\""; + PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/example"; + }; + name = Release; + }; + F700DD0A28E652A10004836B /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 4E423AE82F466005587C3567 /* Pods-RunnerTests.profile.xcconfig */; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = NO; + INFOPLIST_FILE = RunnerTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.0; + MTL_FAST_MATH = YES; + OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/in_app_purchase_storekit/in_app_purchase_storekit.modulemap\" -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/integration_test/integration_test.modulemap\" -Xcc -fmodule-map-file=\"${PODS_ROOT}/Headers/Public/shared_preferences_macos/shared_preferences_macos.modulemap\""; + PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/example"; + }; + name = Profile; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F700DD0B28E652A10004836B /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F700DD0828E652A10004836B /* Debug */, + F700DD0928E652A10004836B /* Release */, + F700DD0A28E652A10004836B /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000000..18d981003d68 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 000000000000..cd370a07dfcb --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000000..21a3cc14c74e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000000..18d981003d68 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/AppDelegate.swift b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/AppDelegate.swift new file mode 100644 index 000000000000..5cec4c48f620 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +// 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. + +import Cocoa +import FlutterMacOS + +@NSApplicationMain +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } +} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Base.lproj/MainMenu.xib b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 000000000000..80e867a4e06b --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/AppInfo.xcconfig b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 000000000000..3c916dec7ec9 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = example + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.example + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2022 dev.flutter.plugins. All rights reserved. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/Debug.xcconfig b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 000000000000..3e2524adcdd6 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/Release.xcconfig b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 000000000000..77ac7613be91 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1 @@ +#include "../../Flutter/Flutter-Release.xcconfig" diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/DebugProfile.entitlements b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/DebugProfile.entitlements new file mode 100644 index 000000000000..dddb8a30c851 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Info.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Info.plist new file mode 100644 index 000000000000..4789daa6a443 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/MainFlutterWindow.swift b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 000000000000..32aaeedceb1f --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,19 @@ +// 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. + +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController.init() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } +} diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Release.entitlements b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Release.entitlements new file mode 100644 index 000000000000..852fa1a4728a --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/FIAPPaymentQueueDeleteTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/FIAPPaymentQueueDeleteTests.m new file mode 120000 index 000000000000..7c8e7691c6d4 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/FIAPPaymentQueueDeleteTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/FIAPPaymentQueueDeleteTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/FIATransactionCacheTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/FIATransactionCacheTests.m new file mode 120000 index 000000000000..5c7c87fd1aea --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/FIATransactionCacheTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/FIATransactionCacheTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/InAppPurchasePluginTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/InAppPurchasePluginTests.m new file mode 120000 index 000000000000..495146dde20b --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/InAppPurchasePluginTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/InAppPurchasePluginTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Info.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Info.plist new file mode 120000 index 000000000000..55acf210929a --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Info.plist @@ -0,0 +1 @@ +../../shared/RunnerTests/Info.plist \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/PaymentQueueTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/PaymentQueueTests.m new file mode 120000 index 000000000000..f207cda68945 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/PaymentQueueTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/PaymentQueueTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/ProductRequestHandlerTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/ProductRequestHandlerTests.m new file mode 120000 index 000000000000..f186e1122526 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/ProductRequestHandlerTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/ProductRequestHandlerTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Stubs.h b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Stubs.h new file mode 120000 index 000000000000..420bd56538d1 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Stubs.h @@ -0,0 +1 @@ +../../shared/RunnerTests/Stubs.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Stubs.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Stubs.m new file mode 120000 index 000000000000..eee9d6b331a9 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/Stubs.m @@ -0,0 +1 @@ +../../shared/RunnerTests/Stubs.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/TranslatorTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/TranslatorTests.m new file mode 120000 index 000000000000..ac58ed96972e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/macos/RunnerTests/TranslatorTests.m @@ -0,0 +1 @@ +../../shared/RunnerTests/TranslatorTests.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/FIAPPaymentQueueDeleteTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/FIAPPaymentQueueDeleteTests.m new file mode 100644 index 000000000000..187cc6e37bf6 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/FIAPPaymentQueueDeleteTests.m @@ -0,0 +1,125 @@ +// 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. + +#import +#import +#import "FIAObjectTranslator.h" +#import "FIAPaymentQueueHandler.h" +#import "Stubs.h" + +@import in_app_purchase_storekit; + +API_AVAILABLE(ios(13.0)) +API_UNAVAILABLE(tvos, macos, watchos) +@interface FIAPPaymentQueueDelegateTests : XCTestCase + +@property(strong, nonatomic) FlutterMethodChannel *channel; +@property(strong, nonatomic) SKPaymentTransaction *transaction; +@property(strong, nonatomic) SKStorefront *storefront; + +@end + +@implementation FIAPPaymentQueueDelegateTests + +- (void)setUp { + self.channel = OCMClassMock(FlutterMethodChannel.class); + + NSDictionary *transactionMap = @{ + @"transactionIdentifier" : [NSNull null], + @"transactionState" : @(SKPaymentTransactionStatePurchasing), + @"payment" : [NSNull null], + @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" + code:123 + userInfo:@{}]], + @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), + @"originalTransaction" : [NSNull null], + }; + self.transaction = [[SKPaymentTransactionStub alloc] initWithMap:transactionMap]; + + NSDictionary *storefrontMap = @{ + @"countryCode" : @"USA", + @"identifier" : @"unique_identifier", + }; + self.storefront = [[SKStorefrontStub alloc] initWithMap:storefrontMap]; +} + +- (void)tearDown { + self.channel = nil; +} + +- (void)testShouldContinueTransaction { + if (@available(iOS 13.0, *)) { + FIAPPaymentQueueDelegate *delegate = + [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; + + OCMStub([self.channel + invokeMethod:@"shouldContinueTransaction" + arguments:[FIAObjectTranslator getMapFromSKStorefront:self.storefront + andSKPaymentTransaction:self.transaction] + result:([OCMArg invokeBlockWithArgs:[NSNumber numberWithBool:NO], nil])]); + + BOOL shouldContinue = [delegate paymentQueue:OCMClassMock(SKPaymentQueue.class) + shouldContinueTransaction:self.transaction + inStorefront:self.storefront]; + + XCTAssertFalse(shouldContinue); + } +} + +- (void)testShouldContinueTransaction_should_default_to_yes { + if (@available(iOS 13.0, *)) { + FIAPPaymentQueueDelegate *delegate = + [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; + + OCMStub([self.channel invokeMethod:@"shouldContinueTransaction" + arguments:[FIAObjectTranslator getMapFromSKStorefront:self.storefront + andSKPaymentTransaction:self.transaction] + result:[OCMArg any]]); + + BOOL shouldContinue = [delegate paymentQueue:OCMClassMock(SKPaymentQueue.class) + shouldContinueTransaction:self.transaction + inStorefront:self.storefront]; + + XCTAssertTrue(shouldContinue); + } +} + +#if TARGET_OS_IOS +- (void)testShouldShowPriceConsentIfNeeded { + if (@available(iOS 13.4, *)) { + FIAPPaymentQueueDelegate *delegate = + [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; + + OCMStub([self.channel + invokeMethod:@"shouldShowPriceConsent" + arguments:nil + result:([OCMArg invokeBlockWithArgs:[NSNumber numberWithBool:NO], nil])]); + + BOOL shouldShow = + [delegate paymentQueueShouldShowPriceConsent:OCMClassMock(SKPaymentQueue.class)]; + + XCTAssertFalse(shouldShow); + } +} +#endif + +#if TARGET_OS_IOS +- (void)testShouldShowPriceConsentIfNeeded_should_default_to_yes { + if (@available(iOS 13.4, *)) { + FIAPPaymentQueueDelegate *delegate = + [[FIAPPaymentQueueDelegate alloc] initWithMethodChannel:self.channel]; + + OCMStub([self.channel invokeMethod:@"shouldShowPriceConsent" + arguments:nil + result:[OCMArg any]]); + + BOOL shouldShow = + [delegate paymentQueueShouldShowPriceConsent:OCMClassMock(SKPaymentQueue.class)]; + + XCTAssertTrue(shouldShow); + } +} +#endif + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/FIATransactionCacheTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/FIATransactionCacheTests.m new file mode 100644 index 000000000000..1ba0aea76e39 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/FIATransactionCacheTests.m @@ -0,0 +1,63 @@ +// 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. + +#import + +@import in_app_purchase_storekit; + +@interface FIATransactionCacheTests : XCTestCase + +@end + +@implementation FIATransactionCacheTests + +- (void)testAddObjectsForNewKey { + NSArray *dummyArray = @[ @1, @2, @3 ]; + FIATransactionCache *cache = [[FIATransactionCache alloc] init]; + [cache addObjects:dummyArray forKey:TransactionCacheKeyUpdatedTransactions]; + + XCTAssertEqual(dummyArray, [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); +} + +- (void)testAddObjectsForExistingKey { + NSArray *dummyArray = @[ @1, @2, @3 ]; + FIATransactionCache *cache = [[FIATransactionCache alloc] init]; + [cache addObjects:dummyArray forKey:TransactionCacheKeyUpdatedTransactions]; + + XCTAssertEqual(dummyArray, [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); + + [cache addObjects:@[ @4, @5, @6 ] forKey:TransactionCacheKeyUpdatedTransactions]; + + NSArray *expected = @[ @1, @2, @3, @4, @5, @6 ]; + XCTAssertEqualObjects(expected, [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); +} + +- (void)testGetObjectsForNonExistingKey { + FIATransactionCache *cache = [[FIATransactionCache alloc] init]; + XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); +} + +- (void)testClear { + NSArray *fakeUpdatedTransactions = @[ @1, @2, @3 ]; + NSArray *fakeRemovedTransactions = @[ @"Remove 1", @"Remove 2", @"Remove 3" ]; + NSArray *fakeUpdatedDownloads = @[ @"Download 1", @"Download 2" ]; + FIATransactionCache *cache = [[FIATransactionCache alloc] init]; + [cache addObjects:fakeUpdatedTransactions forKey:TransactionCacheKeyUpdatedTransactions]; + [cache addObjects:fakeRemovedTransactions forKey:TransactionCacheKeyRemovedTransactions]; + [cache addObjects:fakeUpdatedDownloads forKey:TransactionCacheKeyUpdatedDownloads]; + + XCTAssertEqual(fakeUpdatedTransactions, + [cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); + XCTAssertEqual(fakeRemovedTransactions, + [cache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); + XCTAssertEqual(fakeUpdatedDownloads, + [cache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); + + [cache clear]; + + XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); + XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); + XCTAssertNil([cache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); +} +@end 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 new file mode 100644 index 000000000000..9ace425ce1dc --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m @@ -0,0 +1,524 @@ +// 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. + +#import +#import +#import "FIAPaymentQueueHandler.h" +#import "Stubs.h" + +@import in_app_purchase_storekit; + +@interface InAppPurchasePluginTest : XCTestCase + +@property(strong, nonatomic) FIAPReceiptManagerStub *receiptManagerStub; +@property(strong, nonatomic) InAppPurchasePlugin *plugin; + +@end + +@implementation InAppPurchasePluginTest + +- (void)setUp { + self.receiptManagerStub = [FIAPReceiptManagerStub new]; + self.plugin = [[InAppPurchasePluginStub alloc] initWithReceiptManager:self.receiptManagerStub]; +} + +- (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 { + XCTestExpectation *expectation = [self expectationWithDescription:@"expect result to be YES"]; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue canMakePayments:]" + arguments:NULL]; + __block id result; + [self.plugin handleMethodCall:call + result:^(id r) { + [expectation fulfill]; + result = r; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqual(result, @YES); +} + +- (void)testGetProductResponse { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect response contains 1 item"]; + FlutterMethodCall *call = [FlutterMethodCall + methodCallWithMethodName:@"-[InAppPurchasePlugin startProductRequest:result:]" + arguments:@[ @"123" ]]; + __block id result; + [self.plugin handleMethodCall:call + result:^(id r) { + [expectation fulfill]; + result = r; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssert([result isKindOfClass:[NSDictionary class]]); + NSArray *resultArray = [result objectForKey:@"products"]; + XCTAssertEqual(resultArray.count, 1); + XCTAssertTrue([resultArray.firstObject[@"productIdentifier"] isEqualToString:@"123"]); +} + +- (void)testAddPaymentShouldReturnFlutterErrorWhenArgumentsAreInvalid { + XCTestExpectation *expectation = + [self expectationWithDescription: + @"Result should contain a FlutterError when invalid parameters are passed in."]; + NSString *argument = @"Invalid argument"; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" + arguments:argument]; + [self.plugin handleMethodCall:call + result:^(id _Nullable result) { + FlutterError *error = result; + XCTAssertEqualObjects(@"storekit_invalid_argument", error.code); + XCTAssertEqualObjects(@"Argument type of addPayment is not a Dictionary", + error.message); + XCTAssertEqualObjects(argument, error.details); + [expectation fulfill]; + }]; + + [self waitForExpectations:@[ expectation ] timeout:5]; +} + +- (void)testAddPaymentShouldReturnFlutterErrorWhenPaymentFails { + NSDictionary *arguments = @{ + @"productIdentifier" : @"123", + @"quantity" : @(1), + @"simulatesAskToBuyInSandbox" : @YES, + }; + XCTestExpectation *expectation = + [self expectationWithDescription:@"Result should return failed state."]; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" + arguments:arguments]; + + FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); + OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(NO); + self.plugin.paymentQueueHandler = mockHandler; + + [self.plugin handleMethodCall:call + result:^(id _Nullable result) { + FlutterError *error = result; + XCTAssertEqualObjects(@"storekit_duplicate_product_object", error.code); + XCTAssertEqualObjects( + @"There is a pending transaction for the same product identifier. " + @"Please either wait for it to be finished or finish it manually " + @"using `completePurchase` to avoid edge cases.", + error.message); + XCTAssertEqualObjects(arguments, error.details); + [expectation fulfill]; + }]; + + [self waitForExpectations:@[ expectation ] timeout:5]; + OCMVerify(times(1), [mockHandler addPayment:[OCMArg any]]); +} + +- (void)testAddPaymentSuccessWithoutPaymentDiscount { + XCTestExpectation *expectation = + [self expectationWithDescription:@"Result should return success state"]; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" + arguments:@{ + @"productIdentifier" : @"123", + @"quantity" : @(1), + @"simulatesAskToBuyInSandbox" : @YES, + }]; + FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); + OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(YES); + self.plugin.paymentQueueHandler = mockHandler; + [self.plugin handleMethodCall:call + result:^(id _Nullable result) { + XCTAssertNil(result); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; +} + +- (void)testAddPaymentSuccessWithPaymentDiscount { + XCTestExpectation *expectation = + [self expectationWithDescription:@"Result should return success state"]; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" + arguments:@{ + @"productIdentifier" : @"123", + @"quantity" : @(1), + @"simulatesAskToBuyInSandbox" : @YES, + @"paymentDiscount" : @{ + @"identifier" : @"test_identifier", + @"keyIdentifier" : @"test_key_identifier", + @"nonce" : @"4a11a9cc-3bc3-11ec-8d3d-0242ac130003", + @"signature" : @"test_signature", + @"timestamp" : @(1635847102), + } + }]; + + FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); + OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(YES); + self.plugin.paymentQueueHandler = mockHandler; + [self.plugin handleMethodCall:call + result:^(id _Nullable result) { + XCTAssertNil(result); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + OCMVerify( + times(1), + [mockHandler + addPayment:[OCMArg checkWithBlock:^BOOL(id obj) { + SKPayment *payment = obj; + if (@available(iOS 12.2, *)) { + SKPaymentDiscount *discount = payment.paymentDiscount; + + return [discount.identifier isEqual:@"test_identifier"] && + [discount.keyIdentifier isEqual:@"test_key_identifier"] && + [discount.nonce + isEqual:[[NSUUID alloc] + initWithUUIDString:@"4a11a9cc-3bc3-11ec-8d3d-0242ac130003"]] && + [discount.signature isEqual:@"test_signature"] && + [discount.timestamp isEqual:@(1635847102)]; + } + + return YES; + }]]); +} + +- (void)testAddPaymentFailureWithInvalidPaymentDiscount { + // Support for payment discount is only available on iOS 12.2 and higher. + if (@available(iOS 12.2, *)) { + XCTestExpectation *expectation = + [self expectationWithDescription:@"Result should return success state"]; + NSDictionary *arguments = @{ + @"productIdentifier" : @"123", + @"quantity" : @(1), + @"simulatesAskToBuyInSandbox" : @YES, + @"paymentDiscount" : @{ + @"keyIdentifier" : @"test_key_identifier", + @"nonce" : @"4a11a9cc-3bc3-11ec-8d3d-0242ac130003", + @"signature" : @"test_signature", + @"timestamp" : @(1635847102), + } + }; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" + arguments:arguments]; + + FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); + id translator = OCMClassMock(FIAObjectTranslator.class); + + NSString *error = @"Some error occurred"; + OCMStub(ClassMethod([translator + getSKPaymentDiscountFromMap:[OCMArg any] + withError:(NSString __autoreleasing **)[OCMArg setTo:error]])) + .andReturn(nil); + self.plugin.paymentQueueHandler = mockHandler; + [self.plugin + handleMethodCall:call + result:^(id _Nullable result) { + FlutterError *error = result; + XCTAssertEqualObjects(@"storekit_invalid_payment_discount_object", error.code); + XCTAssertEqualObjects( + @"You have requested a payment and specified a " + @"payment discount with invalid properties. Some error occurred", + error.message); + XCTAssertEqualObjects(arguments, error.details); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + OCMVerify(never(), [mockHandler addPayment:[OCMArg any]]); + } +} + +- (void)testAddPaymentWithNullSandboxArgument { + XCTestExpectation *expectation = + [self expectationWithDescription:@"result should return success state"]; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]" + arguments:@{ + @"productIdentifier" : @"123", + @"quantity" : @(1), + @"simulatesAskToBuyInSandbox" : [NSNull null], + }]; + FIAPaymentQueueHandler *mockHandler = OCMClassMock(FIAPaymentQueueHandler.class); + OCMStub([mockHandler addPayment:[OCMArg any]]).andReturn(YES); + self.plugin.paymentQueueHandler = mockHandler; + [self.plugin handleMethodCall:call + result:^(id _Nullable result) { + XCTAssertNil(result); + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + OCMVerify(times(1), [mockHandler addPayment:[OCMArg checkWithBlock:^BOOL(id obj) { + SKPayment *payment = obj; + return !payment.simulatesAskToBuyInSandbox; + }]]); +} + +- (void)testRestoreTransactions { + XCTestExpectation *expectation = + [self expectationWithDescription:@"result successfully restore transactions"]; + FlutterMethodCall *call = [FlutterMethodCall + methodCallWithMethodName:@"-[InAppPurchasePlugin restoreTransactions:result:]" + arguments:nil]; + SKPaymentQueueStub *queue = [SKPaymentQueueStub new]; + queue.testState = SKPaymentTransactionStatePurchased; + __block BOOL callbackInvoked = NO; + self.plugin.paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + } + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:^() { + callbackInvoked = YES; + [expectation fulfill]; + } + shouldAddStorePayment:nil + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + [queue addTransactionObserver:self.plugin.paymentQueueHandler]; + [self.plugin handleMethodCall:call + result:^(id r){ + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertTrue(callbackInvoked); +} + +- (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]; + XCTAssertNotNil(result); + XCTAssert([result isKindOfClass:[NSString class]]); +} + +- (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; + 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]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertTrue(result); +} + +- (void)testPresentCodeRedemptionSheet { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect successfully present Code Redemption Sheet"]; + FlutterMethodCall *call = [FlutterMethodCall + methodCallWithMethodName:@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" + arguments:nil]; + __block BOOL callbackInvoked = NO; + [self.plugin handleMethodCall:call + result:^(id r) { + callbackInvoked = YES; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertTrue(callbackInvoked); +} + +- (void)testGetPendingTransactions { + XCTestExpectation *expectation = [self expectationWithDescription:@"expect success"]; + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue transactions]" arguments:nil]; + SKPaymentQueue *mockQueue = OCMClassMock(SKPaymentQueue.class); + NSDictionary *transactionMap = @{ + @"transactionIdentifier" : [NSNull null], + @"transactionState" : @(SKPaymentTransactionStatePurchasing), + @"payment" : [NSNull null], + @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" + code:123 + userInfo:@{}]], + @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), + @"originalTransaction" : [NSNull null], + }; + OCMStub(mockQueue.transactions).andReturn(@[ [[SKPaymentTransactionStub alloc] + initWithMap:transactionMap] ]); + + __block NSArray *resultArray; + self.plugin.paymentQueueHandler = + [[FIAPaymentQueueHandler alloc] initWithQueue:mockQueue + transactionsUpdated:nil + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:nil + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + [self.plugin handleMethodCall:call + result:^(id r) { + resultArray = r; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqualObjects(resultArray, @[ transactionMap ]); +} + +- (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]; + 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]; + 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 + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:nil + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + + // Verify the delegate is nil before we register one. + XCTAssertNil(self.plugin.paymentQueueHandler.delegate); + + [self.plugin handleMethodCall:call + result:^(id r){ + }]; + + // Verify the delegate is not nil after we registered one. + XCTAssertNotNil(self.plugin.paymentQueueHandler.delegate); + } +} +#endif + +- (void)testRemovePaymentQueueDelegate { + if (@available(iOS 13, *)) { + FlutterMethodCall *call = + [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue removeDelegate]" + arguments:nil]; + + self.plugin.paymentQueueHandler = + [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueueStub new] + transactionsUpdated:nil + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:nil + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + self.plugin.paymentQueueHandler.delegate = OCMProtocolMock(@protocol(SKPaymentQueueDelegate)); + + // Verify the delegate is not nil before removing it. + XCTAssertNotNil(self.plugin.paymentQueueHandler.delegate); + + [self.plugin handleMethodCall:call + result:^(id r){ + }]; + + // Verify the delegate is nill after removing it. + XCTAssertNil(self.plugin.paymentQueueHandler.delegate); + } +} + +#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){ + }]; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpartial-availability" + if (@available(iOS 13.4, *)) { + OCMVerify(times(1), [mockQueueHandler showPriceConsentIfNeeded]); + } else { + OCMVerify(never(), [mockQueueHandler showPriceConsentIfNeeded]); + } +#pragma clang diagnostic pop +} +#endif + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Info.plist b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Info.plist new file mode 100644 index 000000000000..6c40a6cd0c4a --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/PaymentQueueTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/PaymentQueueTests.m new file mode 100644 index 000000000000..2f8d5857c8d8 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/PaymentQueueTests.m @@ -0,0 +1,420 @@ +// 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. + +#import +#import +#import "Stubs.h" + +@import in_app_purchase_storekit; + +@interface PaymentQueueTest : XCTestCase + +@property(strong, nonatomic) NSDictionary *periodMap; +@property(strong, nonatomic) NSDictionary *discountMap; +@property(strong, nonatomic) NSDictionary *productMap; +@property(strong, nonatomic) NSDictionary *productResponseMap; + +@end + +@implementation PaymentQueueTest + +- (void)setUp { + self.periodMap = @{@"numberOfUnits" : @(0), @"unit" : @(0)}; + self.discountMap = @{ + @"price" : @1.0, + @"currencyCode" : @"USD", + @"numberOfPeriods" : @1, + @"subscriptionPeriod" : self.periodMap, + @"paymentMode" : @1 + }; + self.productMap = @{ + @"price" : @1.0, + @"currencyCode" : @"USD", + @"productIdentifier" : @"123", + @"localizedTitle" : @"title", + @"localizedDescription" : @"des", + @"subscriptionPeriod" : self.periodMap, + @"introductoryPrice" : self.discountMap, + @"subscriptionGroupIdentifier" : @"com.group" + }; + self.productResponseMap = + @{@"products" : @[ self.productMap ], @"invalidProductIdentifiers" : [NSNull null]}; +} + +- (void)testTransactionPurchased { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get purchased transcation."]; + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStatePurchased; + __block SKPaymentTransactionStub *tran; + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + SKPaymentTransaction *transaction = transactions[0]; + tran = (SKPaymentTransactionStub *)transaction; + [expectation fulfill]; + } + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler startObservingPaymentQueue]; + [handler addPayment:payment]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqual(tran.transactionState, SKPaymentTransactionStatePurchased); + XCTAssertEqual(tran.transactionIdentifier, @"fakeID"); +} + +- (void)testTransactionFailed { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get failed transcation."]; + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStateFailed; + __block SKPaymentTransactionStub *tran; + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + SKPaymentTransaction *transaction = transactions[0]; + tran = (SKPaymentTransactionStub *)transaction; + [expectation fulfill]; + } + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler startObservingPaymentQueue]; + [handler addPayment:payment]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqual(tran.transactionState, SKPaymentTransactionStateFailed); + XCTAssertEqual(tran.transactionIdentifier, nil); +} + +- (void)testTransactionRestored { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get restored transcation."]; + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStateRestored; + __block SKPaymentTransactionStub *tran; + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + SKPaymentTransaction *transaction = transactions[0]; + tran = (SKPaymentTransactionStub *)transaction; + [expectation fulfill]; + } + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler startObservingPaymentQueue]; + [handler addPayment:payment]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqual(tran.transactionState, SKPaymentTransactionStateRestored); + XCTAssertEqual(tran.transactionIdentifier, @"fakeID"); +} + +- (void)testTransactionPurchasing { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get purchasing transcation."]; + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStatePurchasing; + __block SKPaymentTransactionStub *tran; + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + SKPaymentTransaction *transaction = transactions[0]; + tran = (SKPaymentTransactionStub *)transaction; + [expectation fulfill]; + } + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler startObservingPaymentQueue]; + [handler addPayment:payment]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqual(tran.transactionState, SKPaymentTransactionStatePurchasing); + XCTAssertEqual(tran.transactionIdentifier, nil); +} + +- (void)testTransactionDeferred { + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get deffered transcation."]; + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStateDeferred; + __block SKPaymentTransactionStub *tran; + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + SKPaymentTransaction *transaction = transactions[0]; + tran = (SKPaymentTransactionStub *)transaction; + [expectation fulfill]; + } + transactionRemoved:nil + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler startObservingPaymentQueue]; + [handler addPayment:payment]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertEqual(tran.transactionState, SKPaymentTransactionStateDeferred); + XCTAssertEqual(tran.transactionIdentifier, nil); +} + +- (void)testFinishTransaction { + XCTestExpectation *expectation = + [self expectationWithDescription:@"handler.transactions should be empty."]; + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStateDeferred; + __block FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + XCTAssertEqual(transactions.count, 1); + SKPaymentTransaction *transaction = transactions[0]; + [handler finishTransaction:transaction]; + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + XCTAssertEqual(transactions.count, 1); + [expectation fulfill]; + } + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:nil + transactionCache:OCMClassMock(FIATransactionCache.class)]; + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler startObservingPaymentQueue]; + [handler addPayment:payment]; + [self waitForExpectations:@[ expectation ] timeout:5]; +} + +- (void)testStartObservingPaymentQueueShouldNotProcessTransactionsWhenCacheIsEmpty { + FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); + FIAPaymentQueueHandler *handler = + [[FIAPaymentQueueHandler alloc] initWithQueue:[[SKPaymentQueueStub alloc] init] + transactionsUpdated:^(NSArray *_Nonnull transactions) { + XCTFail("transactionsUpdated callback should not be called when cache is empty."); + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + XCTFail("transactionRemoved callback should not be called when cache is empty."); + } + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:^(NSArray *_Nonnull downloads) { + XCTFail("updatedDownloads callback should not be called when cache is empty."); + } + transactionCache:mockCache]; + + [handler startObservingPaymentQueue]; + + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); +} + +- (void) + testStartObservingPaymentQueueShouldNotProcessTransactionsWhenCacheContainsEmptyTransactionArrays { + FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); + FIAPaymentQueueHandler *handler = + [[FIAPaymentQueueHandler alloc] initWithQueue:[[SKPaymentQueueStub alloc] init] + transactionsUpdated:^(NSArray *_Nonnull transactions) { + XCTFail("transactionsUpdated callback should not be called when cache is empty."); + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + XCTFail("transactionRemoved callback should not be called when cache is empty."); + } + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:^(NSArray *_Nonnull downloads) { + XCTFail("updatedDownloads callback should not be called when cache is empty."); + } + transactionCache:mockCache]; + + OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]).andReturn(@[]); + OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]).andReturn(@[]); + OCMStub([mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]).andReturn(@[]); + + [handler startObservingPaymentQueue]; + + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); +} + +- (void)testStartObservingPaymentQueueShouldProcessTransactionsForItemsInCache { + XCTestExpectation *updateTransactionsExpectation = + [self expectationWithDescription: + @"transactionsUpdated callback should be called with one transaction."]; + XCTestExpectation *removeTransactionsExpectation = + [self expectationWithDescription: + @"transactionsRemoved callback should be called with one transaction."]; + XCTestExpectation *updateDownloadsExpectation = + [self expectationWithDescription: + @"downloadsUpdated callback should be called with one transaction."]; + SKPaymentTransaction *mockTransaction = OCMClassMock(SKPaymentTransaction.class); + SKDownload *mockDownload = OCMClassMock(SKDownload.class); + FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); + FIAPaymentQueueHandler *handler = + [[FIAPaymentQueueHandler alloc] initWithQueue:[[SKPaymentQueueStub alloc] init] + transactionsUpdated:^(NSArray *_Nonnull transactions) { + XCTAssertEqualObjects(transactions, @[ mockTransaction ]); + [updateTransactionsExpectation fulfill]; + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + XCTAssertEqualObjects(transactions, @[ mockTransaction ]); + [removeTransactionsExpectation fulfill]; + } + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:^(NSArray *_Nonnull downloads) { + XCTAssertEqualObjects(downloads, @[ mockDownload ]); + [updateDownloadsExpectation fulfill]; + } + transactionCache:mockCache]; + + OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]).andReturn(@[ + mockTransaction + ]); + OCMStub([mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]).andReturn(@[ + mockDownload + ]); + OCMStub([mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]).andReturn(@[ + mockTransaction + ]); + + [handler startObservingPaymentQueue]; + + [self waitForExpectations:@[ + updateTransactionsExpectation, removeTransactionsExpectation, updateDownloadsExpectation + ] + timeout:5]; + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]); + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]); + OCMVerify(times(1), [mockCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]); + OCMVerify(times(1), [mockCache clear]); +} + +- (void)testTransactionsShouldBeCachedWhenNotObserving { + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + XCTFail("transactionsUpdated callback should not be called when cache is empty."); + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + XCTFail("transactionRemoved callback should not be called when cache is empty."); + } + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:^(NSArray *_Nonnull downloads) { + XCTFail("updatedDownloads callback should not be called when cache is empty."); + } + transactionCache:mockCache]; + + SKPayment *payment = + [SKPayment paymentWithProduct:[[SKProductStub alloc] initWithMap:self.productResponseMap]]; + [handler addPayment:payment]; + + OCMVerify(times(1), [mockCache addObjects:[OCMArg any] + forKey:TransactionCacheKeyUpdatedTransactions]); + OCMVerify(never(), [mockCache addObjects:[OCMArg any] + forKey:TransactionCacheKeyUpdatedDownloads]); + OCMVerify(never(), [mockCache addObjects:[OCMArg any] + forKey:TransactionCacheKeyRemovedTransactions]); +} + +- (void)testTransactionsShouldNotBeCachedWhenObserving { + XCTestExpectation *updateTransactionsExpectation = + [self expectationWithDescription: + @"transactionsUpdated callback should be called with one transaction."]; + XCTestExpectation *removeTransactionsExpectation = + [self expectationWithDescription: + @"transactionsRemoved callback should be called with one transaction."]; + XCTestExpectation *updateDownloadsExpectation = + [self expectationWithDescription: + @"downloadsUpdated callback should be called with one transaction."]; + SKPaymentTransaction *mockTransaction = OCMClassMock(SKPaymentTransaction.class); + SKDownload *mockDownload = OCMClassMock(SKDownload.class); + SKPaymentQueueStub *queue = [[SKPaymentQueueStub alloc] init]; + queue.testState = SKPaymentTransactionStatePurchased; + FIATransactionCache *mockCache = OCMClassMock(FIATransactionCache.class); + FIAPaymentQueueHandler *handler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:^(NSArray *_Nonnull transactions) { + XCTAssertEqualObjects(transactions, @[ mockTransaction ]); + [updateTransactionsExpectation fulfill]; + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + XCTAssertEqualObjects(transactions, @[ mockTransaction ]); + [removeTransactionsExpectation fulfill]; + } + restoreTransactionFailed:nil + restoreCompletedTransactionsFinished:nil + shouldAddStorePayment:^BOOL(SKPayment *_Nonnull payment, SKProduct *_Nonnull product) { + return YES; + } + updatedDownloads:^(NSArray *_Nonnull downloads) { + XCTAssertEqualObjects(downloads, @[ mockDownload ]); + [updateDownloadsExpectation fulfill]; + } + transactionCache:mockCache]; + + [handler startObservingPaymentQueue]; + [handler paymentQueue:queue updatedTransactions:@[ mockTransaction ]]; + [handler paymentQueue:queue removedTransactions:@[ mockTransaction ]]; + [handler paymentQueue:queue updatedDownloads:@[ mockDownload ]]; + + [self waitForExpectations:@[ + updateTransactionsExpectation, removeTransactionsExpectation, updateDownloadsExpectation + ] + timeout:5]; + OCMVerify(never(), [mockCache addObjects:[OCMArg any] + forKey:TransactionCacheKeyUpdatedTransactions]); + OCMVerify(never(), [mockCache addObjects:[OCMArg any] + forKey:TransactionCacheKeyUpdatedDownloads]); + OCMVerify(never(), [mockCache addObjects:[OCMArg any] + forKey:TransactionCacheKeyRemovedTransactions]); +} +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/ProductRequestHandlerTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/ProductRequestHandlerTests.m new file mode 100644 index 000000000000..ac36aae5acb5 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/ProductRequestHandlerTests.m @@ -0,0 +1,89 @@ +// 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. + +#import +#import "Stubs.h" + +@import in_app_purchase_storekit; + +#pragma tests start here + +@interface RequestHandlerTest : XCTestCase + +@end + +@implementation RequestHandlerTest + +- (void)testRequestHandlerWithProductRequestSuccess { + SKProductRequestStub *request = + [[SKProductRequestStub alloc] initWithProductIdentifiers:[NSSet setWithArray:@[ @"123" ]]]; + FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get response with 1 product"]; + __block SKProductsResponse *response; + [handler + startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *error) { + response = r; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertNotNil(response); + XCTAssertEqual(response.products.count, 1); + SKProduct *product = response.products.firstObject; + XCTAssertTrue([product.productIdentifier isEqualToString:@"123"]); +} + +- (void)testRequestHandlerWithProductRequestFailure { + SKProductRequestStub *request = [[SKProductRequestStub alloc] + initWithFailureError:[NSError errorWithDomain:@"test" code:123 userInfo:@{}]]; + FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; + XCTestExpectation *expectation = + [self expectationWithDescription:@"expect to get response with 1 product"]; + __block NSError *error; + __block SKProductsResponse *response; + [handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *e) { + error = e; + response = r; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertNotNil(error); + XCTAssertEqual(error.domain, @"test"); + XCTAssertNil(response); +} + +- (void)testRequestHandlerWithRefreshReceiptSuccess { + SKReceiptRefreshRequestStub *request = + [[SKReceiptRefreshRequestStub alloc] initWithReceiptProperties:nil]; + FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; + XCTestExpectation *expectation = [self expectationWithDescription:@"expect no error"]; + __block NSError *e; + [handler + startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *error) { + e = error; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertNil(e); +} + +- (void)testRequestHandlerWithRefreshReceiptFailure { + SKReceiptRefreshRequestStub *request = [[SKReceiptRefreshRequestStub alloc] + initWithFailureError:[NSError errorWithDomain:@"test" code:123 userInfo:@{}]]; + FIAPRequestHandler *handler = [[FIAPRequestHandler alloc] initWithRequest:request]; + XCTestExpectation *expectation = [self expectationWithDescription:@"expect error"]; + __block NSError *error; + __block SKProductsResponse *response; + [handler startProductRequestWithCompletionHandler:^(SKProductsResponse *_Nullable r, NSError *e) { + error = e; + response = r; + [expectation fulfill]; + }]; + [self waitForExpectations:@[ expectation ] timeout:5]; + XCTAssertNotNil(error); + XCTAssertEqual(error.domain, @"test"); + XCTAssertNil(response); +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Stubs.h b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Stubs.h new file mode 100644 index 000000000000..d4e8df3eba72 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Stubs.h @@ -0,0 +1,71 @@ +// 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. + +#import +#import + +@import in_app_purchase_storekit; + +NS_ASSUME_NONNULL_BEGIN +API_AVAILABLE(ios(11.2), macos(10.13.2)) +@interface SKProductSubscriptionPeriodStub : SKProductSubscriptionPeriod +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +API_AVAILABLE(ios(11.2), macos(10.13.2)) +@interface SKProductDiscountStub : SKProductDiscount +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +@interface SKProductStub : SKProduct +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +@interface SKProductRequestStub : SKProductsRequest +- (instancetype)initWithProductIdentifiers:(NSSet *)productIdentifiers; +- (instancetype)initWithFailureError:(NSError *)error; +@end + +@interface SKProductsResponseStub : SKProductsResponse +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +@interface InAppPurchasePluginStub : InAppPurchasePlugin +@end + +@interface SKPaymentQueueStub : SKPaymentQueue +@property(assign, nonatomic) SKPaymentTransactionState testState; +@property(strong, nonatomic, nullable) id observer; +@end + +@interface SKPaymentTransactionStub : SKPaymentTransaction +- (instancetype)initWithMap:(NSDictionary *)map; +- (instancetype)initWithState:(SKPaymentTransactionState)state; +- (instancetype)initWithState:(SKPaymentTransactionState)state payment:(SKPayment *)payment; +@end + +@interface SKMutablePaymentStub : SKMutablePayment +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +@interface NSErrorStub : NSError +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +@interface FIAPReceiptManagerStub : FIAPReceiptManager +// Indicates whether getReceiptData of this stub is going to return an error. +// Setting this to true will let getReceiptData give a basic NSError and return nil. +@property(assign, nonatomic) BOOL returnError; +@end + +@interface SKReceiptRefreshRequestStub : SKReceiptRefreshRequest +- (instancetype)initWithFailureError:(NSError *)error; +@end + +API_AVAILABLE(ios(13.0), macos(10.15)) +@interface SKStorefrontStub : SKStorefront +- (instancetype)initWithMap:(NSDictionary *)map; +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Stubs.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Stubs.m new file mode 100644 index 000000000000..f5e44d78b157 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/Stubs.m @@ -0,0 +1,330 @@ +// 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. + +#import "Stubs.h" + +@implementation SKProductSubscriptionPeriodStub + +- (instancetype)initWithMap:(NSDictionary *)map { + self = [super init]; + if (self) { + [self setValue:map[@"numberOfUnits"] ?: @(0) forKey:@"numberOfUnits"]; + [self setValue:map[@"unit"] ?: @(0) forKey:@"unit"]; + } + return self; +} + +@end + +@implementation SKProductDiscountStub + +- (instancetype)initWithMap:(NSDictionary *)map { + self = [super init]; + if (self) { + [self setValue:[[NSDecimalNumber alloc] initWithString:map[@"price"]] ?: [NSNull null] + forKey:@"price"]; + NSLocale *locale = NSLocale.systemLocale; + [self setValue:locale ?: [NSNull null] forKey:@"priceLocale"]; + [self setValue:map[@"numberOfPeriods"] ?: @(0) forKey:@"numberOfPeriods"]; + SKProductSubscriptionPeriodStub *subscriptionPeriodSub = + [[SKProductSubscriptionPeriodStub alloc] initWithMap:map[@"subscriptionPeriod"]]; + [self setValue:subscriptionPeriodSub forKey:@"subscriptionPeriod"]; + [self setValue:map[@"paymentMode"] ?: @(0) forKey:@"paymentMode"]; + if (@available(iOS 12.2, *)) { + [self setValue:map[@"identifier"] ?: [NSNull null] forKey:@"identifier"]; + [self setValue:map[@"type"] ?: @(0) forKey:@"type"]; + } + } + return self; +} + +@end + +@implementation SKProductStub + +- (instancetype)initWithMap:(NSDictionary *)map { + self = [super init]; + if (self) { + [self setValue:map[@"productIdentifier"] ?: [NSNull null] forKey:@"productIdentifier"]; + [self setValue:map[@"localizedDescription"] ?: [NSNull null] forKey:@"localizedDescription"]; + [self setValue:map[@"localizedTitle"] ?: [NSNull null] forKey:@"localizedTitle"]; + [self setValue:map[@"downloadable"] ?: @NO forKey:@"downloadable"]; + [self setValue:[[NSDecimalNumber alloc] initWithString:map[@"price"]] ?: [NSNull null] + forKey:@"price"]; + NSLocale *locale = NSLocale.systemLocale; + [self setValue:locale ?: [NSNull null] forKey:@"priceLocale"]; + [self setValue:map[@"downloadContentLengths"] ?: @(0) forKey:@"downloadContentLengths"]; + if (@available(iOS 11.2, *)) { + SKProductSubscriptionPeriodStub *period = + [[SKProductSubscriptionPeriodStub alloc] initWithMap:map[@"subscriptionPeriod"]]; + [self setValue:period ?: [NSNull null] forKey:@"subscriptionPeriod"]; + SKProductDiscountStub *discount = + [[SKProductDiscountStub alloc] initWithMap:map[@"introductoryPrice"]]; + [self setValue:discount ?: [NSNull null] forKey:@"introductoryPrice"]; + [self setValue:map[@"subscriptionGroupIdentifier"] ?: [NSNull null] + forKey:@"subscriptionGroupIdentifier"]; + } + if (@available(iOS 12.2, *)) { + NSMutableArray *discounts = [[NSMutableArray alloc] init]; + for (NSDictionary *discountMap in map[@"discounts"]) { + [discounts addObject:[[SKProductDiscountStub alloc] initWithMap:discountMap]]; + } + + [self setValue:discounts forKey:@"discounts"]; + } + } + return self; +} + +- (instancetype)initWithProductID:(NSString *)productIdentifier { + self = [super init]; + if (self) { + [self setValue:productIdentifier forKey:@"productIdentifier"]; + } + return self; +} + +@end + +@interface SKProductRequestStub () + +@property(strong, nonatomic) NSSet *identifers; +@property(strong, nonatomic) NSError *error; + +@end + +@implementation SKProductRequestStub + +- (instancetype)initWithProductIdentifiers:(NSSet *)productIdentifiers { + self = [super initWithProductIdentifiers:productIdentifiers]; + self.identifers = productIdentifiers; + return self; +} + +- (instancetype)initWithFailureError:(NSError *)error { + self = [super init]; + self.error = error; + return self; +} + +- (void)start { + NSMutableArray *productArray = [NSMutableArray new]; + for (NSString *identifier in self.identifers) { + [productArray addObject:@{@"productIdentifier" : identifier}]; + } + SKProductsResponseStub *response = + [[SKProductsResponseStub alloc] initWithMap:@{@"products" : productArray}]; + if (self.error) { + [self.delegate request:self didFailWithError:self.error]; + } else { + [self.delegate productsRequest:self didReceiveResponse:response]; + } +} + +@end + +@implementation SKProductsResponseStub + +- (instancetype)initWithMap:(NSDictionary *)map { + self = [super init]; + if (self) { + NSMutableArray *products = [NSMutableArray new]; + for (NSDictionary *productMap in map[@"products"]) { + SKProductStub *product = [[SKProductStub alloc] initWithMap:productMap]; + [products addObject:product]; + } + [self setValue:products forKey:@"products"]; + } + return self; +} + +@end + +@interface InAppPurchasePluginStub () + +@end + +@implementation InAppPurchasePluginStub + +- (SKProductRequestStub *)getProductRequestWithIdentifiers:(NSSet *)identifiers { + return [[SKProductRequestStub alloc] initWithProductIdentifiers:identifiers]; +} + +- (SKProduct *)getProduct:(NSString *)productID { + return [[SKProductStub alloc] initWithProductID:productID]; +} + +- (SKReceiptRefreshRequestStub *)getRefreshReceiptRequest:(NSDictionary *)properties { + return [[SKReceiptRefreshRequestStub alloc] initWithReceiptProperties:properties]; +} + +@end + +@interface SKPaymentQueueStub () + +@end + +@implementation SKPaymentQueueStub + +- (void)addTransactionObserver:(id)observer { + self.observer = observer; +} + +- (void)removeTransactionObserver:(id)observer { + self.observer = nil; +} + +- (void)addPayment:(SKPayment *)payment { + SKPaymentTransactionStub *transaction = + [[SKPaymentTransactionStub alloc] initWithState:self.testState payment:payment]; + [self.observer paymentQueue:self updatedTransactions:@[ transaction ]]; +} + +- (void)restoreCompletedTransactions { + if ([self.observer + respondsToSelector:@selector(paymentQueueRestoreCompletedTransactionsFinished:)]) { + [self.observer paymentQueueRestoreCompletedTransactionsFinished:self]; + } +} + +- (void)finishTransaction:(SKPaymentTransaction *)transaction { + if ([self.observer respondsToSelector:@selector(paymentQueue:removedTransactions:)]) { + [self.observer paymentQueue:self removedTransactions:@[ transaction ]]; + } +} + +@end + +@implementation SKPaymentTransactionStub { + SKPayment *_payment; +} + +- (instancetype)initWithID:(NSString *)identifier { + self = [super init]; + if (self) { + [self setValue:identifier forKey:@"transactionIdentifier"]; + } + return self; +} + +- (instancetype)initWithMap:(NSDictionary *)map { + self = [super init]; + if (self) { + [self setValue:map[@"transactionIdentifier"] forKey:@"transactionIdentifier"]; + [self setValue:map[@"transactionState"] forKey:@"transactionState"]; + if (![map[@"originalTransaction"] isKindOfClass:[NSNull class]] && + map[@"originalTransaction"]) { + [self setValue:[[SKPaymentTransactionStub alloc] initWithMap:map[@"originalTransaction"]] + forKey:@"originalTransaction"]; + } + [self setValue:map[@"error"] ? [[NSErrorStub alloc] initWithMap:map[@"error"]] : [NSNull null] + forKey:@"error"]; + [self setValue:[NSDate dateWithTimeIntervalSince1970:[map[@"transactionTimeStamp"] doubleValue]] + forKey:@"transactionDate"]; + } + return self; +} + +- (instancetype)initWithState:(SKPaymentTransactionState)state { + self = [super init]; + if (self) { + // Only purchased and restored transactions have transactionIdentifier: + // https://developer.apple.com/documentation/storekit/skpaymenttransaction/1411288-transactionidentifier?language=objc + if (state == SKPaymentTransactionStatePurchased || state == SKPaymentTransactionStateRestored) { + [self setValue:@"fakeID" forKey:@"transactionIdentifier"]; + } + [self setValue:@(state) forKey:@"transactionState"]; + } + return self; +} + +- (instancetype)initWithState:(SKPaymentTransactionState)state payment:(SKPayment *)payment { + self = [super init]; + if (self) { + // Only purchased and restored transactions have transactionIdentifier: + // https://developer.apple.com/documentation/storekit/skpaymenttransaction/1411288-transactionidentifier?language=objc + if (state == SKPaymentTransactionStatePurchased || state == SKPaymentTransactionStateRestored) { + [self setValue:@"fakeID" forKey:@"transactionIdentifier"]; + } + [self setValue:@(state) forKey:@"transactionState"]; + _payment = payment; + } + return self; +} + +- (SKPayment *)payment { + return _payment; +} + +@end + +@implementation NSErrorStub + +- (instancetype)initWithMap:(NSDictionary *)map { + return [self initWithDomain:[map objectForKey:@"domain"] + code:[[map objectForKey:@"code"] integerValue] + userInfo:[map objectForKey:@"userInfo"]]; +} + +@end + +@implementation FIAPReceiptManagerStub : FIAPReceiptManager + +- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error { + if (self.returnError) { + *error = [NSError errorWithDomain:@"test" + code:1 + userInfo:@{ + @"name" : @"test", + @"houseNr" : @5, + @"error" : [[NSError alloc] initWithDomain:@"internalTestDomain" + code:99 + userInfo:nil] + }]; + return nil; + } + NSString *originalString = [NSString stringWithFormat:@"test"]; + return [[NSData alloc] initWithBase64EncodedString:originalString options:kNilOptions]; +} + +@end + +@implementation SKReceiptRefreshRequestStub { + NSError *_error; +} + +- (instancetype)initWithReceiptProperties:(NSDictionary *)properties { + self = [super initWithReceiptProperties:properties]; + return self; +} + +- (instancetype)initWithFailureError:(NSError *)error { + self = [super init]; + _error = error; + return self; +} + +- (void)start { + if (_error) { + [self.delegate request:self didFailWithError:_error]; + } else { + [self.delegate requestDidFinish:self]; + } +} + +@end + +@implementation SKStorefrontStub + +- (instancetype)initWithMap:(NSDictionary *)map { + self = [super init]; + if (self) { + // Set stub values + [self setValue:map[@"countryCode"] forKey:@"countryCode"]; + [self setValue:map[@"identifier"] forKey:@"identifier"]; + } + return self; +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/TranslatorTests.m b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/TranslatorTests.m new file mode 100644 index 000000000000..34d686753762 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/TranslatorTests.m @@ -0,0 +1,416 @@ +// 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. + +#import +#import "Stubs.h" + +@import in_app_purchase_storekit; + +@interface TranslatorTest : XCTestCase + +@property(strong, nonatomic) NSDictionary *periodMap; +@property(strong, nonatomic) NSMutableDictionary *discountMap; +@property(strong, nonatomic) NSMutableDictionary *discountMissingIdentifierMap; +@property(strong, nonatomic) NSMutableDictionary *productMap; +@property(strong, nonatomic) NSDictionary *productResponseMap; +@property(strong, nonatomic) NSDictionary *paymentMap; +@property(copy, nonatomic) NSDictionary *paymentDiscountMap; +@property(strong, nonatomic) NSDictionary *transactionMap; +@property(strong, nonatomic) NSDictionary *errorMap; +@property(strong, nonatomic) NSDictionary *localeMap; +@property(strong, nonatomic) NSDictionary *storefrontMap; +@property(strong, nonatomic) NSDictionary *storefrontAndPaymentTransactionMap; + +@end + +@implementation TranslatorTest + +- (void)setUp { + self.periodMap = @{@"numberOfUnits" : @(0), @"unit" : @(0)}; + + self.discountMap = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"price" : @"1", + @"priceLocale" : [FIAObjectTranslator getMapFromNSLocale:NSLocale.systemLocale], + @"numberOfPeriods" : @1, + @"subscriptionPeriod" : self.periodMap, + @"paymentMode" : @1, + }]; + if (@available(iOS 12.2, *)) { + self.discountMap[@"identifier"] = @"test offer id"; + self.discountMap[@"type"] = @(SKProductDiscountTypeIntroductory); + } + self.discountMissingIdentifierMap = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"price" : @"1", + @"priceLocale" : [FIAObjectTranslator getMapFromNSLocale:NSLocale.systemLocale], + @"numberOfPeriods" : @1, + @"subscriptionPeriod" : self.periodMap, + @"paymentMode" : @1, + @"identifier" : [NSNull null], + @"type" : @0, + }]; + + self.productMap = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"price" : @"1", + @"priceLocale" : [FIAObjectTranslator getMapFromNSLocale:NSLocale.systemLocale], + @"productIdentifier" : @"123", + @"localizedTitle" : @"title", + @"localizedDescription" : @"des", + }]; + if (@available(iOS 11.2, *)) { + self.productMap[@"subscriptionPeriod"] = self.periodMap; + self.productMap[@"introductoryPrice"] = self.discountMap; + } + if (@available(iOS 12.2, *)) { + self.productMap[@"discounts"] = @[ self.discountMap ]; + } + + if (@available(iOS 12.0, *)) { + self.productMap[@"subscriptionGroupIdentifier"] = @"com.group"; + } + + self.productResponseMap = + @{@"products" : @[ self.productMap ], @"invalidProductIdentifiers" : @[]}; + self.paymentMap = @{ + @"productIdentifier" : @"123", + @"requestData" : @"abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh", + @"quantity" : @(2), + @"applicationUsername" : @"app user name", + @"simulatesAskToBuyInSandbox" : @(NO) + }; + self.paymentDiscountMap = @{ + @"identifier" : @"payment_discount_identifier", + @"keyIdentifier" : @"payment_discount_key_identifier", + @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", + @"signature" : @"this is a encrypted signature", + @"timestamp" : @([NSDate date].timeIntervalSince1970), + }; + NSDictionary *originalTransactionMap = @{ + @"transactionIdentifier" : @"567", + @"transactionState" : @(SKPaymentTransactionStatePurchasing), + @"payment" : [NSNull null], + @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" + code:123 + userInfo:@{}]], + @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), + @"originalTransaction" : [NSNull null], + }; + self.transactionMap = @{ + @"transactionIdentifier" : @"567", + @"transactionState" : @(SKPaymentTransactionStatePurchasing), + @"payment" : [NSNull null], + @"error" : [FIAObjectTranslator getMapFromNSError:[NSError errorWithDomain:@"test_stub" + code:123 + userInfo:@{}]], + @"transactionTimeStamp" : @([NSDate date].timeIntervalSince1970), + @"originalTransaction" : originalTransactionMap, + }; + self.errorMap = @{ + @"code" : @(123), + @"domain" : @"test_domain", + @"userInfo" : @{ + @"key" : @"value", + } + }; + self.storefrontMap = @{ + @"countryCode" : @"USA", + @"identifier" : @"unique_identifier", + }; + + self.storefrontAndPaymentTransactionMap = @{ + @"storefront" : self.storefrontMap, + @"transaction" : self.transactionMap, + }; +} + +- (void)testSKProductSubscriptionPeriodStubToMap { + if (@available(iOS 11.2, *)) { + SKProductSubscriptionPeriodStub *period = + [[SKProductSubscriptionPeriodStub alloc] initWithMap:self.periodMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKProductSubscriptionPeriod:period]; + XCTAssertEqualObjects(map, self.periodMap); + } +} + +- (void)testSKProductDiscountStubToMap { + if (@available(iOS 11.2, *)) { + SKProductDiscountStub *discount = [[SKProductDiscountStub alloc] initWithMap:self.discountMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKProductDiscount:discount]; + XCTAssertEqualObjects(map, self.discountMap); + } +} + +- (void)testProductToMap { + SKProductStub *product = [[SKProductStub alloc] initWithMap:self.productMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKProduct:product]; + XCTAssertEqualObjects(map, self.productMap); +} + +- (void)testProductResponseToMap { + SKProductsResponseStub *response = + [[SKProductsResponseStub alloc] initWithMap:self.productResponseMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKProductsResponse:response]; + XCTAssertEqualObjects(map, self.productResponseMap); +} + +- (void)testPaymentToMap { + SKMutablePayment *payment = [FIAObjectTranslator getSKMutablePaymentFromMap:self.paymentMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKPayment:payment]; + XCTAssertEqualObjects(map, self.paymentMap); +} + +- (void)testPaymentTransactionToMap { + // payment is not KVC, cannot test payment field. + SKPaymentTransactionStub *paymentTransaction = + [[SKPaymentTransactionStub alloc] initWithMap:self.transactionMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKPaymentTransaction:paymentTransaction]; + XCTAssertEqualObjects(map, self.transactionMap); +} + +- (void)testError { + NSErrorStub *error = [[NSErrorStub alloc] initWithMap:self.errorMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error]; + XCTAssertEqualObjects(map, self.errorMap); +} + +- (void)testErrorWithNSNumberAsUserInfo { + NSError *error = [NSError errorWithDomain:SKErrorDomain code:3 userInfo:@{@"key" : @42}]; + NSDictionary *expectedMap = + @{@"domain" : SKErrorDomain, @"code" : @3, @"userInfo" : @{@"key" : @42}}; + NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error]; + XCTAssertEqualObjects(expectedMap, map); +} + +- (void)testErrorWithMultipleUnderlyingErrors { + NSError *underlyingErrorOne = [NSError errorWithDomain:SKErrorDomain code:2 userInfo:nil]; + NSError *underlyingErrorTwo = [NSError errorWithDomain:SKErrorDomain code:1 userInfo:nil]; + NSError *mainError = [NSError + errorWithDomain:SKErrorDomain + code:3 + userInfo:@{@"underlyingErrors" : @[ underlyingErrorOne, underlyingErrorTwo ]}]; + NSDictionary *expectedMap = @{ + @"domain" : SKErrorDomain, + @"code" : @3, + @"userInfo" : @{ + @"underlyingErrors" : @[ + @{@"domain" : SKErrorDomain, @"code" : @2, @"userInfo" : @{}}, + @{@"domain" : SKErrorDomain, @"code" : @1, @"userInfo" : @{}} + ] + } + }; + NSDictionary *map = [FIAObjectTranslator getMapFromNSError:mainError]; + XCTAssertEqualObjects(expectedMap, map); +} + +- (void)testErrorWithUnsupportedUserInfo { + NSError *error = [NSError errorWithDomain:SKErrorDomain + code:3 + userInfo:@{@"user_info" : [[NSObject alloc] init]}]; + NSDictionary *expectedMap = @{ + @"domain" : SKErrorDomain, + @"code" : @3, + @"userInfo" : @{ + @"user_info" : [NSString + stringWithFormat: + @"Unable to encode native userInfo object of type %@ to map. Please submit an " + @"issue at https://github.com/flutter/flutter/issues/new with the title " + @"\"[in_app_purchase_storekit] Unable to encode userInfo of type %@\" and add " + @"reproduction steps and the error details in the description field.", + [NSObject class], [NSObject class]] + } + }; + NSDictionary *map = [FIAObjectTranslator getMapFromNSError:error]; + XCTAssertEqualObjects(expectedMap, map); +} + +- (void)testLocaleToMap { + if (@available(iOS 10.0, *)) { + NSLocale *system = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; + NSDictionary *map = [FIAObjectTranslator getMapFromNSLocale:system]; + XCTAssertEqualObjects(map[@"currencySymbol"], system.currencySymbol); + XCTAssertEqualObjects(map[@"countryCode"], system.countryCode); + } +} + +- (void)testSKStorefrontToMap { + if (@available(iOS 13.0, *)) { + SKStorefront *storefront = [[SKStorefrontStub alloc] initWithMap:self.storefrontMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKStorefront:storefront]; + XCTAssertEqualObjects(map, self.storefrontMap); + } +} + +- (void)testSKStorefrontAndSKPaymentTransactionToMap { + if (@available(iOS 13.0, *)) { + SKStorefront *storefront = [[SKStorefrontStub alloc] initWithMap:self.storefrontMap]; + SKPaymentTransaction *transaction = + [[SKPaymentTransactionStub alloc] initWithMap:self.transactionMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKStorefront:storefront + andSKPaymentTransaction:transaction]; + XCTAssertEqualObjects(map, self.storefrontAndPaymentTransactionMap); + } +} + +- (void)testSKPaymentDiscountFromMap { + if (@available(iOS 12.2, *)) { + NSString *error = nil; + SKPaymentDiscount *paymentDiscount = + [FIAObjectTranslator getSKPaymentDiscountFromMap:self.paymentDiscountMap withError:&error]; + + XCTAssertEqual(paymentDiscount.identifier, self.paymentDiscountMap[@"identifier"]); + XCTAssertEqual(paymentDiscount.keyIdentifier, self.paymentDiscountMap[@"keyIdentifier"]); + XCTAssertEqualObjects(paymentDiscount.nonce, + [[NSUUID alloc] initWithUUIDString:self.paymentDiscountMap[@"nonce"]]); + XCTAssertEqual(paymentDiscount.signature, self.paymentDiscountMap[@"signature"]); + XCTAssertEqual(paymentDiscount.timestamp, self.paymentDiscountMap[@"timestamp"]); + } +} + +- (void)testSKPaymentDiscountFromMapMissingIdentifier { + if (@available(iOS 12.2, *)) { + NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; + + for (id value in invalidValues) { + NSDictionary *discountMap = @{ + @"identifier" : value, + @"keyIdentifier" : @"payment_discount_key_identifier", + @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", + @"signature" : @"this is a encrypted signature", + @"timestamp" : @([NSDate date].timeIntervalSince1970), + }; + + NSString *error = nil; + [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; + + XCTAssertNotNil(error); + XCTAssertEqualObjects( + error, @"When specifying a payment discount the 'identifier' field is mandatory."); + } + } +} + +- (void)testGetMapFromSKProductDiscountMissingIdentifier { + if (@available(iOS 12.2, *)) { + SKProductDiscountStub *discount = + [[SKProductDiscountStub alloc] initWithMap:self.discountMissingIdentifierMap]; + NSDictionary *map = [FIAObjectTranslator getMapFromSKProductDiscount:discount]; + XCTAssertEqualObjects(map, self.discountMissingIdentifierMap); + } +} + +- (void)testSKPaymentDiscountFromMapMissingKeyIdentifier { + if (@available(iOS 12.2, *)) { + NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; + + for (id value in invalidValues) { + NSDictionary *discountMap = @{ + @"identifier" : @"payment_discount_identifier", + @"keyIdentifier" : value, + @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", + @"signature" : @"this is a encrypted signature", + @"timestamp" : @([NSDate date].timeIntervalSince1970), + }; + + NSString *error = nil; + [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; + + XCTAssertNotNil(error); + XCTAssertEqualObjects( + error, @"When specifying a payment discount the 'keyIdentifier' field is mandatory."); + } + } +} + +- (void)testSKPaymentDiscountFromMapMissingNonce { + if (@available(iOS 12.2, *)) { + NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; + + for (id value in invalidValues) { + NSDictionary *discountMap = @{ + @"identifier" : @"payment_discount_identifier", + @"keyIdentifier" : @"payment_discount_key_identifier", + @"nonce" : value, + @"signature" : @"this is a encrypted signature", + @"timestamp" : @([NSDate date].timeIntervalSince1970), + }; + + NSString *error = nil; + [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; + + XCTAssertNotNil(error); + XCTAssertEqualObjects(error, + @"When specifying a payment discount the 'nonce' field is mandatory."); + } + } +} + +- (void)testSKPaymentDiscountFromMapMissingSignature { + if (@available(iOS 12.2, *)) { + NSArray *invalidValues = @[ [NSNull null], @(1), @"" ]; + + for (id value in invalidValues) { + NSDictionary *discountMap = @{ + @"identifier" : @"payment_discount_identifier", + @"keyIdentifier" : @"payment_discount_key_identifier", + @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", + @"signature" : value, + @"timestamp" : @([NSDate date].timeIntervalSince1970), + }; + + NSString *error = nil; + [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; + + XCTAssertNotNil(error); + XCTAssertEqualObjects( + error, @"When specifying a payment discount the 'signature' field is mandatory."); + } + } +} + +- (void)testSKPaymentDiscountFromMapMissingTimestamp { + if (@available(iOS 12.2, *)) { + NSArray *invalidValues = @[ [NSNull null], @"", @(-1) ]; + + for (id value in invalidValues) { + NSDictionary *discountMap = @{ + @"identifier" : @"payment_discount_identifier", + @"keyIdentifier" : @"payment_discount_key_identifier", + @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", + @"signature" : @"this is a encrypted signature", + @"timestamp" : value, + }; + + NSString *error = nil; + [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; + + XCTAssertNotNil(error); + XCTAssertEqualObjects( + error, @"When specifying a payment discount the 'timestamp' field is mandatory."); + } + } +} + +- (void)testSKPaymentDiscountFromMapOverflowingTimestamp { + if (@available(iOS 12.2, *)) { + NSDictionary *discountMap = @{ + @"identifier" : @"payment_discount_identifier", + @"keyIdentifier" : @"payment_discount_key_identifier", + @"nonce" : @"d18981e0-9003-4365-98a2-4b90e3b62c52", + @"signature" : @"this is a encrypted signature", + @"timestamp" : @1665044583595, // timestamp 2022 Oct + }; + NSString *error = nil; + SKPaymentDiscount *paymentDiscount = + [FIAObjectTranslator getSKPaymentDiscountFromMap:discountMap withError:&error]; + XCTAssertNil(error); + XCTAssertNotNil(paymentDiscount); + XCTAssertEqual(paymentDiscount.identifier, discountMap[@"identifier"]); + XCTAssertEqual(paymentDiscount.keyIdentifier, discountMap[@"keyIdentifier"]); + XCTAssertEqualObjects(paymentDiscount.nonce, + [[NSUUID alloc] initWithUUIDString:discountMap[@"nonce"]]); + XCTAssertEqual(paymentDiscount.signature, discountMap[@"signature"]); + XCTAssertEqual(paymentDiscount.timestamp, discountMap[@"timestamp"]); + } +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Assets/.gitkeep b/packages/in_app_purchase/in_app_purchase_storekit/ios/Assets/.gitkeep deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Assets/.gitkeep b/packages/in_app_purchase/in_app_purchase_storekit/ios/Assets/.gitkeep new file mode 120000 index 000000000000..bf2007784034 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Assets/.gitkeep @@ -0,0 +1 @@ +../../shared/Assets/.gitkeep \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.h deleted file mode 100644 index eb97ceb44754..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.h +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface FIAObjectTranslator : NSObject - -// Converts an instance of SKProduct into a dictionary. -+ (NSDictionary *)getMapFromSKProduct:(SKProduct *)product; - -// Converts an instance of SKProductSubscriptionPeriod into a dictionary. -+ (NSDictionary *)getMapFromSKProductSubscriptionPeriod:(SKProductSubscriptionPeriod *)period - API_AVAILABLE(ios(11.2)); - -// Converts an instance of SKProductDiscount into a dictionary. -+ (NSDictionary *)getMapFromSKProductDiscount:(SKProductDiscount *)discount - API_AVAILABLE(ios(11.2)); - -// Converts an array of SKProductDiscount instances into an array of dictionaries. -+ (nonnull NSArray *)getMapArrayFromSKProductDiscounts: - (nonnull NSArray *)productDiscounts API_AVAILABLE(ios(12.2)); - -// Converts an instance of SKProductsResponse into a dictionary. -+ (NSDictionary *)getMapFromSKProductsResponse:(SKProductsResponse *)productResponse; - -// Converts an instance of SKPayment into a dictionary. -+ (NSDictionary *)getMapFromSKPayment:(SKPayment *)payment; - -// Converts an instance of NSLocale into a dictionary. -+ (NSDictionary *)getMapFromNSLocale:(NSLocale *)locale; - -// Creates an instance of the SKMutablePayment class based on the supplied dictionary. -+ (SKMutablePayment *)getSKMutablePaymentFromMap:(NSDictionary *)map; - -// Converts an instance of SKPaymentTransaction into a dictionary. -+ (NSDictionary *)getMapFromSKPaymentTransaction:(SKPaymentTransaction *)transaction; - -// Converts an instance of NSError into a dictionary. -+ (NSDictionary *)getMapFromNSError:(NSError *)error; - -// Converts an instance of SKStorefront into a dictionary. -+ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront - API_AVAILABLE(ios(13), macos(10.15), watchos(6.2)); - -// Converts the supplied instances of SKStorefront and SKPaymentTransaction into a dictionary. -+ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront - andSKPaymentTransaction:(SKPaymentTransaction *)transaction - API_AVAILABLE(ios(13), macos(10.15), watchos(6.2)); - -// Creates an instance of the SKPaymentDiscount class based on the supplied dictionary. -+ (nullable SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map - withError:(NSString *_Nullable *_Nullable)error - API_AVAILABLE(ios(12.2)); - -@end -; - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.h new file mode 120000 index 000000000000..8c80f07ea9a6 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.h @@ -0,0 +1 @@ +../../shared/Classes/FIAObjectTranslator.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.m deleted file mode 100644 index c656b58808b3..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.m +++ /dev/null @@ -1,297 +0,0 @@ -// 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. - -#import "FIAObjectTranslator.h" - -#pragma mark - SKProduct Coders - -@implementation FIAObjectTranslator - -+ (NSDictionary *)getMapFromSKProduct:(SKProduct *)product { - if (!product) { - return nil; - } - NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"localizedDescription" : product.localizedDescription ?: [NSNull null], - @"localizedTitle" : product.localizedTitle ?: [NSNull null], - @"productIdentifier" : product.productIdentifier ?: [NSNull null], - @"price" : product.price.description ?: [NSNull null] - - }]; - // TODO(cyanglaz): NSLocale is a complex object, want to see the actual need of getting this - // expanded to a map. Matching android to only get the currencySymbol for now. - // https://github.com/flutter/flutter/issues/26610 - [map setObject:[FIAObjectTranslator getMapFromNSLocale:product.priceLocale] ?: [NSNull null] - forKey:@"priceLocale"]; - if (@available(iOS 11.2, *)) { - [map setObject:[FIAObjectTranslator - getMapFromSKProductSubscriptionPeriod:product.subscriptionPeriod] - ?: [NSNull null] - forKey:@"subscriptionPeriod"]; - } - if (@available(iOS 11.2, *)) { - [map setObject:[FIAObjectTranslator getMapFromSKProductDiscount:product.introductoryPrice] - ?: [NSNull null] - forKey:@"introductoryPrice"]; - } - if (@available(iOS 12.2, *)) { - [map setObject:[FIAObjectTranslator getMapArrayFromSKProductDiscounts:product.discounts] - forKey:@"discounts"]; - } - if (@available(iOS 12.0, *)) { - [map setObject:product.subscriptionGroupIdentifier ?: [NSNull null] - forKey:@"subscriptionGroupIdentifier"]; - } - return map; -} - -+ (NSDictionary *)getMapFromSKProductSubscriptionPeriod:(SKProductSubscriptionPeriod *)period { - if (!period) { - return nil; - } - return @{@"numberOfUnits" : @(period.numberOfUnits), @"unit" : @(period.unit)}; -} - -+ (nonnull NSArray *)getMapArrayFromSKProductDiscounts: - (nonnull NSArray *)productDiscounts { - NSMutableArray *discountsMapArray = [[NSMutableArray alloc] init]; - - for (SKProductDiscount *productDiscount in productDiscounts) { - [discountsMapArray addObject:[FIAObjectTranslator getMapFromSKProductDiscount:productDiscount]]; - } - - return discountsMapArray; -} - -+ (NSDictionary *)getMapFromSKProductDiscount:(SKProductDiscount *)discount { - if (!discount) { - return nil; - } - NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"price" : discount.price.description ?: [NSNull null], - @"numberOfPeriods" : @(discount.numberOfPeriods), - @"subscriptionPeriod" : - [FIAObjectTranslator getMapFromSKProductSubscriptionPeriod:discount.subscriptionPeriod] - ?: [NSNull null], - @"paymentMode" : @(discount.paymentMode), - }]; - if (@available(iOS 12.2, *)) { - [map setObject:discount.identifier ?: [NSNull null] forKey:@"identifier"]; - [map setObject:@(discount.type) forKey:@"type"]; - } - - // TODO(cyanglaz): NSLocale is a complex object, want to see the actual need of getting this - // expanded to a map. Matching android to only get the currencySymbol for now. - // https://github.com/flutter/flutter/issues/26610 - [map setObject:[FIAObjectTranslator getMapFromNSLocale:discount.priceLocale] ?: [NSNull null] - forKey:@"priceLocale"]; - return map; -} - -+ (NSDictionary *)getMapFromSKProductsResponse:(SKProductsResponse *)productResponse { - if (!productResponse) { - return nil; - } - NSMutableArray *productsMapArray = [NSMutableArray new]; - for (SKProduct *product in productResponse.products) { - [productsMapArray addObject:[FIAObjectTranslator getMapFromSKProduct:product]]; - } - return @{ - @"products" : productsMapArray, - @"invalidProductIdentifiers" : productResponse.invalidProductIdentifiers ?: @[] - }; -} - -+ (NSDictionary *)getMapFromSKPayment:(SKPayment *)payment { - if (!payment) { - return nil; - } - NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"productIdentifier" : payment.productIdentifier ?: [NSNull null], - @"requestData" : payment.requestData ? [[NSString alloc] initWithData:payment.requestData - encoding:NSUTF8StringEncoding] - : [NSNull null], - @"quantity" : @(payment.quantity), - @"applicationUsername" : payment.applicationUsername ?: [NSNull null] - }]; - [map setObject:@(payment.simulatesAskToBuyInSandbox) forKey:@"simulatesAskToBuyInSandbox"]; - return map; -} - -+ (NSDictionary *)getMapFromNSLocale:(NSLocale *)locale { - if (!locale) { - return nil; - } - NSMutableDictionary *map = [[NSMutableDictionary alloc] init]; - [map setObject:[locale objectForKey:NSLocaleCurrencySymbol] ?: [NSNull null] - forKey:@"currencySymbol"]; - [map setObject:[locale objectForKey:NSLocaleCurrencyCode] ?: [NSNull null] - forKey:@"currencyCode"]; - [map setObject:[locale objectForKey:NSLocaleCountryCode] ?: [NSNull null] forKey:@"countryCode"]; - return map; -} - -+ (SKMutablePayment *)getSKMutablePaymentFromMap:(NSDictionary *)map { - if (!map) { - return nil; - } - SKMutablePayment *payment = [[SKMutablePayment alloc] init]; - payment.productIdentifier = map[@"productIdentifier"]; - NSString *utf8String = map[@"requestData"]; - payment.requestData = [utf8String dataUsingEncoding:NSUTF8StringEncoding]; - payment.quantity = [map[@"quantity"] integerValue]; - payment.applicationUsername = map[@"applicationUsername"]; - payment.simulatesAskToBuyInSandbox = [map[@"simulatesAskToBuyInSandbox"] boolValue]; - return payment; -} - -+ (NSDictionary *)getMapFromSKPaymentTransaction:(SKPaymentTransaction *)transaction { - if (!transaction) { - return nil; - } - NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"error" : [FIAObjectTranslator getMapFromNSError:transaction.error] ?: [NSNull null], - @"payment" : transaction.payment ? [FIAObjectTranslator getMapFromSKPayment:transaction.payment] - : [NSNull null], - @"originalTransaction" : transaction.originalTransaction - ? [FIAObjectTranslator getMapFromSKPaymentTransaction:transaction.originalTransaction] - : [NSNull null], - @"transactionTimeStamp" : transaction.transactionDate - ? @(transaction.transactionDate.timeIntervalSince1970) - : [NSNull null], - @"transactionIdentifier" : transaction.transactionIdentifier ?: [NSNull null], - @"transactionState" : @(transaction.transactionState) - }]; - - return map; -} - -+ (NSDictionary *)getMapFromNSError:(NSError *)error { - if (!error) { - return nil; - } - - NSMutableDictionary *userInfo = [NSMutableDictionary new]; - for (NSErrorUserInfoKey key in error.userInfo) { - id value = error.userInfo[key]; - userInfo[key] = [FIAObjectTranslator encodeNSErrorUserInfo:value]; - } - return @{@"code" : @(error.code), @"domain" : error.domain ?: @"", @"userInfo" : userInfo}; -} - -+ (id)encodeNSErrorUserInfo:(id)value { - if ([value isKindOfClass:[NSError class]]) { - return [FIAObjectTranslator getMapFromNSError:value]; - } else if ([value isKindOfClass:[NSURL class]]) { - return [value absoluteString]; - } else if ([value isKindOfClass:[NSNumber class]]) { - return value; - } else if ([value isKindOfClass:[NSString class]]) { - return value; - } else if ([value isKindOfClass:[NSArray class]]) { - NSMutableArray *errors = [[NSMutableArray alloc] init]; - for (id error in value) { - [errors addObject:[FIAObjectTranslator encodeNSErrorUserInfo:error]]; - } - return errors; - } else { - return [NSString - stringWithFormat: - @"Unable to encode native userInfo object of type %@ to map. Please submit an issue at " - @"https://github.com/flutter/flutter/issues/new with the title " - @"\"[in_app_purchase_storekit] " - @"Unable to encode userInfo of type %@\" and add reproduction steps and the error " - @"details in " - @"the description field.", - [value class], [value class]]; - } -} - -+ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront { - if (!storefront) { - return nil; - } - - NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"countryCode" : storefront.countryCode, - @"identifier" : storefront.identifier - }]; - - return map; -} - -+ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront - andSKPaymentTransaction:(SKPaymentTransaction *)transaction { - if (!storefront || !transaction) { - return nil; - } - - NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ - @"storefront" : [FIAObjectTranslator getMapFromSKStorefront:storefront], - @"transaction" : [FIAObjectTranslator getMapFromSKPaymentTransaction:transaction] - }]; - - return map; -} - -+ (SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map - withError:(NSString **)error { - if (!map || map.count <= 0) { - return nil; - } - - NSString *identifier = map[@"identifier"]; - NSString *keyIdentifier = map[@"keyIdentifier"]; - NSString *nonce = map[@"nonce"]; - NSString *signature = map[@"signature"]; - NSNumber *timestamp = map[@"timestamp"]; - - if (!identifier || ![identifier isKindOfClass:NSString.class] || - [identifier isEqualToString:@""]) { - if (error) { - *error = @"When specifying a payment discount the 'identifier' field is mandatory."; - } - return nil; - } - - if (!keyIdentifier || ![keyIdentifier isKindOfClass:NSString.class] || - [keyIdentifier isEqualToString:@""]) { - if (error) { - *error = @"When specifying a payment discount the 'keyIdentifier' field is mandatory."; - } - return nil; - } - - if (!nonce || ![nonce isKindOfClass:NSString.class] || [nonce isEqualToString:@""]) { - if (error) { - *error = @"When specifying a payment discount the 'nonce' field is mandatory."; - } - return nil; - } - - if (!signature || ![signature isKindOfClass:NSString.class] || [signature isEqualToString:@""]) { - if (error) { - *error = @"When specifying a payment discount the 'signature' field is mandatory."; - } - return nil; - } - - if (!timestamp || ![timestamp isKindOfClass:NSNumber.class] || [timestamp longLongValue] <= 0) { - if (error) { - *error = @"When specifying a payment discount the 'timestamp' field is mandatory."; - } - return nil; - } - - SKPaymentDiscount *discount = - [[SKPaymentDiscount alloc] initWithIdentifier:identifier - keyIdentifier:keyIdentifier - nonce:[[NSUUID alloc] initWithUUIDString:nonce] - signature:signature - timestamp:timestamp]; - - return discount; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.m new file mode 120000 index 000000000000..643df24599b8 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAObjectTranslator.m @@ -0,0 +1 @@ +../../shared/Classes/FIAObjectTranslator.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.h deleted file mode 100644 index a6c91fa9e6b6..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.h +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -#import -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -API_AVAILABLE(ios(13)) -@interface FIAPPaymentQueueDelegate : NSObject -- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel; -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.h new file mode 120000 index 000000000000..5e54d74d187a --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPPaymentQueueDelegate.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.m deleted file mode 100644 index 1056086030a5..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.m +++ /dev/null @@ -1,78 +0,0 @@ -// 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. - -#import "FIAPPaymentQueueDelegate.h" -#import "FIAObjectTranslator.h" - -@interface FIAPPaymentQueueDelegate () - -@property(strong, nonatomic, readonly) FlutterMethodChannel *callbackChannel; - -@end - -@implementation FIAPPaymentQueueDelegate - -- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel { - self = [super init]; - if (self) { - _callbackChannel = methodChannel; - } - - return self; -} - -- (BOOL)paymentQueue:(SKPaymentQueue *)paymentQueue - shouldContinueTransaction:(SKPaymentTransaction *)transaction - inStorefront:(SKStorefront *)newStorefront { - // Default return value for this method is true (see - // https://developer.apple.com/documentation/storekit/skpaymentqueuedelegate/3521328-paymentqueueshouldshowpriceconse?language=objc) - __block BOOL shouldContinue = YES; - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - [self.callbackChannel invokeMethod:@"shouldContinueTransaction" - arguments:[FIAObjectTranslator getMapFromSKStorefront:newStorefront - andSKPaymentTransaction:transaction] - result:^(id _Nullable result) { - // When result is a valid instance of NSNumber use it to determine - // if the transaction should continue. Otherwise use the default - // value. - if (result && [result isKindOfClass:[NSNumber class]]) { - shouldContinue = [(NSNumber *)result boolValue]; - } - - dispatch_semaphore_signal(semaphore); - }]; - - // The client should respond within 1 second otherwise continue - // with default value. - dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC)); - - return shouldContinue; -} - -- (BOOL)paymentQueueShouldShowPriceConsent:(SKPaymentQueue *)paymentQueue { - // Default return value for this method is true (see - // https://developer.apple.com/documentation/storekit/skpaymentqueuedelegate/3521328-paymentqueueshouldshowpriceconse?language=objc) - __block BOOL shouldShowPriceConsent = YES; - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - [self.callbackChannel invokeMethod:@"shouldShowPriceConsent" - arguments:nil - result:^(id _Nullable result) { - // When result is a valid instance of NSNumber use it to determine - // if the transaction should continue. Otherwise use the default - // value. - if (result && [result isKindOfClass:[NSNumber class]]) { - shouldShowPriceConsent = [(NSNumber *)result boolValue]; - } - - dispatch_semaphore_signal(semaphore); - }]; - - // The client should respond within 1 second otherwise continue - // with default value. - dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC)); - - return shouldShowPriceConsent; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.m new file mode 120000 index 000000000000..f972e7d7c7e8 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPPaymentQueueDelegate.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPPaymentQueueDelegate.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.h deleted file mode 100644 index 94020ff2348b..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.h +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class FlutterError; - -@interface FIAPReceiptManager : NSObject - -- (nullable NSString *)retrieveReceiptWithError:(FlutterError *_Nullable *_Nullable)error; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.h new file mode 120000 index 000000000000..f5c64da51bf3 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPReceiptManager.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.m deleted file mode 100644 index b359b415d873..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.m +++ /dev/null @@ -1,38 +0,0 @@ -// 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. - -#import "FIAPReceiptManager.h" -#import -#import "FIAObjectTranslator.h" - -@interface FIAPReceiptManager () -// Gets the receipt file data from the location of the url. Can be nil if -// there is an error. This interface is defined so it can be stubbed for testing. -- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error; - -@end - -@implementation FIAPReceiptManager - -- (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError { - NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; - NSError *receiptError; - NSData *receipt = [self getReceiptData:receiptURL error:&receiptError]; - if (!receipt || receiptError) { - if (flutterError) { - NSDictionary *errorMap = [FIAObjectTranslator getMapFromNSError:receiptError]; - *flutterError = [FlutterError errorWithCode:errorMap[@"code"] - message:errorMap[@"domain"] - details:errorMap[@"userInfo"]]; - } - return nil; - } - return [receipt base64EncodedStringWithOptions:kNilOptions]; -} - -- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error { - return [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:error]; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.m new file mode 120000 index 000000000000..7cc0593abb34 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPReceiptManager.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPReceiptManager.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.h deleted file mode 100644 index cbf21d6e161f..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.h +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -typedef void (^ProductRequestCompletion)(SKProductsResponse *_Nullable response, - NSError *_Nullable errror); - -@interface FIAPRequestHandler : NSObject - -- (instancetype)initWithRequest:(SKRequest *)request; -- (void)startProductRequestWithCompletionHandler:(ProductRequestCompletion)completion; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.h new file mode 120000 index 000000000000..b008c38df4bb --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPRequestHandler.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.m deleted file mode 100644 index 8767265d8544..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.m +++ /dev/null @@ -1,55 +0,0 @@ -// 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. - -#import "FIAPRequestHandler.h" -#import - -#pragma mark - Main Handler - -@interface FIAPRequestHandler () - -@property(copy, nonatomic) ProductRequestCompletion completion; -@property(strong, nonatomic) SKRequest *request; - -@end - -@implementation FIAPRequestHandler - -- (instancetype)initWithRequest:(SKRequest *)request { - self = [super init]; - if (self) { - self.request = request; - request.delegate = self; - } - return self; -} - -- (void)startProductRequestWithCompletionHandler:(ProductRequestCompletion)completion { - self.completion = completion; - [self.request start]; -} - -- (void)productsRequest:(SKProductsRequest *)request - didReceiveResponse:(SKProductsResponse *)response { - if (self.completion) { - self.completion(response, nil); - // set the completion to nil here so self.completion won't be triggered again in - // requestDidFinish for SKProductRequest. - self.completion = nil; - } -} - -- (void)requestDidFinish:(SKRequest *)request { - if (self.completion) { - self.completion(nil, nil); - } -} - -- (void)request:(SKRequest *)request didFailWithError:(NSError *)error { - if (self.completion) { - self.completion(nil, error); - } -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.m new file mode 120000 index 000000000000..22a1ba3a7c48 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPRequestHandler.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPRequestHandler.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.h deleted file mode 100644 index bb074aa6c577..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.h +++ /dev/null @@ -1,132 +0,0 @@ -// 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. - -#import -#import -#import "FIATransactionCache.h" - -@class SKPaymentTransaction; - -NS_ASSUME_NONNULL_BEGIN - -typedef void (^TransactionsUpdated)(NSArray *transactions); -typedef void (^TransactionsRemoved)(NSArray *transactions); -typedef void (^RestoreTransactionFailed)(NSError *error); -typedef void (^RestoreCompletedTransactionsFinished)(void); -typedef BOOL (^ShouldAddStorePayment)(SKPayment *payment, SKProduct *product); -typedef void (^UpdatedDownloads)(NSArray *downloads); - -@interface FIAPaymentQueueHandler : NSObject - -@property(NS_NONATOMIC_IOSONLY, weak, nullable) id delegate API_AVAILABLE( - ios(13.0), macos(10.15), watchos(6.2)); - -/// Creates a new FIAPaymentQueueHandler initialized with an empty -/// FIATransactionCache. -/// -/// @param queue The SKPaymentQueue instance connected to the App Store and -/// responsible for processing transactions. -/// @param transactionsUpdated Callback method that is called each time the App -/// Store indicates transactions are updated. -/// @param transactionsRemoved Callback method that is called each time the App -/// Store indicates transactions are removed. -/// @param restoreTransactionFailed Callback method that is called each time -/// the App Store indicates transactions failed -/// to restore. -/// @param restoreCompletedTransactionsFinished Callback method that is called -/// each time the App Store -/// indicates restoring of -/// transactions has finished. -/// @param shouldAddStorePayment Callback method that is called each time an -/// in-app purchase has been initiated from the -/// App Store. -/// @param updatedDownloads Callback method that is called each time the App -/// Store indicates downloads are updated. -- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue - transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated - transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved - restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed - restoreCompletedTransactionsFinished: - (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished - shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment - updatedDownloads:(nullable UpdatedDownloads)updatedDownloads - DEPRECATED_MSG_ATTRIBUTE( - "Use the " - "'initWithQueue:transactionsUpdated:transactionsRemoved:restoreTransactionsFinished:" - "shouldAddStorePayment:updatedDownloads:transactionCache:' message instead."); - -/// Creates a new FIAPaymentQueueHandler. -/// -/// The "transactionsUpdated", "transactionsRemoved" and "updatedDownloads" -/// callbacks are only called while actively observing transactions. To start -/// observing transactions send the "startObservingPaymentQueue" message. -/// Sending the "stopObservingPaymentQueue" message will stop actively -/// observing transactions. When transactions are not observed they are cached -/// to the "transactionCache" and will be delivered via the -/// "transactionsUpdated", "transactionsRemoved" and "updatedDownloads" -/// callbacks as soon as the "startObservingPaymentQueue" message arrives. -/// -/// Note: cached transactions that are not processed when the application is -/// killed will be delivered again by the App Store as soon as the application -/// starts again. -/// -/// @param queue The SKPaymentQueue instance connected to the App Store and -/// responsible for processing transactions. -/// @param transactionsUpdated Callback method that is called each time the App -/// Store indicates transactions are updated. -/// @param transactionsRemoved Callback method that is called each time the App -/// Store indicates transactions are removed. -/// @param restoreTransactionFailed Callback method that is called each time -/// the App Store indicates transactions failed -/// to restore. -/// @param restoreCompletedTransactionsFinished Callback method that is called -/// each time the App Store -/// indicates restoring of -/// transactions has finished. -/// @param shouldAddStorePayment Callback method that is called each time an -/// in-app purchase has been initiated from the -/// App Store. -/// @param updatedDownloads Callback method that is called each time the App -/// Store indicates downloads are updated. -/// @param transactionCache An empty [FIATransactionCache] instance that is -/// responsible for keeping track of transactions that -/// arrive when not actively observing transactions. -- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue - transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated - transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved - restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed - restoreCompletedTransactionsFinished: - (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished - shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment - updatedDownloads:(nullable UpdatedDownloads)updatedDownloads - transactionCache:(nonnull FIATransactionCache *)transactionCache; -// Can throw exceptions if the transaction type is purchasing, should always used in a @try block. -- (void)finishTransaction:(nonnull SKPaymentTransaction *)transaction; -- (void)restoreTransactions:(nullable NSString *)applicationName; -- (void)presentCodeRedemptionSheet; -- (NSArray *)getUnfinishedTransactions; - -// This method needs to be called before any other methods. -- (void)startObservingPaymentQueue; -// Call this method when the Flutter app is no longer listening -- (void)stopObservingPaymentQueue; - -// Appends a payment to the SKPaymentQueue. -// -// @param payment Payment object to be added to the payment queue. -// @return whether "addPayment" was successful. -- (BOOL)addPayment:(SKPayment *)payment; - -// Displays the price consent sheet. -// -// The price consent sheet is only displayed when the following -// it true: -// - You have increased the price of the subscription in App Store Connect. -// - The subscriber has not yet responded to a price consent query. -// Otherwise the method has no effect. -- (void)showPriceConsentIfNeeded API_AVAILABLE(ios(13.4)); - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.h new file mode 120000 index 000000000000..8a64356be52e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPaymentQueueHandler.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.m deleted file mode 100644 index 59fdceded2bc..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.m +++ /dev/null @@ -1,232 +0,0 @@ -// 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. - -#import "FIAPaymentQueueHandler.h" -#import "FIAPPaymentQueueDelegate.h" -#import "FIATransactionCache.h" - -@interface FIAPaymentQueueHandler () - -/// The SKPaymentQueue instance connected to the App Store and responsible for processing -/// transactions. -@property(strong, nonatomic) SKPaymentQueue *queue; - -/// Callback method that is called each time the App Store indicates transactions are updated. -@property(nullable, copy, nonatomic) TransactionsUpdated transactionsUpdated; - -/// Callback method that is called each time the App Store indicates transactions are removed. -@property(nullable, copy, nonatomic) TransactionsRemoved transactionsRemoved; - -/// Callback method that is called each time the App Store indicates transactions failed to restore. -@property(nullable, copy, nonatomic) RestoreTransactionFailed restoreTransactionFailed; - -/// Callback method that is called each time the App Store indicates restoring of transactions has -/// finished. -@property(nullable, copy, nonatomic) - RestoreCompletedTransactionsFinished paymentQueueRestoreCompletedTransactionsFinished; - -/// Callback method that is called each time an in-app purchase has been initiated from the App -/// Store. -@property(nullable, copy, nonatomic) ShouldAddStorePayment shouldAddStorePayment; - -/// Callback method that is called each time the App Store indicates downloads are updated. -@property(nullable, copy, nonatomic) UpdatedDownloads updatedDownloads; - -/// The transaction cache responsible for caching transactions. -/// -/// Keeps track of transactions that arrive when the Flutter client is not -/// actively observing for transactions. -@property(strong, nonatomic, nonnull) FIATransactionCache *transactionCache; - -/// Indicates if the Flutter client is observing transactions. -/// -/// When the client is not observing, transactions are cached and send to the -/// client as soon as it starts observing. The Flutter client can start -/// observing by sending a startObservingPaymentQueue message and stop by -/// sending a stopObservingPaymentQueue message. -@property(atomic, assign, readwrite, getter=isObservingTransactions) BOOL observingTransactions; - -@end - -@implementation FIAPaymentQueueHandler - -- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue - transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated - transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved - restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed - restoreCompletedTransactionsFinished: - (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished - shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment - updatedDownloads:(nullable UpdatedDownloads)updatedDownloads { - return [[FIAPaymentQueueHandler alloc] initWithQueue:queue - transactionsUpdated:transactionsUpdated - transactionRemoved:transactionsRemoved - restoreTransactionFailed:restoreTransactionFailed - restoreCompletedTransactionsFinished:restoreCompletedTransactionsFinished - shouldAddStorePayment:shouldAddStorePayment - updatedDownloads:updatedDownloads - transactionCache:[[FIATransactionCache alloc] init]]; -} - -- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue - transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated - transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved - restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed - restoreCompletedTransactionsFinished: - (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished - shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment - updatedDownloads:(nullable UpdatedDownloads)updatedDownloads - transactionCache:(nonnull FIATransactionCache *)transactionCache { - self = [super init]; - if (self) { - _queue = queue; - _transactionsUpdated = transactionsUpdated; - _transactionsRemoved = transactionsRemoved; - _restoreTransactionFailed = restoreTransactionFailed; - _paymentQueueRestoreCompletedTransactionsFinished = restoreCompletedTransactionsFinished; - _shouldAddStorePayment = shouldAddStorePayment; - _updatedDownloads = updatedDownloads; - _transactionCache = transactionCache; - - [_queue addTransactionObserver:self]; - if (@available(iOS 13.0, macOS 10.15, *)) { - queue.delegate = self.delegate; - } - } - return self; -} - -- (void)startObservingPaymentQueue { - self.observingTransactions = YES; - - [self processCachedTransactions]; -} - -- (void)stopObservingPaymentQueue { - // When the client stops observing transaction, the transaction observer is - // not removed from the SKPaymentQueue. The FIAPaymentQueueHandler will cache - // trasnactions in memory when the client is not observing, allowing the app - // to process these transactions if it starts observing again during the same - // lifetime of the app. - // - // If the app is killed, cached transactions will be removed from memory; - // however, the App Store will re-deliver the transactions as soon as the app - // is started again, since the cached transactions have not been acknowledged - // by the client (by sending the `finishTransaction` message). - self.observingTransactions = NO; -} - -- (void)processCachedTransactions { - NSArray *cachedObjects = - [self.transactionCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]; - if (cachedObjects.count != 0) { - self.transactionsUpdated(cachedObjects); - } - - cachedObjects = [self.transactionCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]; - if (cachedObjects.count != 0) { - self.updatedDownloads(cachedObjects); - } - - cachedObjects = [self.transactionCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]; - if (cachedObjects.count != 0) { - self.transactionsRemoved(cachedObjects); - } - - [self.transactionCache clear]; -} - -- (BOOL)addPayment:(SKPayment *)payment { - for (SKPaymentTransaction *transaction in self.queue.transactions) { - if ([transaction.payment.productIdentifier isEqualToString:payment.productIdentifier]) { - return NO; - } - } - [self.queue addPayment:payment]; - return YES; -} - -- (void)finishTransaction:(SKPaymentTransaction *)transaction { - [self.queue finishTransaction:transaction]; -} - -- (void)restoreTransactions:(nullable NSString *)applicationName { - if (applicationName) { - [self.queue restoreCompletedTransactionsWithApplicationUsername:applicationName]; - } else { - [self.queue restoreCompletedTransactions]; - } -} - -- (void)presentCodeRedemptionSheet { - if (@available(iOS 14, *)) { - [self.queue presentCodeRedemptionSheet]; - } else { - NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 or newer"); - } -} - -- (void)showPriceConsentIfNeeded { - [self.queue showPriceConsentIfNeeded]; -} - -#pragma mark - observing - -// Sent when the transaction array has changed (additions or state changes). Client should check -// state of transactions and finish as appropriate. -- (void)paymentQueue:(SKPaymentQueue *)queue - updatedTransactions:(NSArray *)transactions { - if (!self.observingTransactions) { - [_transactionCache addObjects:transactions forKey:TransactionCacheKeyUpdatedTransactions]; - return; - } - - // notify dart through callbacks. - self.transactionsUpdated(transactions); -} - -// Sent when transactions are removed from the queue (via finishTransaction:). -- (void)paymentQueue:(SKPaymentQueue *)queue - removedTransactions:(NSArray *)transactions { - if (!self.observingTransactions) { - [_transactionCache addObjects:transactions forKey:TransactionCacheKeyRemovedTransactions]; - return; - } - self.transactionsRemoved(transactions); -} - -// Sent when an error is encountered while adding transactions from the user's purchase history back -// to the queue. -- (void)paymentQueue:(SKPaymentQueue *)queue - restoreCompletedTransactionsFailedWithError:(NSError *)error { - self.restoreTransactionFailed(error); -} - -// Sent when all transactions from the user's purchase history have successfully been added back to -// the queue. -- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { - self.paymentQueueRestoreCompletedTransactionsFinished(); -} - -// Sent when the download state has changed. -- (void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads { - if (!self.observingTransactions) { - [_transactionCache addObjects:downloads forKey:TransactionCacheKeyUpdatedDownloads]; - return; - } - self.updatedDownloads(downloads); -} - -// Sent when a user initiates an IAP buy from the App Store -- (BOOL)paymentQueue:(SKPaymentQueue *)queue - shouldAddStorePayment:(SKPayment *)payment - forProduct:(SKProduct *)product { - return (self.shouldAddStorePayment(payment, product)); -} - -- (NSArray *)getUnfinishedTransactions { - return self.queue.transactions; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.m new file mode 120000 index 000000000000..87359d2e1c55 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIAPaymentQueueHandler.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPaymentQueueHandler.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.h deleted file mode 100644 index dea3c2d85d14..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.h +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -NS_ASSUME_NONNULL_BEGIN - -typedef NS_ENUM(NSUInteger, TransactionCacheKey) { - TransactionCacheKeyUpdatedDownloads, - TransactionCacheKeyUpdatedTransactions, - TransactionCacheKeyRemovedTransactions -}; - -@interface FIATransactionCache : NSObject - -/// Adds objects to the transaction cache. -/// -/// If the cache already contains an array of objects on the specified key, the supplied -/// array will be appended to the existing array. -- (void)addObjects:(NSArray *)objects forKey:(TransactionCacheKey)key; - -/// Gets the array of objects stored at the given key. -/// -/// If there are no objects associated with the given key nil is returned. -- (NSArray *)getObjectsForKey:(TransactionCacheKey)key; - -/// Removes all objects from the transaction cache. -- (void)clear; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.h new file mode 120000 index 000000000000..1f8f3f92da93 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.h @@ -0,0 +1 @@ +../../shared/Classes/FIATransactionCache.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.m deleted file mode 100644 index f80b9c40c7bc..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.m +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -#import "FIATransactionCache.h" - -@interface FIATransactionCache () - -/// A NSMutableDictionary storing the objects that are cached. -@property(nonatomic, strong, nonnull) NSMutableDictionary *cache; - -@end - -@implementation FIATransactionCache - -- (instancetype)init { - self = [super init]; - if (self) { - self.cache = [[NSMutableDictionary alloc] init]; - } - - return self; -} - -- (void)addObjects:(NSArray *)objects forKey:(TransactionCacheKey)key { - NSArray *cachedObjects = self.cache[@(key)]; - - self.cache[@(key)] = - cachedObjects ? [cachedObjects arrayByAddingObjectsFromArray:objects] : objects; -} - -- (NSArray *)getObjectsForKey:(TransactionCacheKey)key { - return self.cache[@(key)]; -} - -- (void)clear { - [self.cache removeAllObjects]; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.m new file mode 120000 index 000000000000..b27e9811319e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/FIATransactionCache.m @@ -0,0 +1 @@ +../../shared/Classes/FIATransactionCache.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.h deleted file mode 100644 index 8cb42f3fe8c2..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.h +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -#import -@class FIAPaymentQueueHandler; -@class FIAPReceiptManager; - -@interface InAppPurchasePlugin : NSObject - -@property(strong, nonatomic) FIAPaymentQueueHandler *paymentQueueHandler; - -- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager - NS_DESIGNATED_INITIALIZER; -- (instancetype)init NS_UNAVAILABLE; - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.h b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.h new file mode 120000 index 000000000000..d92777687ecd --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.h @@ -0,0 +1 @@ +../../shared/Classes/InAppPurchasePlugin.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.m deleted file mode 100644 index bfc90ea43716..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.m +++ /dev/null @@ -1,438 +0,0 @@ -// 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. - -#import "InAppPurchasePlugin.h" -#import -#import "FIAObjectTranslator.h" -#import "FIAPPaymentQueueDelegate.h" -#import "FIAPReceiptManager.h" -#import "FIAPRequestHandler.h" -#import "FIAPaymentQueueHandler.h" - -@interface InAppPurchasePlugin () - -// Holding strong references to FIAPRequestHandlers. Remove the handlers from the set after -// the request is finished. -@property(strong, nonatomic, readonly) NSMutableSet *requestHandlers; - -// After querying the product, the available products will be saved in the map to be used -// for purchase. -@property(strong, nonatomic, readonly) NSMutableDictionary *productsCache; - -// Callback channel to dart used for when a function from the transaction observer is triggered. -@property(strong, nonatomic, readonly) FlutterMethodChannel *transactionObserverCallbackChannel; - -// Callback channel to dart used for when a function from the payment queue delegate is triggered. -@property(strong, nonatomic, readonly) FlutterMethodChannel *paymentQueueDelegateCallbackChannel; -@property(strong, nonatomic, readonly) NSObject *registrar; - -@property(strong, nonatomic, readonly) FIAPReceiptManager *receiptManager; -@property(strong, nonatomic, readonly) - FIAPPaymentQueueDelegate *paymentQueueDelegate API_AVAILABLE(ios(13)); - -@end - -@implementation InAppPurchasePlugin - -+ (void)registerWithRegistrar:(NSObject *)registrar { - FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase" - binaryMessenger:[registrar messenger]]; - InAppPurchasePlugin *instance = [[InAppPurchasePlugin alloc] initWithRegistrar:registrar]; - [registrar addMethodCallDelegate:instance channel:channel]; -} - -- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager { - self = [super init]; - _receiptManager = receiptManager; - _requestHandlers = [NSMutableSet new]; - _productsCache = [NSMutableDictionary new]; - return self; -} - -- (instancetype)initWithRegistrar:(NSObject *)registrar { - self = [self initWithReceiptManager:[FIAPReceiptManager new]]; - _registrar = registrar; - - __weak typeof(self) weakSelf = self; - _paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueue defaultQueue] - transactionsUpdated:^(NSArray *_Nonnull transactions) { - [weakSelf handleTransactionsUpdated:transactions]; - } - transactionRemoved:^(NSArray *_Nonnull transactions) { - [weakSelf handleTransactionsRemoved:transactions]; - } - restoreTransactionFailed:^(NSError *_Nonnull error) { - [weakSelf handleTransactionRestoreFailed:error]; - } - restoreCompletedTransactionsFinished:^{ - [weakSelf restoreCompletedTransactionsFinished]; - } - shouldAddStorePayment:^BOOL(SKPayment *payment, SKProduct *product) { - return [weakSelf shouldAddStorePayment:payment product:product]; - } - updatedDownloads:^void(NSArray *_Nonnull downloads) { - [weakSelf updatedDownloads:downloads]; - } - transactionCache:[[FIATransactionCache alloc] init]]; - - _transactionObserverCallbackChannel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase" - binaryMessenger:[registrar messenger]]; - return self; -} - -- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - if ([@"-[SKPaymentQueue canMakePayments:]" isEqualToString:call.method]) { - [self canMakePayments:result]; - } else if ([@"-[SKPaymentQueue transactions]" isEqualToString:call.method]) { - [self getPendingTransactions:result]; - } else if ([@"-[InAppPurchasePlugin startProductRequest:result:]" isEqualToString:call.method]) { - [self handleProductRequestMethodCall:call result:result]; - } else if ([@"-[InAppPurchasePlugin addPayment:result:]" isEqualToString:call.method]) { - [self addPayment:call result:result]; - } else if ([@"-[InAppPurchasePlugin finishTransaction:result:]" isEqualToString:call.method]) { - [self finishTransaction:call result:result]; - } else if ([@"-[InAppPurchasePlugin restoreTransactions:result:]" isEqualToString:call.method]) { - [self restoreTransactions:call result:result]; - } else if ([@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" - isEqualToString:call.method]) { - [self presentCodeRedemptionSheet:call result:result]; - } else if ([@"-[InAppPurchasePlugin retrieveReceiptData:result:]" isEqualToString:call.method]) { - [self retrieveReceiptData:call result:result]; - } else if ([@"-[InAppPurchasePlugin refreshReceipt:result:]" isEqualToString:call.method]) { - [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]; - } else if ([@"-[SKPaymentQueue registerDelegate]" isEqualToString:call.method]) { - [self registerPaymentQueueDelegate:result]; - } else if ([@"-[SKPaymentQueue removeDelegate]" isEqualToString:call.method]) { - [self removePaymentQueueDelegate:result]; - } else if ([@"-[SKPaymentQueue showPriceConsentIfNeeded]" isEqualToString:call.method]) { - [self showPriceConsentIfNeeded:result]; - } else { - result(FlutterMethodNotImplemented); - } -} - -- (void)canMakePayments:(FlutterResult)result { - result(@([SKPaymentQueue canMakePayments])); -} - -- (void)getPendingTransactions:(FlutterResult)result { - NSArray *transactions = - [self.paymentQueueHandler getUnfinishedTransactions]; - NSMutableArray *transactionMaps = [[NSMutableArray alloc] init]; - for (SKPaymentTransaction *transaction in transactions) { - [transactionMaps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]]; - } - result(transactionMaps); -} - -- (void)handleProductRequestMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - if (![call.arguments isKindOfClass:[NSArray class]]) { - result([FlutterError errorWithCode:@"storekit_invalid_argument" - message:@"Argument type of startRequest is not array" - details:call.arguments]); - return; - } - NSArray *productIdentifiers = (NSArray *)call.arguments; - SKProductsRequest *request = - [self getProductRequestWithIdentifiers:[NSSet setWithArray:productIdentifiers]]; - 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_getproductrequest_platform_error" - message:error.localizedDescription - details:error.description]); - return; - } - if (!response) { - result([FlutterError errorWithCode:@"storekit_platform_no_response" - message:@"Failed to get SKProductResponse in startRequest " - @"call. Error occured on iOS platform" - details:call.arguments]); - return; - } - for (SKProduct *product in response.products) { - [self.productsCache setObject:product forKey:product.productIdentifier]; - } - result([FIAObjectTranslator getMapFromSKProductsResponse:response]); - [weakSelf.requestHandlers removeObject:handler]; - }]; -} - -- (void)addPayment:(FlutterMethodCall *)call result:(FlutterResult)result { - if (![call.arguments isKindOfClass:[NSDictionary class]]) { - result([FlutterError errorWithCode:@"storekit_invalid_argument" - message:@"Argument type of addPayment is not a Dictionary" - details:call.arguments]); - return; - } - NSDictionary *paymentMap = (NSDictionary *)call.arguments; - NSString *productID = [paymentMap objectForKey:@"productIdentifier"]; - // When a product is already fetched, we create a payment object with - // the product to process the payment. - SKProduct *product = [self getProduct:productID]; - if (!product) { - result([FlutterError - errorWithCode:@"storekit_invalid_payment_object" - message: - @"You have requested a payment for an invalid product. Either the " - @"`productIdentifier` of the payment is not valid or the product has not been " - @"fetched before adding the payment to the payment queue." - details:call.arguments]); - return; - } - SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product]; - payment.applicationUsername = [paymentMap objectForKey:@"applicationUsername"]; - NSNumber *quantity = [paymentMap objectForKey:@"quantity"]; - payment.quantity = (quantity != nil) ? quantity.integerValue : 1; - NSNumber *simulatesAskToBuyInSandbox = [paymentMap objectForKey:@"simulatesAskToBuyInSandbox"]; - payment.simulatesAskToBuyInSandbox = (id)simulatesAskToBuyInSandbox == (id)[NSNull null] - ? NO - : [simulatesAskToBuyInSandbox boolValue]; - - if (@available(iOS 12.2, *)) { - NSDictionary *paymentDiscountMap = [self getNonNullValueFromDictionary:paymentMap - forKey:@"paymentDiscount"]; - NSString *error = nil; - SKPaymentDiscount *paymentDiscount = - [FIAObjectTranslator getSKPaymentDiscountFromMap:paymentDiscountMap withError:&error]; - - if (error) { - result([FlutterError - errorWithCode:@"storekit_invalid_payment_discount_object" - message:[NSString stringWithFormat:@"You have requested a payment and specified a " - @"payment discount with invalid properties. %@", - error] - details:call.arguments]); - return; - } - - payment.paymentDiscount = paymentDiscount; - } - - if (![self.paymentQueueHandler addPayment:payment]) { - result([FlutterError - errorWithCode:@"storekit_duplicate_product_object" - message:@"There is a pending transaction for the same product identifier. Please " - @"either wait for it to be finished or finish it manually using " - @"`completePurchase` to avoid edge cases." - - details:call.arguments]); - return; - } - result(nil); -} - -- (void)finishTransaction:(FlutterMethodCall *)call result:(FlutterResult)result { - if (![call.arguments isKindOfClass:[NSDictionary class]]) { - result([FlutterError errorWithCode:@"storekit_invalid_argument" - message:@"Argument type of finishTransaction is not a Dictionary" - details:call.arguments]); - return; - } - NSDictionary *paymentMap = (NSDictionary *)call.arguments; - NSString *transactionIdentifier = [paymentMap objectForKey:@"transactionIdentifier"]; - NSString *productIdentifier = [paymentMap objectForKey:@"productIdentifier"]; - - NSArray *pendingTransactions = - [self.paymentQueueHandler getUnfinishedTransactions]; - - for (SKPaymentTransaction *transaction in pendingTransactions) { - // If the user cancels the purchase dialog we won't have a transactionIdentifier. - // So if it is null AND a transaction in the pendingTransactions list has - // also a null transactionIdentifier we check for equal product identifiers. - if ([transaction.transactionIdentifier isEqualToString:transactionIdentifier] || - ([transactionIdentifier isEqual:[NSNull null]] && - transaction.transactionIdentifier == nil && - [transaction.payment.productIdentifier isEqualToString:productIdentifier])) { - @try { - [self.paymentQueueHandler finishTransaction:transaction]; - } @catch (NSException *e) { - result([FlutterError errorWithCode:@"storekit_finish_transaction_exception" - message:e.name - details:e.description]); - return; - } - } - } - - result(nil); -} - -- (void)restoreTransactions:(FlutterMethodCall *)call result:(FlutterResult)result { - if (call.arguments && ![call.arguments isKindOfClass:[NSString class]]) { - result([FlutterError - errorWithCode:@"storekit_invalid_argument" - message:@"Argument is not nil and the type of finishTransaction is not a string." - details:call.arguments]); - return; - } - [self.paymentQueueHandler restoreTransactions:call.arguments]; - result(nil); -} - -- (void)presentCodeRedemptionSheet:(FlutterMethodCall *)call result:(FlutterResult)result { - [self.paymentQueueHandler presentCodeRedemptionSheet]; - result(nil); -} - -- (void)retrieveReceiptData:(FlutterMethodCall *)call result:(FlutterResult)result { - FlutterError *error = nil; - NSString *receiptData = [self.receiptManager retrieveReceiptWithError:&error]; - 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)registerPaymentQueueDelegate:(FlutterResult)result { - 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; - } - result(nil); -} - -- (void)removePaymentQueueDelegate:(FlutterResult)result { - if (@available(iOS 13.0, *)) { - _paymentQueueHandler.delegate = nil; - } - _paymentQueueDelegate = nil; - _paymentQueueDelegateCallbackChannel = nil; - result(nil); -} - -- (void)showPriceConsentIfNeeded:(FlutterResult)result { - if (@available(iOS 13.4, *)) { - [_paymentQueueHandler showPriceConsentIfNeeded]; - } - result(nil); -} - -- (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key { - id value = dictionary[key]; - return [value isKindOfClass:[NSNull class]] ? nil : value; -} - -#pragma mark - transaction observer: - -- (void)handleTransactionsUpdated:(NSArray *)transactions { - NSMutableArray *maps = [NSMutableArray new]; - for (SKPaymentTransaction *transaction in transactions) { - [maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]]; - } - [self.transactionObserverCallbackChannel invokeMethod:@"updatedTransactions" arguments:maps]; -} - -- (void)handleTransactionsRemoved:(NSArray *)transactions { - NSMutableArray *maps = [NSMutableArray new]; - for (SKPaymentTransaction *transaction in transactions) { - [maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]]; - } - [self.transactionObserverCallbackChannel invokeMethod:@"removedTransactions" arguments:maps]; -} - -- (void)handleTransactionRestoreFailed:(NSError *)error { - [self.transactionObserverCallbackChannel - invokeMethod:@"restoreCompletedTransactionsFailed" - arguments:[FIAObjectTranslator getMapFromNSError:error]]; -} - -- (void)restoreCompletedTransactionsFinished { - [self.transactionObserverCallbackChannel - invokeMethod:@"paymentQueueRestoreCompletedTransactionsFinished" - arguments:nil]; -} - -- (void)updatedDownloads:(NSArray *)downloads { - NSLog(@"Received an updatedDownloads callback, but downloads are not supported."); -} - -- (BOOL)shouldAddStorePayment:(SKPayment *)payment product:(SKProduct *)product { - // We always return NO here. And we send the message to dart to process the payment; and we will - // have a interception method that deciding if the payment should be processed (implemented by the - // programmer). - [self.productsCache setObject:product forKey:product.productIdentifier]; - [self.transactionObserverCallbackChannel - invokeMethod:@"shouldAddStorePayment" - arguments:@{ - @"payment" : [FIAObjectTranslator getMapFromSKPayment:payment], - @"product" : [FIAObjectTranslator getMapFromSKProduct:product] - }]; - return NO; -} - -#pragma mark - dependency injection (for unit testing) - -- (SKProductsRequest *)getProductRequestWithIdentifiers:(NSSet *)identifiers { - return [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers]; -} - -- (SKProduct *)getProduct:(NSString *)productID { - return [self.productsCache objectForKey:productID]; -} - -- (SKReceiptRefreshRequest *)getRefreshReceiptRequest:(NSDictionary *)properties { - return [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:properties]; -} - -@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.m new file mode 120000 index 000000000000..67f61aad1fb0 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/Classes/InAppPurchasePlugin.m @@ -0,0 +1 @@ +../../shared/Classes/InAppPurchasePlugin.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/in_app_purchase_storekit.podspec b/packages/in_app_purchase/in_app_purchase_storekit/ios/in_app_purchase_storekit.podspec deleted file mode 100644 index dd83234ac4ad..000000000000 --- a/packages/in_app_purchase/in_app_purchase_storekit/ios/in_app_purchase_storekit.podspec +++ /dev/null @@ -1,24 +0,0 @@ -# -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html -# -Pod::Spec.new do |s| - s.name = 'in_app_purchase_storekit' - s.version = '0.0.1' - s.summary = 'Flutter In App Purchase iOS' - s.description = <<-DESC -A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store. -Downloaded by pub (not CocoaPods). - DESC - s.homepage = 'https://github.com/flutter/plugins' - s.license = { :type => 'BSD', :file => '../LICENSE' } - s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } - s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_storekit' } - # TODO(mvanbeusekom): update URL when in_app_purchase_storekit package is published. - # Updating it before the package is published will cause a lint error and block the tree. - s.documentation_url = 'https://pub.dev/packages/in_app_purchase' - s.source_files = 'Classes/**/*' - s.public_header_files = 'Classes/**/*.h' - s.dependency 'Flutter' - s.platform = :ios, '9.0' - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } -end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/ios/in_app_purchase_storekit.podspec b/packages/in_app_purchase/in_app_purchase_storekit/ios/in_app_purchase_storekit.podspec new file mode 120000 index 000000000000..79982cb307de --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/ios/in_app_purchase_storekit.podspec @@ -0,0 +1 @@ +../shared/in_app_purchase_storekit.podspec \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_delegate_wrapper.dart b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_delegate_wrapper.dart index 1d98dd3f4250..5c65fb1df6de 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_delegate_wrapper.dart +++ b/packages/in_app_purchase/in_app_purchase_storekit/lib/src/store_kit_wrappers/sk_payment_queue_delegate_wrapper.dart @@ -10,8 +10,8 @@ import '../../store_kit_wrappers.dart'; /// The payment queue delegate can be implementated to provide information /// needed to complete transactions. /// -/// The [SKPaymentQueueDelegateWrapper] is only available on iOS 13 and higher. -/// Using the delegate on older iOS version will be ignored. +/// The [SKPaymentQueueDelegateWrapper] is available on macOS and iOS 13+. +/// Usage with versions below iOS 13 and macOS are ignored. abstract class SKPaymentQueueDelegateWrapper { /// Called by the system to check whether the transaction should continue if /// the device's App Store storefront has changed during a transaction. diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Assets/.gitkeep b/packages/in_app_purchase/in_app_purchase_storekit/macos/Assets/.gitkeep new file mode 120000 index 000000000000..bf2007784034 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Assets/.gitkeep @@ -0,0 +1 @@ +../../shared/Assets/.gitkeep \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAObjectTranslator.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAObjectTranslator.h new file mode 120000 index 000000000000..8c80f07ea9a6 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAObjectTranslator.h @@ -0,0 +1 @@ +../../shared/Classes/FIAObjectTranslator.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAObjectTranslator.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAObjectTranslator.m new file mode 120000 index 000000000000..643df24599b8 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAObjectTranslator.m @@ -0,0 +1 @@ +../../shared/Classes/FIAObjectTranslator.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPPaymentQueueDelegate.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPPaymentQueueDelegate.h new file mode 120000 index 000000000000..5e54d74d187a --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPPaymentQueueDelegate.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPPaymentQueueDelegate.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPPaymentQueueDelegate.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPPaymentQueueDelegate.m new file mode 120000 index 000000000000..f972e7d7c7e8 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPPaymentQueueDelegate.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPPaymentQueueDelegate.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPReceiptManager.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPReceiptManager.h new file mode 120000 index 000000000000..f5c64da51bf3 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPReceiptManager.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPReceiptManager.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPReceiptManager.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPReceiptManager.m new file mode 120000 index 000000000000..7cc0593abb34 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPReceiptManager.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPReceiptManager.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPRequestHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPRequestHandler.h new file mode 120000 index 000000000000..b008c38df4bb --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPRequestHandler.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPRequestHandler.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPRequestHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPRequestHandler.m new file mode 120000 index 000000000000..22a1ba3a7c48 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPRequestHandler.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPRequestHandler.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPaymentQueueHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPaymentQueueHandler.h new file mode 120000 index 000000000000..8a64356be52e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPaymentQueueHandler.h @@ -0,0 +1 @@ +../../shared/Classes/FIAPaymentQueueHandler.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPaymentQueueHandler.m new file mode 120000 index 000000000000..87359d2e1c55 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIAPaymentQueueHandler.m @@ -0,0 +1 @@ +../../shared/Classes/FIAPaymentQueueHandler.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIATransactionCache.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIATransactionCache.h new file mode 120000 index 000000000000..1f8f3f92da93 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIATransactionCache.h @@ -0,0 +1 @@ +../../shared/Classes/FIATransactionCache.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIATransactionCache.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIATransactionCache.m new file mode 120000 index 000000000000..b27e9811319e --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/FIATransactionCache.m @@ -0,0 +1 @@ +../../shared/Classes/FIATransactionCache.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/InAppPurchasePlugin.h b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/InAppPurchasePlugin.h new file mode 120000 index 000000000000..d92777687ecd --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/InAppPurchasePlugin.h @@ -0,0 +1 @@ +../../shared/Classes/InAppPurchasePlugin.h \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/InAppPurchasePlugin.m new file mode 120000 index 000000000000..67f61aad1fb0 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/Classes/InAppPurchasePlugin.m @@ -0,0 +1 @@ +../../shared/Classes/InAppPurchasePlugin.m \ No newline at end of file diff --git a/packages/in_app_purchase/in_app_purchase_storekit/macos/in_app_purchase_storekit.podspec b/packages/in_app_purchase/in_app_purchase_storekit/macos/in_app_purchase_storekit.podspec new file mode 120000 index 000000000000..79982cb307de --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/macos/in_app_purchase_storekit.podspec @@ -0,0 +1 @@ +../shared/in_app_purchase_storekit.podspec \ 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 0b6e21a26978..f45b3acaad47 100644 --- a/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml +++ b/packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml @@ -1,8 +1,8 @@ name: in_app_purchase_storekit -description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework. +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/plugins/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.3 +version: 0.3.4 environment: sdk: ">=2.14.0 <3.0.0" @@ -14,6 +14,8 @@ flutter: platforms: ios: pluginClass: InAppPurchasePlugin + macos: + pluginClass: InAppPurchasePlugin dependencies: collection: ^1.15.0 diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Assets/.gitkeep b/packages/in_app_purchase/in_app_purchase_storekit/shared/Assets/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAObjectTranslator.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAObjectTranslator.h new file mode 100644 index 000000000000..eb97ceb44754 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAObjectTranslator.h @@ -0,0 +1,62 @@ +// 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. + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface FIAObjectTranslator : NSObject + +// Converts an instance of SKProduct into a dictionary. ++ (NSDictionary *)getMapFromSKProduct:(SKProduct *)product; + +// Converts an instance of SKProductSubscriptionPeriod into a dictionary. ++ (NSDictionary *)getMapFromSKProductSubscriptionPeriod:(SKProductSubscriptionPeriod *)period + API_AVAILABLE(ios(11.2)); + +// Converts an instance of SKProductDiscount into a dictionary. ++ (NSDictionary *)getMapFromSKProductDiscount:(SKProductDiscount *)discount + API_AVAILABLE(ios(11.2)); + +// Converts an array of SKProductDiscount instances into an array of dictionaries. ++ (nonnull NSArray *)getMapArrayFromSKProductDiscounts: + (nonnull NSArray *)productDiscounts API_AVAILABLE(ios(12.2)); + +// Converts an instance of SKProductsResponse into a dictionary. ++ (NSDictionary *)getMapFromSKProductsResponse:(SKProductsResponse *)productResponse; + +// Converts an instance of SKPayment into a dictionary. ++ (NSDictionary *)getMapFromSKPayment:(SKPayment *)payment; + +// Converts an instance of NSLocale into a dictionary. ++ (NSDictionary *)getMapFromNSLocale:(NSLocale *)locale; + +// Creates an instance of the SKMutablePayment class based on the supplied dictionary. ++ (SKMutablePayment *)getSKMutablePaymentFromMap:(NSDictionary *)map; + +// Converts an instance of SKPaymentTransaction into a dictionary. ++ (NSDictionary *)getMapFromSKPaymentTransaction:(SKPaymentTransaction *)transaction; + +// Converts an instance of NSError into a dictionary. ++ (NSDictionary *)getMapFromNSError:(NSError *)error; + +// Converts an instance of SKStorefront into a dictionary. ++ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront + API_AVAILABLE(ios(13), macos(10.15), watchos(6.2)); + +// Converts the supplied instances of SKStorefront and SKPaymentTransaction into a dictionary. ++ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront + andSKPaymentTransaction:(SKPaymentTransaction *)transaction + API_AVAILABLE(ios(13), macos(10.15), watchos(6.2)); + +// Creates an instance of the SKPaymentDiscount class based on the supplied dictionary. ++ (nullable SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map + withError:(NSString *_Nullable *_Nullable)error + API_AVAILABLE(ios(12.2)); + +@end +; + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAObjectTranslator.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAObjectTranslator.m new file mode 100644 index 000000000000..c656b58808b3 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAObjectTranslator.m @@ -0,0 +1,297 @@ +// 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. + +#import "FIAObjectTranslator.h" + +#pragma mark - SKProduct Coders + +@implementation FIAObjectTranslator + ++ (NSDictionary *)getMapFromSKProduct:(SKProduct *)product { + if (!product) { + return nil; + } + NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"localizedDescription" : product.localizedDescription ?: [NSNull null], + @"localizedTitle" : product.localizedTitle ?: [NSNull null], + @"productIdentifier" : product.productIdentifier ?: [NSNull null], + @"price" : product.price.description ?: [NSNull null] + + }]; + // TODO(cyanglaz): NSLocale is a complex object, want to see the actual need of getting this + // expanded to a map. Matching android to only get the currencySymbol for now. + // https://github.com/flutter/flutter/issues/26610 + [map setObject:[FIAObjectTranslator getMapFromNSLocale:product.priceLocale] ?: [NSNull null] + forKey:@"priceLocale"]; + if (@available(iOS 11.2, *)) { + [map setObject:[FIAObjectTranslator + getMapFromSKProductSubscriptionPeriod:product.subscriptionPeriod] + ?: [NSNull null] + forKey:@"subscriptionPeriod"]; + } + if (@available(iOS 11.2, *)) { + [map setObject:[FIAObjectTranslator getMapFromSKProductDiscount:product.introductoryPrice] + ?: [NSNull null] + forKey:@"introductoryPrice"]; + } + if (@available(iOS 12.2, *)) { + [map setObject:[FIAObjectTranslator getMapArrayFromSKProductDiscounts:product.discounts] + forKey:@"discounts"]; + } + if (@available(iOS 12.0, *)) { + [map setObject:product.subscriptionGroupIdentifier ?: [NSNull null] + forKey:@"subscriptionGroupIdentifier"]; + } + return map; +} + ++ (NSDictionary *)getMapFromSKProductSubscriptionPeriod:(SKProductSubscriptionPeriod *)period { + if (!period) { + return nil; + } + return @{@"numberOfUnits" : @(period.numberOfUnits), @"unit" : @(period.unit)}; +} + ++ (nonnull NSArray *)getMapArrayFromSKProductDiscounts: + (nonnull NSArray *)productDiscounts { + NSMutableArray *discountsMapArray = [[NSMutableArray alloc] init]; + + for (SKProductDiscount *productDiscount in productDiscounts) { + [discountsMapArray addObject:[FIAObjectTranslator getMapFromSKProductDiscount:productDiscount]]; + } + + return discountsMapArray; +} + ++ (NSDictionary *)getMapFromSKProductDiscount:(SKProductDiscount *)discount { + if (!discount) { + return nil; + } + NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"price" : discount.price.description ?: [NSNull null], + @"numberOfPeriods" : @(discount.numberOfPeriods), + @"subscriptionPeriod" : + [FIAObjectTranslator getMapFromSKProductSubscriptionPeriod:discount.subscriptionPeriod] + ?: [NSNull null], + @"paymentMode" : @(discount.paymentMode), + }]; + if (@available(iOS 12.2, *)) { + [map setObject:discount.identifier ?: [NSNull null] forKey:@"identifier"]; + [map setObject:@(discount.type) forKey:@"type"]; + } + + // TODO(cyanglaz): NSLocale is a complex object, want to see the actual need of getting this + // expanded to a map. Matching android to only get the currencySymbol for now. + // https://github.com/flutter/flutter/issues/26610 + [map setObject:[FIAObjectTranslator getMapFromNSLocale:discount.priceLocale] ?: [NSNull null] + forKey:@"priceLocale"]; + return map; +} + ++ (NSDictionary *)getMapFromSKProductsResponse:(SKProductsResponse *)productResponse { + if (!productResponse) { + return nil; + } + NSMutableArray *productsMapArray = [NSMutableArray new]; + for (SKProduct *product in productResponse.products) { + [productsMapArray addObject:[FIAObjectTranslator getMapFromSKProduct:product]]; + } + return @{ + @"products" : productsMapArray, + @"invalidProductIdentifiers" : productResponse.invalidProductIdentifiers ?: @[] + }; +} + ++ (NSDictionary *)getMapFromSKPayment:(SKPayment *)payment { + if (!payment) { + return nil; + } + NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"productIdentifier" : payment.productIdentifier ?: [NSNull null], + @"requestData" : payment.requestData ? [[NSString alloc] initWithData:payment.requestData + encoding:NSUTF8StringEncoding] + : [NSNull null], + @"quantity" : @(payment.quantity), + @"applicationUsername" : payment.applicationUsername ?: [NSNull null] + }]; + [map setObject:@(payment.simulatesAskToBuyInSandbox) forKey:@"simulatesAskToBuyInSandbox"]; + return map; +} + ++ (NSDictionary *)getMapFromNSLocale:(NSLocale *)locale { + if (!locale) { + return nil; + } + NSMutableDictionary *map = [[NSMutableDictionary alloc] init]; + [map setObject:[locale objectForKey:NSLocaleCurrencySymbol] ?: [NSNull null] + forKey:@"currencySymbol"]; + [map setObject:[locale objectForKey:NSLocaleCurrencyCode] ?: [NSNull null] + forKey:@"currencyCode"]; + [map setObject:[locale objectForKey:NSLocaleCountryCode] ?: [NSNull null] forKey:@"countryCode"]; + return map; +} + ++ (SKMutablePayment *)getSKMutablePaymentFromMap:(NSDictionary *)map { + if (!map) { + return nil; + } + SKMutablePayment *payment = [[SKMutablePayment alloc] init]; + payment.productIdentifier = map[@"productIdentifier"]; + NSString *utf8String = map[@"requestData"]; + payment.requestData = [utf8String dataUsingEncoding:NSUTF8StringEncoding]; + payment.quantity = [map[@"quantity"] integerValue]; + payment.applicationUsername = map[@"applicationUsername"]; + payment.simulatesAskToBuyInSandbox = [map[@"simulatesAskToBuyInSandbox"] boolValue]; + return payment; +} + ++ (NSDictionary *)getMapFromSKPaymentTransaction:(SKPaymentTransaction *)transaction { + if (!transaction) { + return nil; + } + NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"error" : [FIAObjectTranslator getMapFromNSError:transaction.error] ?: [NSNull null], + @"payment" : transaction.payment ? [FIAObjectTranslator getMapFromSKPayment:transaction.payment] + : [NSNull null], + @"originalTransaction" : transaction.originalTransaction + ? [FIAObjectTranslator getMapFromSKPaymentTransaction:transaction.originalTransaction] + : [NSNull null], + @"transactionTimeStamp" : transaction.transactionDate + ? @(transaction.transactionDate.timeIntervalSince1970) + : [NSNull null], + @"transactionIdentifier" : transaction.transactionIdentifier ?: [NSNull null], + @"transactionState" : @(transaction.transactionState) + }]; + + return map; +} + ++ (NSDictionary *)getMapFromNSError:(NSError *)error { + if (!error) { + return nil; + } + + NSMutableDictionary *userInfo = [NSMutableDictionary new]; + for (NSErrorUserInfoKey key in error.userInfo) { + id value = error.userInfo[key]; + userInfo[key] = [FIAObjectTranslator encodeNSErrorUserInfo:value]; + } + return @{@"code" : @(error.code), @"domain" : error.domain ?: @"", @"userInfo" : userInfo}; +} + ++ (id)encodeNSErrorUserInfo:(id)value { + if ([value isKindOfClass:[NSError class]]) { + return [FIAObjectTranslator getMapFromNSError:value]; + } else if ([value isKindOfClass:[NSURL class]]) { + return [value absoluteString]; + } else if ([value isKindOfClass:[NSNumber class]]) { + return value; + } else if ([value isKindOfClass:[NSString class]]) { + return value; + } else if ([value isKindOfClass:[NSArray class]]) { + NSMutableArray *errors = [[NSMutableArray alloc] init]; + for (id error in value) { + [errors addObject:[FIAObjectTranslator encodeNSErrorUserInfo:error]]; + } + return errors; + } else { + return [NSString + stringWithFormat: + @"Unable to encode native userInfo object of type %@ to map. Please submit an issue at " + @"https://github.com/flutter/flutter/issues/new with the title " + @"\"[in_app_purchase_storekit] " + @"Unable to encode userInfo of type %@\" and add reproduction steps and the error " + @"details in " + @"the description field.", + [value class], [value class]]; + } +} + ++ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront { + if (!storefront) { + return nil; + } + + NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"countryCode" : storefront.countryCode, + @"identifier" : storefront.identifier + }]; + + return map; +} + ++ (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront + andSKPaymentTransaction:(SKPaymentTransaction *)transaction { + if (!storefront || !transaction) { + return nil; + } + + NSMutableDictionary *map = [[NSMutableDictionary alloc] initWithDictionary:@{ + @"storefront" : [FIAObjectTranslator getMapFromSKStorefront:storefront], + @"transaction" : [FIAObjectTranslator getMapFromSKPaymentTransaction:transaction] + }]; + + return map; +} + ++ (SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map + withError:(NSString **)error { + if (!map || map.count <= 0) { + return nil; + } + + NSString *identifier = map[@"identifier"]; + NSString *keyIdentifier = map[@"keyIdentifier"]; + NSString *nonce = map[@"nonce"]; + NSString *signature = map[@"signature"]; + NSNumber *timestamp = map[@"timestamp"]; + + if (!identifier || ![identifier isKindOfClass:NSString.class] || + [identifier isEqualToString:@""]) { + if (error) { + *error = @"When specifying a payment discount the 'identifier' field is mandatory."; + } + return nil; + } + + if (!keyIdentifier || ![keyIdentifier isKindOfClass:NSString.class] || + [keyIdentifier isEqualToString:@""]) { + if (error) { + *error = @"When specifying a payment discount the 'keyIdentifier' field is mandatory."; + } + return nil; + } + + if (!nonce || ![nonce isKindOfClass:NSString.class] || [nonce isEqualToString:@""]) { + if (error) { + *error = @"When specifying a payment discount the 'nonce' field is mandatory."; + } + return nil; + } + + if (!signature || ![signature isKindOfClass:NSString.class] || [signature isEqualToString:@""]) { + if (error) { + *error = @"When specifying a payment discount the 'signature' field is mandatory."; + } + return nil; + } + + if (!timestamp || ![timestamp isKindOfClass:NSNumber.class] || [timestamp longLongValue] <= 0) { + if (error) { + *error = @"When specifying a payment discount the 'timestamp' field is mandatory."; + } + return nil; + } + + SKPaymentDiscount *discount = + [[SKPaymentDiscount alloc] initWithIdentifier:identifier + keyIdentifier:keyIdentifier + nonce:[[NSUUID alloc] initWithUUIDString:nonce] + signature:signature + timestamp:timestamp]; + + return discount; +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPPaymentQueueDelegate.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPPaymentQueueDelegate.h new file mode 100644 index 000000000000..4347846f54ca --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPPaymentQueueDelegate.h @@ -0,0 +1,21 @@ +// 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. + +#if TARGET_OS_OSX +#import +#else +#import +#endif +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +API_AVAILABLE(ios(13)) +API_UNAVAILABLE(tvos, macos, watchos) +@interface FIAPPaymentQueueDelegate : NSObject +- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel; +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPPaymentQueueDelegate.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPPaymentQueueDelegate.m new file mode 100644 index 000000000000..cb18d9b86d66 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPPaymentQueueDelegate.m @@ -0,0 +1,80 @@ +// 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. + +#import "FIAPPaymentQueueDelegate.h" +#import "FIAObjectTranslator.h" + +@interface FIAPPaymentQueueDelegate () + +@property(strong, nonatomic, readonly) FlutterMethodChannel *callbackChannel; + +@end + +@implementation FIAPPaymentQueueDelegate + +- (id)initWithMethodChannel:(FlutterMethodChannel *)methodChannel { + self = [super init]; + if (self) { + _callbackChannel = methodChannel; + } + + return self; +} + +- (BOOL)paymentQueue:(SKPaymentQueue *)paymentQueue + shouldContinueTransaction:(SKPaymentTransaction *)transaction + inStorefront:(SKStorefront *)newStorefront { + // Default return value for this method is true (see + // https://developer.apple.com/documentation/storekit/skpaymentqueuedelegate/3521328-paymentqueueshouldshowpriceconse?language=objc) + __block BOOL shouldContinue = YES; + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + [self.callbackChannel invokeMethod:@"shouldContinueTransaction" + arguments:[FIAObjectTranslator getMapFromSKStorefront:newStorefront + andSKPaymentTransaction:transaction] + result:^(id _Nullable result) { + // When result is a valid instance of NSNumber use it to determine + // if the transaction should continue. Otherwise use the default + // value. + if (result && [result isKindOfClass:[NSNumber class]]) { + shouldContinue = [(NSNumber *)result boolValue]; + } + + dispatch_semaphore_signal(semaphore); + }]; + + // The client should respond within 1 second otherwise continue + // with default value. + dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC)); + + return shouldContinue; +} + +#if TARGET_OS_IOS +- (BOOL)paymentQueueShouldShowPriceConsent:(SKPaymentQueue *)paymentQueue { + // Default return value for this method is true (see + // https://developer.apple.com/documentation/storekit/skpaymentqueuedelegate/3521328-paymentqueueshouldshowpriceconse?language=objc) + __block BOOL shouldShowPriceConsent = YES; + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + [self.callbackChannel invokeMethod:@"shouldShowPriceConsent" + arguments:nil + result:^(id _Nullable result) { + // When result is a valid instance of NSNumber use it to determine + // if the transaction should continue. Otherwise use the default + // value. + if (result && [result isKindOfClass:[NSNumber class]]) { + shouldShowPriceConsent = [(NSNumber *)result boolValue]; + } + + dispatch_semaphore_signal(semaphore); + }]; + + // The client should respond within 1 second otherwise continue + // with default value. + dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC)); + + return shouldShowPriceConsent; +} +#endif + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPReceiptManager.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPReceiptManager.h new file mode 100644 index 000000000000..94020ff2348b --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPReceiptManager.h @@ -0,0 +1,17 @@ +// 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. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class FlutterError; + +@interface FIAPReceiptManager : NSObject + +- (nullable NSString *)retrieveReceiptWithError:(FlutterError *_Nullable *_Nullable)error; + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPReceiptManager.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPReceiptManager.m new file mode 100644 index 000000000000..fc125da133d4 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPReceiptManager.m @@ -0,0 +1,42 @@ +// 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. + +#import "FIAPReceiptManager.h" +#if TARGET_OS_OSX +#import +#else +#import +#endif +#import "FIAObjectTranslator.h" + +@interface FIAPReceiptManager () +// Gets the receipt file data from the location of the url. Can be nil if +// there is an error. This interface is defined so it can be stubbed for testing. +- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error; + +@end + +@implementation FIAPReceiptManager + +- (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError { + NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; + NSError *receiptError; + NSData *receipt = [self getReceiptData:receiptURL error:&receiptError]; + if (!receipt || receiptError) { + if (flutterError) { + NSDictionary *errorMap = [FIAObjectTranslator getMapFromNSError:receiptError]; + *flutterError = [FlutterError errorWithCode:errorMap[@"code"] + message:errorMap[@"domain"] + details:errorMap[@"userInfo"]]; + } + return nil; + } + return [receipt base64EncodedStringWithOptions:kNilOptions]; +} + +- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error { + return [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:error]; +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPRequestHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPRequestHandler.h new file mode 100644 index 000000000000..cbf21d6e161f --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPRequestHandler.h @@ -0,0 +1,20 @@ +// 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. + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef void (^ProductRequestCompletion)(SKProductsResponse *_Nullable response, + NSError *_Nullable errror); + +@interface FIAPRequestHandler : NSObject + +- (instancetype)initWithRequest:(SKRequest *)request; +- (void)startProductRequestWithCompletionHandler:(ProductRequestCompletion)completion; + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPRequestHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPRequestHandler.m new file mode 100644 index 000000000000..8767265d8544 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPRequestHandler.m @@ -0,0 +1,55 @@ +// 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. + +#import "FIAPRequestHandler.h" +#import + +#pragma mark - Main Handler + +@interface FIAPRequestHandler () + +@property(copy, nonatomic) ProductRequestCompletion completion; +@property(strong, nonatomic) SKRequest *request; + +@end + +@implementation FIAPRequestHandler + +- (instancetype)initWithRequest:(SKRequest *)request { + self = [super init]; + if (self) { + self.request = request; + request.delegate = self; + } + return self; +} + +- (void)startProductRequestWithCompletionHandler:(ProductRequestCompletion)completion { + self.completion = completion; + [self.request start]; +} + +- (void)productsRequest:(SKProductsRequest *)request + didReceiveResponse:(SKProductsResponse *)response { + if (self.completion) { + self.completion(response, nil); + // set the completion to nil here so self.completion won't be triggered again in + // requestDidFinish for SKProductRequest. + self.completion = nil; + } +} + +- (void)requestDidFinish:(SKRequest *)request { + if (self.completion) { + self.completion(nil, nil); + } +} + +- (void)request:(SKRequest *)request didFailWithError:(NSError *)error { + if (self.completion) { + self.completion(nil, error); + } +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPaymentQueueHandler.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPaymentQueueHandler.h new file mode 100644 index 000000000000..fdc042655fd7 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPaymentQueueHandler.h @@ -0,0 +1,132 @@ +// 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. + +#import +#import +#import "FIATransactionCache.h" + +@class SKPaymentTransaction; + +NS_ASSUME_NONNULL_BEGIN + +typedef void (^TransactionsUpdated)(NSArray *transactions); +typedef void (^TransactionsRemoved)(NSArray *transactions); +typedef void (^RestoreTransactionFailed)(NSError *error); +typedef void (^RestoreCompletedTransactionsFinished)(void); +typedef BOOL (^ShouldAddStorePayment)(SKPayment *payment, SKProduct *product); +typedef void (^UpdatedDownloads)(NSArray *downloads); + +@interface FIAPaymentQueueHandler : NSObject + +@property(NS_NONATOMIC_IOSONLY, weak, nullable) id delegate API_AVAILABLE( + ios(13.0), macos(10.15), watchos(6.2)); + +/// Creates a new FIAPaymentQueueHandler initialized with an empty +/// FIATransactionCache. +/// +/// @param queue The SKPaymentQueue instance connected to the App Store and +/// responsible for processing transactions. +/// @param transactionsUpdated Callback method that is called each time the App +/// Store indicates transactions are updated. +/// @param transactionsRemoved Callback method that is called each time the App +/// Store indicates transactions are removed. +/// @param restoreTransactionFailed Callback method that is called each time +/// the App Store indicates transactions failed +/// to restore. +/// @param restoreCompletedTransactionsFinished Callback method that is called +/// each time the App Store +/// indicates restoring of +/// transactions has finished. +/// @param shouldAddStorePayment Callback method that is called each time an +/// in-app purchase has been initiated from the +/// App Store. +/// @param updatedDownloads Callback method that is called each time the App +/// Store indicates downloads are updated. +- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue + transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated + transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved + restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed + restoreCompletedTransactionsFinished: + (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished + shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment + updatedDownloads:(nullable UpdatedDownloads)updatedDownloads + DEPRECATED_MSG_ATTRIBUTE( + "Use the " + "'initWithQueue:transactionsUpdated:transactionsRemoved:restoreTransactionsFinished:" + "shouldAddStorePayment:updatedDownloads:transactionCache:' message instead."); + +/// Creates a new FIAPaymentQueueHandler. +/// +/// The "transactionsUpdated", "transactionsRemoved" and "updatedDownloads" +/// callbacks are only called while actively observing transactions. To start +/// observing transactions send the "startObservingPaymentQueue" message. +/// Sending the "stopObservingPaymentQueue" message will stop actively +/// observing transactions. When transactions are not observed they are cached +/// to the "transactionCache" and will be delivered via the +/// "transactionsUpdated", "transactionsRemoved" and "updatedDownloads" +/// callbacks as soon as the "startObservingPaymentQueue" message arrives. +/// +/// Note: cached transactions that are not processed when the application is +/// killed will be delivered again by the App Store as soon as the application +/// starts again. +/// +/// @param queue The SKPaymentQueue instance connected to the App Store and +/// responsible for processing transactions. +/// @param transactionsUpdated Callback method that is called each time the App +/// Store indicates transactions are updated. +/// @param transactionsRemoved Callback method that is called each time the App +/// Store indicates transactions are removed. +/// @param restoreTransactionFailed Callback method that is called each time +/// the App Store indicates transactions failed +/// to restore. +/// @param restoreCompletedTransactionsFinished Callback method that is called +/// each time the App Store +/// indicates restoring of +/// transactions has finished. +/// @param shouldAddStorePayment Callback method that is called each time an +/// in-app purchase has been initiated from the +/// App Store. +/// @param updatedDownloads Callback method that is called each time the App +/// Store indicates downloads are updated. +/// @param transactionCache An empty [FIATransactionCache] instance that is +/// responsible for keeping track of transactions that +/// arrive when not actively observing transactions. +- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue + transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated + transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved + restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed + restoreCompletedTransactionsFinished: + (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished + shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment + updatedDownloads:(nullable UpdatedDownloads)updatedDownloads + transactionCache:(nonnull FIATransactionCache *)transactionCache; +// Can throw exceptions if the transaction type is purchasing, should always used in a @try block. +- (void)finishTransaction:(nonnull SKPaymentTransaction *)transaction; +- (void)restoreTransactions:(nullable NSString *)applicationName; +- (void)presentCodeRedemptionSheet API_UNAVAILABLE(tvos, macos, watchos); +- (NSArray *)getUnfinishedTransactions; + +// This method needs to be called before any other methods. +- (void)startObservingPaymentQueue; +// Call this method when the Flutter app is no longer listening +- (void)stopObservingPaymentQueue; + +// Appends a payment to the SKPaymentQueue. +// +// @param payment Payment object to be added to the payment queue. +// @return whether "addPayment" was successful. +- (BOOL)addPayment:(SKPayment *)payment; + +// Displays the price consent sheet. +// +// The price consent sheet is only displayed when the following +// is true: +// - You have increased the price of the subscription in App Store Connect. +// - The subscriber has not yet responded to a price consent query. +// Otherwise the method has no effect. +- (void)showPriceConsentIfNeeded API_AVAILABLE(ios(13.4))API_UNAVAILABLE(tvos, macos, watchos); + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPaymentQueueHandler.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPaymentQueueHandler.m new file mode 100644 index 000000000000..d18a09cfa405 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIAPaymentQueueHandler.m @@ -0,0 +1,236 @@ +// 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. + +#import "FIAPaymentQueueHandler.h" +#import "FIAPPaymentQueueDelegate.h" +#import "FIATransactionCache.h" + +@interface FIAPaymentQueueHandler () + +/// The SKPaymentQueue instance connected to the App Store and responsible for processing +/// transactions. +@property(strong, nonatomic) SKPaymentQueue *queue; + +/// Callback method that is called each time the App Store indicates transactions are updated. +@property(nullable, copy, nonatomic) TransactionsUpdated transactionsUpdated; + +/// Callback method that is called each time the App Store indicates transactions are removed. +@property(nullable, copy, nonatomic) TransactionsRemoved transactionsRemoved; + +/// Callback method that is called each time the App Store indicates transactions failed to restore. +@property(nullable, copy, nonatomic) RestoreTransactionFailed restoreTransactionFailed; + +/// Callback method that is called each time the App Store indicates restoring of transactions has +/// finished. +@property(nullable, copy, nonatomic) + RestoreCompletedTransactionsFinished paymentQueueRestoreCompletedTransactionsFinished; + +/// Callback method that is called each time an in-app purchase has been initiated from the App +/// Store. +@property(nullable, copy, nonatomic) ShouldAddStorePayment shouldAddStorePayment; + +/// Callback method that is called each time the App Store indicates downloads are updated. +@property(nullable, copy, nonatomic) UpdatedDownloads updatedDownloads; + +/// The transaction cache responsible for caching transactions. +/// +/// Keeps track of transactions that arrive when the Flutter client is not +/// actively observing for transactions. +@property(strong, nonatomic, nonnull) FIATransactionCache *transactionCache; + +/// Indicates if the Flutter client is observing transactions. +/// +/// When the client is not observing, transactions are cached and send to the +/// client as soon as it starts observing. The Flutter client can start +/// observing by sending a startObservingPaymentQueue message and stop by +/// sending a stopObservingPaymentQueue message. +@property(atomic, assign, readwrite, getter=isObservingTransactions) BOOL observingTransactions; + +@end + +@implementation FIAPaymentQueueHandler + +- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue + transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated + transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved + restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed + restoreCompletedTransactionsFinished: + (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished + shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment + updatedDownloads:(nullable UpdatedDownloads)updatedDownloads { + return [[FIAPaymentQueueHandler alloc] initWithQueue:queue + transactionsUpdated:transactionsUpdated + transactionRemoved:transactionsRemoved + restoreTransactionFailed:restoreTransactionFailed + restoreCompletedTransactionsFinished:restoreCompletedTransactionsFinished + shouldAddStorePayment:shouldAddStorePayment + updatedDownloads:updatedDownloads + transactionCache:[[FIATransactionCache alloc] init]]; +} + +- (instancetype)initWithQueue:(nonnull SKPaymentQueue *)queue + transactionsUpdated:(nullable TransactionsUpdated)transactionsUpdated + transactionRemoved:(nullable TransactionsRemoved)transactionsRemoved + restoreTransactionFailed:(nullable RestoreTransactionFailed)restoreTransactionFailed + restoreCompletedTransactionsFinished: + (nullable RestoreCompletedTransactionsFinished)restoreCompletedTransactionsFinished + shouldAddStorePayment:(nullable ShouldAddStorePayment)shouldAddStorePayment + updatedDownloads:(nullable UpdatedDownloads)updatedDownloads + transactionCache:(nonnull FIATransactionCache *)transactionCache { + self = [super init]; + if (self) { + _queue = queue; + _transactionsUpdated = transactionsUpdated; + _transactionsRemoved = transactionsRemoved; + _restoreTransactionFailed = restoreTransactionFailed; + _paymentQueueRestoreCompletedTransactionsFinished = restoreCompletedTransactionsFinished; + _shouldAddStorePayment = shouldAddStorePayment; + _updatedDownloads = updatedDownloads; + _transactionCache = transactionCache; + + [_queue addTransactionObserver:self]; + if (@available(iOS 13.0, macOS 10.15, *)) { + queue.delegate = self.delegate; + } + } + return self; +} + +- (void)startObservingPaymentQueue { + self.observingTransactions = YES; + + [self processCachedTransactions]; +} + +- (void)stopObservingPaymentQueue { + // When the client stops observing transaction, the transaction observer is + // not removed from the SKPaymentQueue. The FIAPaymentQueueHandler will cache + // trasnactions in memory when the client is not observing, allowing the app + // to process these transactions if it starts observing again during the same + // lifetime of the app. + // + // If the app is killed, cached transactions will be removed from memory; + // however, the App Store will re-deliver the transactions as soon as the app + // is started again, since the cached transactions have not been acknowledged + // by the client (by sending the `finishTransaction` message). + self.observingTransactions = NO; +} + +- (void)processCachedTransactions { + NSArray *cachedObjects = + [self.transactionCache getObjectsForKey:TransactionCacheKeyUpdatedTransactions]; + if (cachedObjects.count != 0) { + self.transactionsUpdated(cachedObjects); + } + + cachedObjects = [self.transactionCache getObjectsForKey:TransactionCacheKeyUpdatedDownloads]; + if (cachedObjects.count != 0) { + self.updatedDownloads(cachedObjects); + } + + cachedObjects = [self.transactionCache getObjectsForKey:TransactionCacheKeyRemovedTransactions]; + if (cachedObjects.count != 0) { + self.transactionsRemoved(cachedObjects); + } + + [self.transactionCache clear]; +} + +- (BOOL)addPayment:(SKPayment *)payment { + for (SKPaymentTransaction *transaction in self.queue.transactions) { + if ([transaction.payment.productIdentifier isEqualToString:payment.productIdentifier]) { + return NO; + } + } + [self.queue addPayment:payment]; + return YES; +} + +- (void)finishTransaction:(SKPaymentTransaction *)transaction { + [self.queue finishTransaction:transaction]; +} + +- (void)restoreTransactions:(nullable NSString *)applicationName { + if (applicationName) { + [self.queue restoreCompletedTransactionsWithApplicationUsername:applicationName]; + } else { + [self.queue restoreCompletedTransactions]; + } +} + +#if TARGET_OS_IOS +- (void)presentCodeRedemptionSheet { + if (@available(iOS 14, *)) { + [self.queue presentCodeRedemptionSheet]; + } else { + NSLog(@"presentCodeRedemptionSheet is only available on iOS 14 or newer"); + } +} +#endif + +#if TARGET_OS_IOS +- (void)showPriceConsentIfNeeded { + [self.queue showPriceConsentIfNeeded]; +} +#endif + +#pragma mark - observing + +// Sent when the transaction array has changed (additions or state changes). Client should check +// state of transactions and finish as appropriate. +- (void)paymentQueue:(SKPaymentQueue *)queue + updatedTransactions:(NSArray *)transactions { + if (!self.observingTransactions) { + [_transactionCache addObjects:transactions forKey:TransactionCacheKeyUpdatedTransactions]; + return; + } + + // notify dart through callbacks. + self.transactionsUpdated(transactions); +} + +// Sent when transactions are removed from the queue (via finishTransaction:). +- (void)paymentQueue:(SKPaymentQueue *)queue + removedTransactions:(NSArray *)transactions { + if (!self.observingTransactions) { + [_transactionCache addObjects:transactions forKey:TransactionCacheKeyRemovedTransactions]; + return; + } + self.transactionsRemoved(transactions); +} + +// Sent when an error is encountered while adding transactions from the user's purchase history back +// to the queue. +- (void)paymentQueue:(SKPaymentQueue *)queue + restoreCompletedTransactionsFailedWithError:(NSError *)error { + self.restoreTransactionFailed(error); +} + +// Sent when all transactions from the user's purchase history have successfully been added back to +// the queue. +- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { + self.paymentQueueRestoreCompletedTransactionsFinished(); +} + +// Sent when the download state has changed. +- (void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads { + if (!self.observingTransactions) { + [_transactionCache addObjects:downloads forKey:TransactionCacheKeyUpdatedDownloads]; + return; + } + self.updatedDownloads(downloads); +} + +// Sent when a user initiates an IAP buy from the App Store +- (BOOL)paymentQueue:(SKPaymentQueue *)queue + shouldAddStorePayment:(SKPayment *)payment + forProduct:(SKProduct *)product { + return (self.shouldAddStorePayment(payment, product)); +} + +- (NSArray *)getUnfinishedTransactions { + return self.queue.transactions; +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIATransactionCache.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIATransactionCache.h new file mode 100644 index 000000000000..dea3c2d85d14 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIATransactionCache.h @@ -0,0 +1,31 @@ +// 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. + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, TransactionCacheKey) { + TransactionCacheKeyUpdatedDownloads, + TransactionCacheKeyUpdatedTransactions, + TransactionCacheKeyRemovedTransactions +}; + +@interface FIATransactionCache : NSObject + +/// Adds objects to the transaction cache. +/// +/// If the cache already contains an array of objects on the specified key, the supplied +/// array will be appended to the existing array. +- (void)addObjects:(NSArray *)objects forKey:(TransactionCacheKey)key; + +/// Gets the array of objects stored at the given key. +/// +/// If there are no objects associated with the given key nil is returned. +- (NSArray *)getObjectsForKey:(TransactionCacheKey)key; + +/// Removes all objects from the transaction cache. +- (void)clear; + +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIATransactionCache.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIATransactionCache.m new file mode 100644 index 000000000000..f80b9c40c7bc --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/FIATransactionCache.m @@ -0,0 +1,40 @@ +// 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. + +#import "FIATransactionCache.h" + +@interface FIATransactionCache () + +/// A NSMutableDictionary storing the objects that are cached. +@property(nonatomic, strong, nonnull) NSMutableDictionary *cache; + +@end + +@implementation FIATransactionCache + +- (instancetype)init { + self = [super init]; + if (self) { + self.cache = [[NSMutableDictionary alloc] init]; + } + + return self; +} + +- (void)addObjects:(NSArray *)objects forKey:(TransactionCacheKey)key { + NSArray *cachedObjects = self.cache[@(key)]; + + self.cache[@(key)] = + cachedObjects ? [cachedObjects arrayByAddingObjectsFromArray:objects] : objects; +} + +- (NSArray *)getObjectsForKey:(TransactionCacheKey)key { + return self.cache[@(key)]; +} + +- (void)clear { + [self.cache removeAllObjects]; +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/InAppPurchasePlugin.h b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/InAppPurchasePlugin.h new file mode 100644 index 000000000000..eeab0a706683 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/InAppPurchasePlugin.h @@ -0,0 +1,21 @@ +// 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. + +#if TARGET_OS_OSX +#import +#else +#import +#endif +@class FIAPaymentQueueHandler; +@class FIAPReceiptManager; + +@interface InAppPurchasePlugin : NSObject + +@property(strong, nonatomic) FIAPaymentQueueHandler *paymentQueueHandler; + +- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager + NS_DESIGNATED_INITIALIZER; +- (instancetype)init NS_UNAVAILABLE; + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/InAppPurchasePlugin.m b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/InAppPurchasePlugin.m new file mode 100644 index 000000000000..1ecb0fc1dc68 --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/Classes/InAppPurchasePlugin.m @@ -0,0 +1,451 @@ +// 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. + +#import "InAppPurchasePlugin.h" +#import +#import "FIAObjectTranslator.h" +#import "FIAPPaymentQueueDelegate.h" +#import "FIAPReceiptManager.h" +#import "FIAPRequestHandler.h" +#import "FIAPaymentQueueHandler.h" + +@interface InAppPurchasePlugin () + +// Holding strong references to FIAPRequestHandlers. Remove the handlers from the set after +// the request is finished. +@property(strong, nonatomic, readonly) NSMutableSet *requestHandlers; + +// After querying the product, the available products will be saved in the map to be used +// for purchase. +@property(strong, nonatomic, readonly) NSMutableDictionary *productsCache; + +// Callback channel to dart used for when a function from the transaction observer is triggered. +@property(strong, nonatomic, readonly) FlutterMethodChannel *transactionObserverCallbackChannel; + +// Callback channel to dart used for when a function from the payment queue delegate is triggered. +@property(strong, nonatomic, readonly) FlutterMethodChannel *paymentQueueDelegateCallbackChannel; +@property(strong, nonatomic, readonly) NSObject *registrar; + +@property(strong, nonatomic, readonly) FIAPReceiptManager *receiptManager; +@property(strong, nonatomic, readonly) + FIAPPaymentQueueDelegate *paymentQueueDelegate API_AVAILABLE(ios(13)) + API_UNAVAILABLE(tvos, macos, watchos); + +@end + +@implementation InAppPurchasePlugin + ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase" + binaryMessenger:[registrar messenger]]; + InAppPurchasePlugin *instance = [[InAppPurchasePlugin alloc] initWithRegistrar:registrar]; + [registrar addMethodCallDelegate:instance channel:channel]; +} + +- (instancetype)initWithReceiptManager:(FIAPReceiptManager *)receiptManager { + self = [super init]; + _receiptManager = receiptManager; + _requestHandlers = [NSMutableSet new]; + _productsCache = [NSMutableDictionary new]; + return self; +} + +- (instancetype)initWithRegistrar:(NSObject *)registrar { + self = [self initWithReceiptManager:[FIAPReceiptManager new]]; + _registrar = registrar; + + __weak typeof(self) weakSelf = self; + _paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:[SKPaymentQueue defaultQueue] + transactionsUpdated:^(NSArray *_Nonnull transactions) { + [weakSelf handleTransactionsUpdated:transactions]; + } + transactionRemoved:^(NSArray *_Nonnull transactions) { + [weakSelf handleTransactionsRemoved:transactions]; + } + restoreTransactionFailed:^(NSError *_Nonnull error) { + [weakSelf handleTransactionRestoreFailed:error]; + } + restoreCompletedTransactionsFinished:^{ + [weakSelf restoreCompletedTransactionsFinished]; + } + shouldAddStorePayment:^BOOL(SKPayment *payment, SKProduct *product) { + return [weakSelf shouldAddStorePayment:payment product:product]; + } + updatedDownloads:^void(NSArray *_Nonnull downloads) { + [weakSelf updatedDownloads:downloads]; + } + transactionCache:[[FIATransactionCache alloc] init]]; + + _transactionObserverCallbackChannel = + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase" + binaryMessenger:[registrar messenger]]; + return self; +} + +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + if ([@"-[SKPaymentQueue canMakePayments:]" isEqualToString:call.method]) { + [self canMakePayments:result]; + } else if ([@"-[SKPaymentQueue transactions]" isEqualToString:call.method]) { + [self getPendingTransactions:result]; + } else if ([@"-[InAppPurchasePlugin startProductRequest:result:]" isEqualToString:call.method]) { + [self handleProductRequestMethodCall:call result:result]; + } else if ([@"-[InAppPurchasePlugin addPayment:result:]" isEqualToString:call.method]) { + [self addPayment:call result:result]; + } else if ([@"-[InAppPurchasePlugin finishTransaction:result:]" isEqualToString:call.method]) { + [self finishTransaction:call result:result]; + } else if ([@"-[InAppPurchasePlugin restoreTransactions:result:]" isEqualToString:call.method]) { + [self restoreTransactions:call result:result]; +#if TARGET_OS_IOS + } else if ([@"-[InAppPurchasePlugin presentCodeRedemptionSheet:result:]" + isEqualToString:call.method]) { + [self presentCodeRedemptionSheet:call result:result]; +#endif + } else 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); + } +} + +- (void)canMakePayments:(FlutterResult)result { + result(@([SKPaymentQueue canMakePayments])); +} + +- (void)getPendingTransactions:(FlutterResult)result { + NSArray *transactions = + [self.paymentQueueHandler getUnfinishedTransactions]; + NSMutableArray *transactionMaps = [[NSMutableArray alloc] init]; + for (SKPaymentTransaction *transaction in transactions) { + [transactionMaps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]]; + } + result(transactionMaps); +} + +- (void)handleProductRequestMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + if (![call.arguments isKindOfClass:[NSArray class]]) { + result([FlutterError errorWithCode:@"storekit_invalid_argument" + message:@"Argument type of startRequest is not array" + details:call.arguments]); + return; + } + NSArray *productIdentifiers = (NSArray *)call.arguments; + SKProductsRequest *request = + [self getProductRequestWithIdentifiers:[NSSet setWithArray:productIdentifiers]]; + 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_getproductrequest_platform_error" + message:error.localizedDescription + details:error.description]); + return; + } + if (!response) { + result([FlutterError errorWithCode:@"storekit_platform_no_response" + message:@"Failed to get SKProductResponse in startRequest " + @"call. Error occured on iOS platform" + details:call.arguments]); + return; + } + for (SKProduct *product in response.products) { + [self.productsCache setObject:product forKey:product.productIdentifier]; + } + result([FIAObjectTranslator getMapFromSKProductsResponse:response]); + [weakSelf.requestHandlers removeObject:handler]; + }]; +} + +- (void)addPayment:(FlutterMethodCall *)call result:(FlutterResult)result { + if (![call.arguments isKindOfClass:[NSDictionary class]]) { + result([FlutterError errorWithCode:@"storekit_invalid_argument" + message:@"Argument type of addPayment is not a Dictionary" + details:call.arguments]); + return; + } + NSDictionary *paymentMap = (NSDictionary *)call.arguments; + NSString *productID = [paymentMap objectForKey:@"productIdentifier"]; + // When a product is already fetched, we create a payment object with + // the product to process the payment. + SKProduct *product = [self getProduct:productID]; + if (!product) { + result([FlutterError + errorWithCode:@"storekit_invalid_payment_object" + message: + @"You have requested a payment for an invalid product. Either the " + @"`productIdentifier` of the payment is not valid or the product has not been " + @"fetched before adding the payment to the payment queue." + details:call.arguments]); + return; + } + SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product]; + payment.applicationUsername = [paymentMap objectForKey:@"applicationUsername"]; + NSNumber *quantity = [paymentMap objectForKey:@"quantity"]; + payment.quantity = (quantity != nil) ? quantity.integerValue : 1; + NSNumber *simulatesAskToBuyInSandbox = [paymentMap objectForKey:@"simulatesAskToBuyInSandbox"]; + payment.simulatesAskToBuyInSandbox = (id)simulatesAskToBuyInSandbox == (id)[NSNull null] + ? NO + : [simulatesAskToBuyInSandbox boolValue]; + + if (@available(iOS 12.2, *)) { + NSDictionary *paymentDiscountMap = [self getNonNullValueFromDictionary:paymentMap + forKey:@"paymentDiscount"]; + NSString *error = nil; + SKPaymentDiscount *paymentDiscount = + [FIAObjectTranslator getSKPaymentDiscountFromMap:paymentDiscountMap withError:&error]; + + if (error) { + result([FlutterError + errorWithCode:@"storekit_invalid_payment_discount_object" + message:[NSString stringWithFormat:@"You have requested a payment and specified a " + @"payment discount with invalid properties. %@", + error] + details:call.arguments]); + return; + } + + payment.paymentDiscount = paymentDiscount; + } + + if (![self.paymentQueueHandler addPayment:payment]) { + result([FlutterError + errorWithCode:@"storekit_duplicate_product_object" + message:@"There is a pending transaction for the same product identifier. Please " + @"either wait for it to be finished or finish it manually using " + @"`completePurchase` to avoid edge cases." + + details:call.arguments]); + return; + } + result(nil); +} + +- (void)finishTransaction:(FlutterMethodCall *)call result:(FlutterResult)result { + if (![call.arguments isKindOfClass:[NSDictionary class]]) { + result([FlutterError errorWithCode:@"storekit_invalid_argument" + message:@"Argument type of finishTransaction is not a Dictionary" + details:call.arguments]); + return; + } + NSDictionary *paymentMap = (NSDictionary *)call.arguments; + NSString *transactionIdentifier = [paymentMap objectForKey:@"transactionIdentifier"]; + NSString *productIdentifier = [paymentMap objectForKey:@"productIdentifier"]; + + NSArray *pendingTransactions = + [self.paymentQueueHandler getUnfinishedTransactions]; + + for (SKPaymentTransaction *transaction in pendingTransactions) { + // If the user cancels the purchase dialog we won't have a transactionIdentifier. + // So if it is null AND a transaction in the pendingTransactions list has + // also a null transactionIdentifier we check for equal product identifiers. + if ([transaction.transactionIdentifier isEqualToString:transactionIdentifier] || + ([transactionIdentifier isEqual:[NSNull null]] && + transaction.transactionIdentifier == nil && + [transaction.payment.productIdentifier isEqualToString:productIdentifier])) { + @try { + [self.paymentQueueHandler finishTransaction:transaction]; + } @catch (NSException *e) { + result([FlutterError errorWithCode:@"storekit_finish_transaction_exception" + message:e.name + details:e.description]); + return; + } + } + } + + result(nil); +} + +- (void)restoreTransactions:(FlutterMethodCall *)call result:(FlutterResult)result { + if (call.arguments && ![call.arguments isKindOfClass:[NSString class]]) { + result([FlutterError + errorWithCode:@"storekit_invalid_argument" + message:@"Argument is not nil and the type of finishTransaction is not a string." + details:call.arguments]); + return; + } + [self.paymentQueueHandler restoreTransactions:call.arguments]; + result(nil); +} + +#if TARGET_OS_IOS +- (void)presentCodeRedemptionSheet:(FlutterMethodCall *)call result:(FlutterResult)result { + [self.paymentQueueHandler presentCodeRedemptionSheet]; + result(nil); +} +#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); +} + +#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" + binaryMessenger:[_registrar messenger]]; + + _paymentQueueDelegate = [[FIAPPaymentQueueDelegate alloc] + initWithMethodChannel:_paymentQueueDelegateCallbackChannel]; + _paymentQueueHandler.delegate = _paymentQueueDelegate; + } + result(nil); +} +#endif + +- (void)removePaymentQueueDelegate:(FlutterResult)result { + if (@available(iOS 13.0, *)) { + _paymentQueueHandler.delegate = nil; + } + _paymentQueueDelegate = nil; + _paymentQueueDelegateCallbackChannel = nil; + result(nil); +} + +#if TARGET_OS_IOS +- (void)showPriceConsentIfNeeded:(FlutterResult)result { + if (@available(iOS 13.4, *)) { + [_paymentQueueHandler showPriceConsentIfNeeded]; + } + result(nil); +} +#endif + +- (id)getNonNullValueFromDictionary:(NSDictionary *)dictionary forKey:(NSString *)key { + id value = dictionary[key]; + return [value isKindOfClass:[NSNull class]] ? nil : value; +} + +#pragma mark - transaction observer: + +- (void)handleTransactionsUpdated:(NSArray *)transactions { + NSMutableArray *maps = [NSMutableArray new]; + for (SKPaymentTransaction *transaction in transactions) { + [maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]]; + } + [self.transactionObserverCallbackChannel invokeMethod:@"updatedTransactions" arguments:maps]; +} + +- (void)handleTransactionsRemoved:(NSArray *)transactions { + NSMutableArray *maps = [NSMutableArray new]; + for (SKPaymentTransaction *transaction in transactions) { + [maps addObject:[FIAObjectTranslator getMapFromSKPaymentTransaction:transaction]]; + } + [self.transactionObserverCallbackChannel invokeMethod:@"removedTransactions" arguments:maps]; +} + +- (void)handleTransactionRestoreFailed:(NSError *)error { + [self.transactionObserverCallbackChannel + invokeMethod:@"restoreCompletedTransactionsFailed" + arguments:[FIAObjectTranslator getMapFromNSError:error]]; +} + +- (void)restoreCompletedTransactionsFinished { + [self.transactionObserverCallbackChannel + invokeMethod:@"paymentQueueRestoreCompletedTransactionsFinished" + arguments:nil]; +} + +- (void)updatedDownloads:(NSArray *)downloads { + NSLog(@"Received an updatedDownloads callback, but downloads are not supported."); +} + +- (BOOL)shouldAddStorePayment:(SKPayment *)payment product:(SKProduct *)product { + // We always return NO here. And we send the message to dart to process the payment; and we will + // have a interception method that deciding if the payment should be processed (implemented by the + // programmer). + [self.productsCache setObject:product forKey:product.productIdentifier]; + [self.transactionObserverCallbackChannel + invokeMethod:@"shouldAddStorePayment" + arguments:@{ + @"payment" : [FIAObjectTranslator getMapFromSKPayment:payment], + @"product" : [FIAObjectTranslator getMapFromSKProduct:product] + }]; + return NO; +} + +#pragma mark - dependency injection (for unit testing) + +- (SKProductsRequest *)getProductRequestWithIdentifiers:(NSSet *)identifiers { + return [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers]; +} + +- (SKProduct *)getProduct:(NSString *)productID { + return [self.productsCache objectForKey:productID]; +} + +- (SKReceiptRefreshRequest *)getRefreshReceiptRequest:(NSDictionary *)properties { + return [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:properties]; +} + +@end diff --git a/packages/in_app_purchase/in_app_purchase_storekit/shared/in_app_purchase_storekit.podspec b/packages/in_app_purchase/in_app_purchase_storekit/shared/in_app_purchase_storekit.podspec new file mode 100644 index 000000000000..84c385e3405c --- /dev/null +++ b/packages/in_app_purchase/in_app_purchase_storekit/shared/in_app_purchase_storekit.podspec @@ -0,0 +1,26 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# +Pod::Spec.new do |s| + s.name = 'in_app_purchase_storekit' + s.version = '0.0.1' + s.summary = 'Flutter In App Purchase iOS and macOS' + s.description = <<-DESC +A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store. +Downloaded by pub (not CocoaPods). + DESC + s.homepage = 'https://github.com/flutter/plugins' + s.license = { :type => 'BSD', :file => '../LICENSE' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_storekit' } + # TODO(mvanbeusekom): update URL when in_app_purchase_storekit package is published. + # Updating it before the package is published will cause a lint error and block the tree. + s.documentation_url = 'https://pub.dev/packages/in_app_purchase' + s.source_files = 'Classes/**/*' + s.public_header_files = 'Classes/**/*.h' + s.ios.dependency 'Flutter' + s.osx.dependency 'FlutterMacOS' + s.ios.deployment_target = '9.0' + s.osx.deployment_target = '10.15' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } +end