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

[in_app_purchase] Fix crash when retrieveReceiptWithError gives an error. #4138

Merged
merged 7 commits into from
Jul 8, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/in_app_purchase/in_app_purchase_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.2+2

* Fix crash when retrieveReceiptWithError gives an error.

## 0.1.2+1

* Fix wrong data type when cancelling user credentials dialog.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ - (void)testRetrieveReceiptDataError {
[self waitForExpectations:@[ expectation ] timeout:5];
XCTAssertNotNil(result);
XCTAssert([result isKindOfClass:[FlutterError class]]);
NSDictionary* details = ((FlutterError*)result).details;
XCTAssertNotNil(details[@"error"]);
NSNumber* errorCode = (NSNumber*)details[@"error"][@"code"];
XCTAssertEqual(errorCode, [NSNumber numberWithInteger:99]);
}

- (void)testRefreshReceiptRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ @implementation FIAPReceiptManagerStub : FIAPReceiptManager

- (NSData *)getReceiptData:(NSURL *)url error:(NSError **)error {
if (self.returnError) {
*error = [[NSError alloc] init];
*error = [NSError errorWithDomain:@"test"
code:1
userInfo:@{
@"name" : @"test",
@"houseNr" : @5,
@"error" : [[NSError alloc] initWithDomain:@"internalTestDomain"
code:99
userInfo:nil]
}];
return nil;
}
NSString *originalString = [NSString stringWithFormat:@"test"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#import "FIAPReceiptManager.h"
#import <Flutter/Flutter.h>
#import "FIAObjectTranslator.h"

@interface FIAPReceiptManager ()
// Gets the receipt file data from the location of the url. Can be nil if
Expand All @@ -20,10 +21,10 @@ - (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError {
NSData *receipt = [self getReceiptData:receiptURL error:&receiptError];
if (!receipt || receiptError) {
if (flutterError) {
*flutterError = [FlutterError
errorWithCode:[[NSString alloc] initWithFormat:@"%li", (long)receiptError.code]
message:receiptError.domain
details:receiptError.userInfo];
NSDictionary *errorMap = [FIAObjectTranslator getMapFromNSError:receiptError];
*flutterError = [FlutterError errorWithCode:errorMap[@"code"]
message:errorMap[@"domain"]
details:errorMap[@"userInfo"]];
}
return nil;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/in_app_purchase_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_ios
description: An implementation for the iOS platform of the Flutter `in_app_purchase` plugin. This uses the iOS StoreKit Framework.
repository: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.1.2+1
version: 0.1.2+2

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down