Skip to content

Commit 2aa6e3f

Browse files
blaugoldLouiseHsu
andauthored
[in_app_purchase_storekit] Fix type of error code returned from native code in SKReceiptManager.retrieveReceiptData (flutter#6265)
The native code did not convert the integer `code` returned from `FIAObjectTranslator getMapFromNSError` to a string before passing it to `FlutterError errorWithCode`. This allowed an `int` to flow into a position where the corresponding Dart code expects a `String`. Fixes flutter#144595 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates [following repository CHANGELOG style]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests Co-authored-by: LouiseHsu <[email protected]>
1 parent 4ece1dd commit 2aa6e3f

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.12+1
2+
3+
* Fixes type of error code returned from native code in SKReceiptManager.retrieveReceiptData.
4+
15
## 0.3.12
26

37
* Converts `refreshReceipt()`, `startObservingPaymentQueue()`, `stopObservingPaymentQueue()`,

packages/in_app_purchase/in_app_purchase_storekit/darwin/Classes/FIAPReceiptManager.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ - (NSString *)retrieveReceiptWithError:(FlutterError **)flutterError {
2929
if (!receipt || receiptError) {
3030
if (flutterError) {
3131
NSDictionary *errorMap = [FIAObjectTranslator getMapFromNSError:receiptError];
32-
*flutterError = [FlutterError errorWithCode:errorMap[@"code"]
33-
message:errorMap[@"domain"]
34-
details:errorMap[@"userInfo"]];
32+
*flutterError =
33+
[FlutterError errorWithCode:[NSString stringWithFormat:@"%@", errorMap[@"code"]]
34+
message:errorMap[@"domain"]
35+
details:errorMap[@"userInfo"]];
3536
}
3637
return nil;
3738
}

packages/in_app_purchase/in_app_purchase_storekit/example/shared/RunnerTests/InAppPurchasePluginTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ - (void)testRetrieveReceiptDataError {
307307

308308
XCTAssertNil(result);
309309
XCTAssertNotNil(error);
310+
XCTAssert([error.code isKindOfClass:[NSString class]]);
310311
NSDictionary *details = error.details;
311312
XCTAssertNotNil(details[@"error"]);
312313
NSNumber *errorCode = (NSNumber *)details[@"error"][@"code"];

packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_storekit
22
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit
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.3.12
5+
version: 0.3.12+1
66

77
environment:
88
sdk: ^3.2.3

0 commit comments

Comments
 (0)