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

Add ownershipType to entitlementInfo #278

Merged
merged 4 commits into from Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,5 @@
- Adds ownershipType to the EntitlementInfo wrapper

Copy link
Contributor

@vegaro vegaro Nov 29, 2021

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 😄

## 3.7.0

- Bump`purchases-hybrid-common` to `1.11.0` [Changelog here](https://github.com/RevenueCat/purchases-hybrid-common/releases/tag/1.11.0)
Expand Down
41 changes: 37 additions & 4 deletions lib/entitlement_info_wrapper.dart
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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":
Copy link
Contributor

@vegaro vegaro Nov 30, 2021

Choose a reason for hiding this comment

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

This should be FAMILY_SHARED as commented in the android PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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,
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used the iOS docs and also updated the purchases-android ones to match. I included the UNKNOWN because it looks like the linter wants all public fields documented.


/// For ownership when a user has been shared the purchase via family sharing
familySharing,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be familyShared

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}