Skip to content

Commit c037496

Browse files
gaaclarkeEgor
authored and
Egor
committed
in_app_purchase: started supported null as a parameter for the sandbox arguement (flutter#3110)
1 parent 26b2284 commit c037496

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

packages/in_app_purchase/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## 0.3.4+11
3+
4+
* [iOS] Fixed: crash when sending null for simulatesAskToBuyInSandbox parameter.
5+
26
## 0.3.4+10
37

48
* Fixed typo 'verity' for 'verify'.

packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ - (void)addPayment:(FlutterMethodCall *)call result:(FlutterResult)result {
179179
NSNumber *quantity = [paymentMap objectForKey:@"quantity"];
180180
payment.quantity = (quantity != nil) ? quantity.integerValue : 1;
181181
if (@available(iOS 8.3, *)) {
182-
payment.simulatesAskToBuyInSandbox =
183-
[[paymentMap objectForKey:@"simulatesAskToBuyInSandbox"] boolValue];
182+
NSNumber *simulatesAskToBuyInSandbox = [paymentMap objectForKey:@"simulatesAskToBuyInSandbox"];
183+
payment.simulatesAskToBuyInSandbox = (id)simulatesAskToBuyInSandbox == (id)[NSNull null]
184+
? NO
185+
: [simulatesAskToBuyInSandbox boolValue];
184186
}
185187

186188
if (![self.paymentQueueHandler addPayment:payment]) {

packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,51 @@ - (void)testAddPaymentSuccessWithMockQueue {
146146
XCTAssertEqual(transactionForUpdateBlock.transactionState, SKPaymentTransactionStatePurchased);
147147
}
148148

149+
- (void)testAddPaymentWithNullSandboxArgument {
150+
XCTestExpectation* expectation =
151+
[self expectationWithDescription:@"result should return success state"];
152+
XCTestExpectation* simulatesAskToBuyInSandboxExpectation =
153+
[self expectationWithDescription:@"payment isn't simulatesAskToBuyInSandbox"];
154+
FlutterMethodCall* call =
155+
[FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]"
156+
arguments:@{
157+
@"productIdentifier" : @"123",
158+
@"quantity" : @(1),
159+
@"simulatesAskToBuyInSandbox" : [NSNull null],
160+
}];
161+
SKPaymentQueueStub* queue = [SKPaymentQueueStub new];
162+
queue.testState = SKPaymentTransactionStatePurchased;
163+
__block SKPaymentTransaction* transactionForUpdateBlock;
164+
self.plugin.paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue
165+
transactionsUpdated:^(NSArray<SKPaymentTransaction*>* _Nonnull transactions) {
166+
SKPaymentTransaction* transaction = transactions[0];
167+
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
168+
transactionForUpdateBlock = transaction;
169+
[expectation fulfill];
170+
}
171+
if (@available(iOS 8.3, *)) {
172+
if (!transaction.payment.simulatesAskToBuyInSandbox) {
173+
[simulatesAskToBuyInSandboxExpectation fulfill];
174+
}
175+
} else {
176+
[simulatesAskToBuyInSandboxExpectation fulfill];
177+
}
178+
}
179+
transactionRemoved:nil
180+
restoreTransactionFailed:nil
181+
restoreCompletedTransactionsFinished:nil
182+
shouldAddStorePayment:^BOOL(SKPayment* _Nonnull payment, SKProduct* _Nonnull product) {
183+
return YES;
184+
}
185+
updatedDownloads:nil];
186+
[queue addTransactionObserver:self.plugin.paymentQueueHandler];
187+
[self.plugin handleMethodCall:call
188+
result:^(id r){
189+
}];
190+
[self waitForExpectations:@[ expectation, simulatesAskToBuyInSandboxExpectation ] timeout:5];
191+
XCTAssertEqual(transactionForUpdateBlock.transactionState, SKPaymentTransactionStatePurchased);
192+
}
193+
149194
- (void)testRestoreTransactions {
150195
XCTestExpectation* expectation =
151196
[self expectationWithDescription:@"result successfully restore transactions"];

packages/in_app_purchase/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: in_app_purchase
22
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase
4-
version: 0.3.4+10
4+
version: 0.3.4+11
55

66
dependencies:
77
async: ^2.0.8

0 commit comments

Comments
 (0)