-
Notifications
You must be signed in to change notification settings - Fork 192
Change result of purchase methods to PurchaseResult #1408
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
Changes from all commits
eb49155
0d3dde9
ce152ff
649d72a
8e8944b
ac72a62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:purchases_flutter/object_wrappers.dart'; | ||
|
||
// ignore_for_file: unused_element | ||
// ignore_for_file: unused_local_variable | ||
// ignore_for_file: deprecated_member_use | ||
class _PurchaseResultApiTest { | ||
void _checkFromJsonFactory(Map<String, dynamic> json) { | ||
PurchaseResult transaction = PurchaseResult.fromJson(json); | ||
} | ||
|
||
void _checkConstructor( | ||
CustomerInfo customerInfo, | ||
StoreTransaction storeTransaction) { | ||
PurchaseResult purchaseResult = | ||
PurchaseResult(customerInfo, storeTransaction); | ||
} | ||
|
||
void _checkProperties(PurchaseResult purchaseResult) { | ||
CustomerInfo customerInfo = purchaseResult.customerInfo; | ||
StoreTransaction storeTransaction = purchaseResult.storeTransaction; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
import 'customer_info_wrapper.dart'; | ||
import 'store_transaction.dart'; | ||
|
||
/// Represents the successful result of a purchase operation. | ||
class PurchaseResult extends Equatable { | ||
/// The updated [CustomerInfo] after the purchase has been synced with | ||
/// RevenueCat's servers. | ||
final CustomerInfo customerInfo; | ||
/// The [StoreTransaction] for this purchase. | ||
final StoreTransaction storeTransaction; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that in the web platforms (RN and capacitor) we also have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing you mean that it's part of the |
||
|
||
const PurchaseResult( | ||
this.customerInfo, | ||
this.storeTransaction, | ||
); | ||
|
||
factory PurchaseResult.fromJson(Map<String, dynamic> json) => PurchaseResult( | ||
CustomerInfo.fromJson(Map<String, dynamic>.from(json['customerInfo'])), | ||
StoreTransaction.fromJson(Map<String, dynamic>.from(json['transaction'])), | ||
); | ||
|
||
@override | ||
List<Object> get props => [ | ||
customerInfo, | ||
storeTransaction, | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why we need to test the constructor's API.
Is the constructor public? If so, if we ever need to add an extra property to
PurchaseResult
, it would be a breaking change since the constructor would also change. Or am I missing something? (note that I knownull
about Dart 😅)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question! So the constructors for all our classes are currently public in dart (they were public before removing freezed as well). If we need to add new fields in the future, we would need to add multiple constructors, falling back to some default when no value is passed. This can indeed be problematic if no good default can be set though...
We could try to make the constructors package private... we haven't really been doing that until now, but I guess that now that we have removed freezed, we have more control. I might just want to leave it like this for now so we dedicate more time to study our options moving forward. Wdyt @RevenueCat/coresdk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! Exactly, it might be problematic if we need to add new fields in the future.
Yes, I think this should be our end goal. But I agree that, for now, we can leave it like this and think about this in the future 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I like non-public constructors, but doing that now would be a breaking change right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup... though having said that, it would be "ok" since we're releasing this on a major anyway. My main concern is over delaying the release for this, since I'm not sure of the best way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah I'm not sure either. It's not just adding visibility modifiers? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for package private you need to define each file as part of a library, and prepend any method with an
_
: https://medium.com/@simplemanderson/dart-libraries-and-visibility-and-how-they-caught-me-by-surprise-d98ba7868fde.I just need to test that it works 😅 (I'm focusing on returning the StoreTransaction in purchases-unity after a purchase but I can test this in a bit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just testing this for a bit and it's not straightforward... We would need to define a library and make all models a
part of
that library... I wouldn't make that change right now without more testing, so I would prefer to keep it as is for this major. Wdyt @JayShortway @ajpallares ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining and testing! 🙏 In that case I'd be okay keeping it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the investigation Toni! Sure, let's go with what we have right now, as it involves way deeper changes 👍