Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong type purchase package purchase product #301

Merged
merged 6 commits into from
Jan 18, 2022

Conversation

vegaro
Copy link
Contributor

@vegaro vegaro commented Jan 18, 2022

[sc-12529]

Fixes #300

This line https://github.com/RevenueCat/purchases-flutter/pull/270/files#diff-2a88ebe6bbbad2ced268a39ea09b1e2d0553678f4e1e43bc8ed79a31c3b3921bL73 changed from Map<dynamic, dynamic> to Map<String, dynamic>.

It would have been caught by tests, but it's a shame we didn't have tests for such crucial functions. I added some tests for the fixed functions and will follow up with a PR making sure all functions are tested to prevent this from happening again. I want to release ASAP.

@@ -628,6 +635,32 @@ class Purchases {
/// Android only. Call close when you are done with this instance of Purchases to disconnect
/// from the billing services and clean up resources
static Future<void> close() => _channel.invokeMethod('close');

static Future<Map<String, dynamic>>
_invokeMethodReturningPurchaserInfoJsonFromMap(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better names accepted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just be invokeMethodReturningPurchaserInfoJson. but maybe we can also just call invokeMethodReturningMap here, and then have a method getPurchaserInfoJsonFromMap or something, to separate out the two pieces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked the idea of extracting _getPurchaserInfoJsonFromMap. Checkout the latest commit

@vegaro vegaro requested a review from aboedo January 18, 2022 16:27
Copy link
Member

@aboedo aboedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! left minor suggestions, they can go into a follow-up PR too

method,
arguments,
);
final response = Map<String, dynamic>.from(result!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can log if result is nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will crash, and I think it should crash because something is very wrong if there's no result, so I don't think logging is necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i agree it should crash, just seems like we sometimes don't get the most descriptive error messages. i suppose using the ! should give us a clear message though

@vegaro vegaro force-pushed the fix-wrong-type-purchasePackage-purchaseProduct branch from d4c24a5 to aa04b53 Compare January 18, 2022 20:49
@vegaro
Copy link
Contributor Author

vegaro commented Jan 18, 2022

@aboedo @beylmk I renamed the functions and extracted the part where we get the Json from the Map. Let me know what you think

Copy link
Member

@aboedo aboedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ it

Copy link
Contributor

@beylmk beylmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vegaro vegaro merged commit 8405eb8 into main Jan 18, 2022
@vegaro vegaro deleted the fix-wrong-type-purchasePackage-purchaseProduct branch January 18, 2022 21:59
@beylmk beylmk mentioned this pull request Jan 18, 2022
Jethro87 pushed a commit to Jethro87/purchases-flutter that referenced this pull request Jan 4, 2025
* run codegen.sh

* fix purchasePackage and purchaseProduct

* fix discounted versions

* use [dynamic arguments]

* ignore trailing commas

* some rename + refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants