Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
in_app_purchase: started supported null as a parameter for the sandbo…
Browse files Browse the repository at this point in the history
…x arguement
  • Loading branch information
gaaclarke committed Oct 3, 2020
1 parent 18771ff commit d0b7ddc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

## 0.3.4+11

* [iOS] Fixed: crash when sending null for simulatesAskToBuyInSandbox parameter.

## 0.3.4+10

* Fixed typo 'verity' for 'verify'.
Expand Down
6 changes: 4 additions & 2 deletions packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ - (void)addPayment:(FlutterMethodCall *)call result:(FlutterResult)result {
NSNumber *quantity = [paymentMap objectForKey:@"quantity"];
payment.quantity = (quantity != nil) ? quantity.integerValue : 1;
if (@available(iOS 8.3, *)) {
payment.simulatesAskToBuyInSandbox =
[[paymentMap objectForKey:@"simulatesAskToBuyInSandbox"] boolValue];
NSNumber *simulatesAskToBuyInSandbox = [paymentMap objectForKey:@"simulatesAskToBuyInSandbox"];
payment.simulatesAskToBuyInSandbox = (id)simulatesAskToBuyInSandbox == (id)[NSNull null]
? NO
: [simulatesAskToBuyInSandbox boolValue];
}

if (![self.paymentQueueHandler addPayment:payment]) {
Expand Down
45 changes: 45 additions & 0 deletions packages/in_app_purchase/ios/Tests/InAppPurchasePluginTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,51 @@ - (void)testAddPaymentSuccessWithMockQueue {
XCTAssertEqual(transactionForUpdateBlock.transactionState, SKPaymentTransactionStatePurchased);
}

- (void)testAddPaymentWithNullSandboxArgument {
XCTestExpectation* expectation =
[self expectationWithDescription:@"result should return success state"];
XCTestExpectation* simulatesAskToBuyInSandboxExpectation =
[self expectationWithDescription:@"payment isn't simulatesAskToBuyInSandbox"];
FlutterMethodCall* call =
[FlutterMethodCall methodCallWithMethodName:@"-[InAppPurchasePlugin addPayment:result:]"
arguments:@{
@"productIdentifier" : @"123",
@"quantity" : @(1),
@"simulatesAskToBuyInSandbox" : [NSNull null],
}];
SKPaymentQueueStub* queue = [SKPaymentQueueStub new];
queue.testState = SKPaymentTransactionStatePurchased;
__block SKPaymentTransaction* transactionForUpdateBlock;
self.plugin.paymentQueueHandler = [[FIAPaymentQueueHandler alloc] initWithQueue:queue
transactionsUpdated:^(NSArray<SKPaymentTransaction*>* _Nonnull transactions) {
SKPaymentTransaction* transaction = transactions[0];
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
transactionForUpdateBlock = transaction;
[expectation fulfill];
}
if (@available(iOS 8.3, *)) {
if (!transaction.payment.simulatesAskToBuyInSandbox) {
[simulatesAskToBuyInSandboxExpectation fulfill];
}
} else {
[simulatesAskToBuyInSandboxExpectation fulfill];
}
}
transactionRemoved:nil
restoreTransactionFailed:nil
restoreCompletedTransactionsFinished:nil
shouldAddStorePayment:^BOOL(SKPayment* _Nonnull payment, SKProduct* _Nonnull product) {
return YES;
}
updatedDownloads:nil];
[queue addTransactionObserver:self.plugin.paymentQueueHandler];
[self.plugin handleMethodCall:call
result:^(id r){
}];
[self waitForExpectations:@[ expectation, simulatesAskToBuyInSandboxExpectation ] timeout:5];
XCTAssertEqual(transactionForUpdateBlock.transactionState, SKPaymentTransactionStatePurchased);
}

- (void)testRestoreTransactions {
XCTestExpectation* expectation =
[self expectationWithDescription:@"result successfully restore transactions"];
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: in_app_purchase
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase
version: 0.3.4+10
version: 0.3.4+11

dependencies:
async: ^2.0.8
Expand Down

0 comments on commit d0b7ddc

Please sign in to comment.