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
Add ownershipType to entitlementInfo #278
Changes from 1 commit
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 |
---|---|---|
|
@@ -47,6 +47,12 @@ class EntitlementInfo { | |
/// Check the `isActive` property. | ||
final String? billingIssueDetectedAt; | ||
|
||
/// Use this property to determine whether a purchase was made by the current | ||
/// user or shared to them by a family member. This can be useful for | ||
/// onboarding users who have had an entitlement shared with them, but might | ||
/// not be entirely aware of the benefits they now have. | ||
final OwnershipType ownershipType; | ||
|
||
/// Construct an EntitlementInfo | ||
EntitlementInfo( | ||
this.identifier, | ||
|
@@ -60,7 +66,8 @@ class EntitlementInfo { | |
this.productIdentifier, | ||
this.isSandbox, | ||
this.unsubscribeDetectedAt, | ||
this.billingIssueDetectedAt); | ||
this.billingIssueDetectedAt, | ||
this.ownershipType); | ||
|
||
/// Constructs an EntitlementInfo from a JSON object | ||
factory EntitlementInfo.fromJson(Map<dynamic, dynamic> json) { | ||
|
@@ -100,6 +107,17 @@ class EntitlementInfo { | |
store = Store.unknownStore; | ||
break; | ||
} | ||
late var ownershipType; | ||
switch (json["ownershipType"]) { | ||
case "PURCHASED": | ||
ownershipType = OwnershipType.purchased; | ||
break; | ||
case "FAMILY_SHARING": | ||
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. This should be 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. Fixed |
||
ownershipType = OwnershipType.familySharing; | ||
break; | ||
default: | ||
ownershipType = OwnershipType.unknown; | ||
} | ||
return EntitlementInfo( | ||
json["identifier"] as String, | ||
json["isActive"] as bool, | ||
|
@@ -112,12 +130,13 @@ class EntitlementInfo { | |
json["productIdentifier"] as String, | ||
json["isSandbox"] as bool, | ||
json["unsubscribeDetectedAt"] as String?, | ||
json["billingIssueDetectedAt"] as String?); | ||
json["billingIssueDetectedAt"] as String?, | ||
ownershipType); | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'EntitlementInfo{identifier: $identifier, isActive: $isActive, willRenew: $willRenew, periodType: $periodType, latestPurchaseDate: $latestPurchaseDate, originalPurchaseDate: $originalPurchaseDate, expirationDate: $expirationDate, store: $store, productIdentifier: $productIdentifier, isSandbox: $isSandbox, unsubscribeDetectedAt: $unsubscribeDetectedAt, billingIssueDetectedAt: $billingIssueDetectedAt}'; | ||
return 'EntitlementInfo{identifier: $identifier, isActive: $isActive, willRenew: $willRenew, periodType: $periodType, latestPurchaseDate: $latestPurchaseDate, originalPurchaseDate: $originalPurchaseDate, expirationDate: $expirationDate, store: $store, productIdentifier: $productIdentifier, isSandbox: $isSandbox, unsubscribeDetectedAt: $unsubscribeDetectedAt, billingIssueDetectedAt: $billingIssueDetectedAt, ownershipType: $ownershipType}'; | ||
} | ||
|
||
@override | ||
|
@@ -136,7 +155,8 @@ class EntitlementInfo { | |
this.productIdentifier == other.productIdentifier && | ||
this.isSandbox == other.isSandbox && | ||
this.unsubscribeDetectedAt == other.unsubscribeDetectedAt && | ||
this.billingIssueDetectedAt == other.billingIssueDetectedAt); | ||
this.billingIssueDetectedAt == other.billingIssueDetectedAt && | ||
this.ownershipType == other.ownershipType); | ||
} | ||
} | ||
|
||
|
@@ -175,3 +195,16 @@ enum Store { | |
/// For entitlements granted via an unknown store. | ||
unknownStore | ||
} | ||
|
||
/// Enum of ownership types | ||
enum OwnershipType { | ||
/// For ownership when a user made the purchase themselves | ||
purchased, | ||
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. These docs look great, but maybe we can reuse the docs in the iOS enum? https://github.com/RevenueCat/purchases-ios/blob/main/Purchases/Public/PurchaseOwnershipType.swift#L20 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. Used the iOS docs and also updated the |
||
|
||
/// For ownership when a user has been shared the purchase via family sharing | ||
familySharing, | ||
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. This should be 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. Fixed |
||
|
||
/// For when the ownership type is unknown. Maybe there is no purchase. | ||
/// Maybe it came from a store which doesn't publish this information | ||
unknown | ||
} |
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 adding this here. We can take care of the Changelog when releasing the newer version, so no need to add this in the Changelog for now 😄