-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[in_app_purchase] add storefront in skpaymentqueuewrapper #5348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result | |
| [self canMakePayments:result]; | ||
| } else if ([@"-[SKPaymentQueue transactions]" isEqualToString:call.method]) { | ||
| [self getPendingTransactions:result]; | ||
| } else if ([@"-[SKPaymentQueue storefront]" isEqualToString:call.method]) { | ||
| [self getStorefront:result]; | ||
| } else if ([@"-[InAppPurchasePlugin startProductRequest:result:]" isEqualToString:call.method]) { | ||
| [self handleProductRequestMethodCall:call result:result]; | ||
| } else if ([@"-[InAppPurchasePlugin addPayment:result:]" isEqualToString:call.method]) { | ||
|
|
@@ -139,6 +141,22 @@ - (void)getPendingTransactions:(FlutterResult)result { | |
| result(transactionMaps); | ||
| } | ||
|
|
||
| - (void)getStorefront:(FlutterResult)result { | ||
| if (@available(iOS 13.0, *)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should include macOS 10.15+ here too. |
||
| SKStorefront *storefront = self.paymentQueueHandler.storefront; | ||
| if (!storefront) { | ||
| result(nil); | ||
| return; | ||
| } | ||
| result([FIAObjectTranslator getMapFromSKStorefront:storefront]); | ||
| return; | ||
| } else { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: no need to wrap code after an early return in |
||
| NSLog(@"storefront is not avaialbe in iOS below 13.0."); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this should mention both iOS and macOS. |
||
| result(nil); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| - (void)handleProductRequestMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { | ||
| if (![call.arguments isKindOfClass:[NSArray class]]) { | ||
| result([FlutterError errorWithCode:@"storekit_invalid_argument" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -419,6 +419,71 @@ - (void)testGetPendingTransactions { | |
| XCTAssertEqualObjects(resultArray, @[ transactionMap ]); | ||
| } | ||
|
|
||
| - (void)testPaymentQueueStorefront { | ||
| if (@available(iOS 13, *)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or macOS 10.15 |
||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: These should be two separate test methods, rather than sub-blocks of the same test. Unit tests should each test as few things as is feasible. |
||
| // storefront is not nil | ||
| XCTestExpectation *expectation = [self expectationWithDescription:@"expect success"]; | ||
| FlutterMethodCall *call = | ||
| [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue storefront]" | ||
| arguments:nil]; | ||
| SKPaymentQueue *mockQueue = OCMClassMock(SKPaymentQueue.class); | ||
| NSDictionary *storefrontMap = @{ | ||
| @"countryCode" : @"USA", | ||
| @"identifier" : @"unique_identifier", | ||
| }; | ||
| OCMStub(mockQueue.storefront).andReturn([[SKStorefrontStub alloc] initWithMap:storefrontMap]); | ||
|
|
||
| __block NSDictionary *resultMap; | ||
| 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) { | ||
| resultMap = r; | ||
| [expectation fulfill]; | ||
| }]; | ||
| [self waitForExpectations:@[ expectation ] timeout:5]; | ||
| XCTAssertEqualObjects(resultMap, storefrontMap); | ||
| } | ||
| { | ||
| // storefront is nil | ||
| XCTestExpectation *expectation = [self expectationWithDescription:@"expect success"]; | ||
| FlutterMethodCall *call = | ||
| [FlutterMethodCall methodCallWithMethodName:@"-[SKPaymentQueue storefront]" | ||
| arguments:nil]; | ||
| SKPaymentQueue *mockQueue = OCMClassMock(SKPaymentQueue.class); | ||
| OCMStub(mockQueue.storefront).andReturn(nil); | ||
|
|
||
| __block NSDictionary *resultMap; | ||
| 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) { | ||
| resultMap = r; | ||
| [expectation fulfill]; | ||
| }]; | ||
| [self waitForExpectations:@[ expectation ] timeout:5]; | ||
| XCTAssertNil(resultMap); | ||
| } | ||
| } else { | ||
| NSLog(@"Skip testPaymentQueueStorefront for iOS lower than 13.0."); | ||
| } | ||
| } | ||
|
|
||
| - (void)testStartObservingPaymentQueue { | ||
| XCTestExpectation *expectation = | ||
| [self expectationWithDescription:@"Should return success result"]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,16 @@ class SKPaymentQueueWrapper { | |
| SKPaymentQueueDelegateWrapper? _paymentQueueDelegate; | ||
| SKTransactionObserverWrapper? _observer; | ||
|
|
||
| /// Calls [`[SKPaymentQueue storefront]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/3182430-storefront?language=objc) | ||
|
stuartmorgan-g marked this conversation as resolved.
Outdated
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing a period. |
||
| Future<SKStorefrontWrapper?> storefront() async { | ||
| final Map<String, dynamic>? storefrontMap = await channel | ||
| .invokeMapMethod<String, dynamic>('-[SKPaymentQueue storefront]'); | ||
| if (storefrontMap == null) { | ||
| return null; | ||
| } | ||
| return SKStorefrontWrapper.fromJson(storefrontMap); | ||
| } | ||
|
|
||
| /// Calls [`-[SKPaymentQueue transactions]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506026-transactions?language=objc) | ||
| Future<List<SKPaymentTransactionWrapper>> transactions() async { | ||
| return _getTransactionList((await channel | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we only want this to be
nonatomicon iOS? Surely we don't have different threading semantics for macOS?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The storefront property in SKPaymentQueue is nonatomic on iOS. I tried to keep it the sam way but yeah we don't need it. Will revert to nonatomic for all.