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

Adds subscriptions to CustomerInfo #4508

Merged
merged 19 commits into from
Dec 4, 2024
Merged

Conversation

vegaro
Copy link
Contributor

@vegaro vegaro commented Nov 21, 2024

We had more information we were not exposing in the CustomerInfo JSON

This PR adds CustomerInfo.subscriptions which has some useful information for devs that don't use the entitlements system

@vegaro vegaro added the pr:feat A new feature label Nov 22, 2024
@vegaro vegaro force-pushed the add-subscription-to-customer-info branch from 2308788 to 3cbefb9 Compare November 22, 2024 13:47
@vegaro vegaro marked this pull request as ready for review November 27, 2024 08:08
@vegaro vegaro requested review from a team and aboedo November 27, 2024 08:09
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.

I think this is fine.

But there's one thing that just feels a bit odd to me in the fact that we're using our own public REST API, but then we abstract it privately, then make it public again.

It's not like it's a very internal REST API either - it's very much public and stable and we wouldn't just modify it out the blue since it would break older SDKs, which makes me feel like we're overcomplicating things a bit

Comment on lines 91 to 92
/// Dictionary of all subscription product identifiers and their subscription info
@objc public let subscriptions: [String: SubscriptionInfo]
Copy link
Member

Choose a reason for hiding this comment

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

my first thought was that it's a bit confusing that this is a dict but nonSubscriptions is an array. I get why, but naming-wise I'd maybe have expected both to be the same. Wonder if subscriptionsByProductIdentifier would have helped, but not sure. Or maybe even typealiasing ProductIdentifier = String so that then you have the type [ProductIdentifier: SubscriptionInfo].
Then again you could make the argument that we should have all APIs do that or none ¯\(ツ)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also a bit confusing with activeSubscriptions being only the subs ids and this being full objects... Maybe something like allSubscriptionsInfo? Or maybe too verbose not sure...

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could deprecate activeSubscriptions as part of this change? Not a ton of value in that anymore, and very easy to recreate with subscriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, @fire-at-will made the same comment that maybe subscriptions could be a Set. Imho I think a dictionary makes more sense since most people using this would want to get a subscription by product identifier, and making it a Set forces them to use a filter. Making it a dictionary offers accessing by product id and also offers a .values to access only the values.

Thoughts:

  • activeSubscriptions should really be activeSubscriptionProductIds or something like that
  • I think I would not want to deprecate activeSubscriptions, maybe in the next major, but I still see activeSubscriptions valuable since it saves folks from having to do logic on subscriptions to get the active ones. I would treat it as syntactic sugar.
  • allSubscriptionsInfo also makes sense, but I don't think it cleans up the fact that activeSubscriptions is just the product ids and allSubscriptionsInfo classes. I think it would still missing the informatino that it is a dictionary
  • subscriptionsByProductIdentifier makes a lot of sense. And the typealias ProductIdentifier can also be added. I think that would be the most informative and most correct. I think byProductIdentifier is important so we can replicate it in the rest of the SDKs that don't have type aliases

Sources/Purchasing/NonSubscriptionTransaction.swift Outdated Show resolved Hide resolved
@aboedo
Copy link
Member

aboedo commented Nov 27, 2024

or rather, I guess what I'm asking is "should we just make the subscriber object public instead"

Copy link
Member

@JayShortway JayShortway left a comment

Choose a reason for hiding this comment

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

I'm pretty excited about this! 😄 No comments other than Andy's.

Sources/Identity/SubscriptionInfo.swift Show resolved Hide resolved
var purchaseDate: Date?
var purchaseDate: Date
Copy link
Member

Choose a reason for hiding this comment

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

Just checking that we know this is always available, and having it optional was being too defensive?

Copy link
Contributor Author

@vegaro vegaro Dec 3, 2024

Choose a reason for hiding this comment

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

I checked in the backend and it's not optional there

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

Agreed this is great! Left some comments but I think this could work as is.

@objc public let storeTransactionId: String?

/// Whether the subscription is currently active.
@objc public let isActive: Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Small concern but I'm wondering if we should have a VerificationResult (from trusted entitlements) here as well, or maybe move the existing one in EntitlementInfos up to the CustomerInfo entity... otherwise some devs might use this without checking trusted entitlements...

Comment on lines 91 to 92
/// Dictionary of all subscription product identifiers and their subscription info
@objc public let subscriptions: [String: SubscriptionInfo]
Copy link
Contributor

Choose a reason for hiding this comment

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

It's also a bit confusing with activeSubscriptions being only the subs ids and this being full objects... Maybe something like allSubscriptionsInfo? Or maybe too verbose not sure...

@vegaro
Copy link
Contributor Author

vegaro commented Dec 3, 2024

@tonidero @aboedo @JayShortway made some updates in 0d388c5 (#4508), let me know what you think

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

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

:shipit:

@vegaro vegaro merged commit 658782b into main Dec 4, 2024
7 checks passed
@vegaro vegaro deleted the add-subscription-to-customer-info branch December 4, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:feat A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants