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

in_app_purchase: started supported null as a parameter for the simulatesAskToBuyInSandbox #3110

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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