Skip to content

Commit d24cc15

Browse files
renefloorfotiDim
authored andcommitted
[in_app_purchase] Fix crash when retrieveReceiptWithError gives an error. (flutter#4138)
1 parent 7fa9e43 commit d24cc15

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

packages/in_app_purchase/in_app_purchase_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.2+2
2+
3+
* Fix crash when retrieveReceiptWithError gives an error.
4+
15
## 0.1.2+1
26

37
* Fix wrong data type when cancelling user credentials dialog.

packages/in_app_purchase/in_app_purchase_ios/example/ios/RunnerTests/InAppPurchasePluginTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ - (void)testRetrieveReceiptDataError {
251251
[self waitForExpectations:@[ expectation ] timeout:5];
252252
XCTAssertNotNil(result);
253253
XCTAssert([result isKindOfClass:[FlutterError class]]);
254+
NSDictionary* details = ((FlutterError*)result).details;
255+
XCTAssertNotNil(details[@"error"]);
256+
NSNumber* errorCode = (NSNumber*)details[@"error"][@"code"];
257+
XCTAssertEqual(errorCode, [NSNumber numberWithInteger:99]);
254258
}
255259

256260
- (void)testRefreshReceiptRequest {

packages/in_app_purchase/in_app_purchase_ios/example/ios/RunnerTests/Stubs.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,15 @@ @implementation FIAPReceiptManagerStub : FIAPReceiptManager
261261

262262
- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
263263
if (self.returnError) {
264-
*error = [[NSError alloc] init];
264+
*error = [NSError errorWithDomain:@"test"
265+
code:1
266+
userInfo:@{
267+
@"name" : @"test",
268+
@"houseNr" : @5,
269+
@"error" : [[NSError alloc] initWithDomain:@"internalTestDomain"
270+
code:99
271+
userInfo:nil]
272+
}];
265273
return nil;
266274
}
267275
NSString *originalString = [NSString stringWithFormat:@"test"];

packages/in_app_purchase/in_app_purchase_ios/ios/Classes/FIAPReceiptManager.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "FIAPReceiptManager.h"
66
#import <Flutter/Flutter.h>
7+
#import "FIAObjectTranslator.h"
78

89
@interface FIAPReceiptManager ()
910
// Gets the receipt file data from the location of the url. Can be nil if
@@ -20,10 +21,10 @@ - (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError {
2021
NSData *receipt = [self getReceiptData:receiptURL error:&receiptError];
2122
if (!receipt || receiptError) {
2223
if (flutterError) {
23-
*flutterError = [FlutterError
24-
errorWithCode:[[NSString alloc] initWithFormat:@"%li", (long)receiptError.code]
25-
message:receiptError.domain
26-
details:receiptError.userInfo];
24+
NSDictionary *errorMap = [FIAObjectTranslator getMapFromNSError:receiptError];
25+
*flutterError = [FlutterError errorWithCode:errorMap[@"code"]
26+
message:errorMap[@"domain"]
27+
details:errorMap[@"userInfo"]];
2728
}
2829
return nil;
2930
}

packages/in_app_purchase/in_app_purchase_ios/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_ios
22
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the iOS StoreKit Framework.
33
repository: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase_ios
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.1.2+1
5+
version: 0.1.2+2
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)