Skip to main content
Question

Stable ID for Current Subscription

  • December 6, 2024
  • 3 replies
  • 71 views

Forum|alt.badge.img+4
  • Helper
  • 4 replies

How can I get a stable ID for the ‘current subscription’ using the iOS SDK?

What I’m looking to do is to give users some amount of in-app credit to use every month they are subscribed, with that clock starting immediately when they subscribe to either a monthly or yearly plan. So I need some sort of bucketing system to track the usage for the current month number, and therefore I need a stable key to use.

Here’s what I had in mind: <current subscription id> + <current month index>.

The month index would simply be derived by comparing the current time to the subscription’s original start time. When the index rolls over, they are using a fresh new bucket of credit. (I could probably live with slight drift over time of the point in the month at which the index turns over relative to the renewal time, after say a delay due to a billing retry and grace period).

But what does RevenueCat provide that I could use for a subscription ID? I would need it to change after upgrade or downgrade, because the amount of credit I want to give would be different. And I would want it to change after a period of non-subscription so that the credit tracking resets when the user re-subscribes later.

Am I missing something in the SDK that can serve this role?

This post has been closed for comments

3 replies

Forum|alt.badge.img+4
  • Author
  • Helper
  • 4 replies
  • December 6, 2024

I see that there is a property `EntitlementInfo.latestPurchaseDate` — this means that an entitlement ‘knows’ which transaction is the cause of its currently being granted, if in fact it is active.

I guess what would do the job is another property `EntitlementInfo.latestTransactionId` which would expose the underlying StoreKit transaction ID. I could use this as a key unique to the current continuous subscription period for a given entitlement.

Is there any workaround to get this transaction ID with the current SDK? Any ideas about promotional entitlements (which presumably don’t have any underlying StoreKit events or objects)?


Ryan Glanz
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 383 replies
  • December 12, 2024

Could you use the activeSubscriptions property on the CustomerInfo object for this?

https://revenuecat.github.io/purchases-ios-docs/5.6.0/documentation/revenuecat/customerinfo/activesubscriptions


Forum|alt.badge.img+4
  • Author
  • Helper
  • 4 replies
  • December 18, 2024
Ryan Glanz wrote:

Could you use the activeSubscriptions property on the CustomerInfo object for this?

Thanks Ryan. I’m not really seeing how this would help? Are you suggesting that I loop over the active subscriptions and choose one based on the active entitlements and some business logic, after which I can use the original transaction ID from that subscription as the stable ID?

I guess to clarify what I’m really after: a stable ID for the current continuous period of entitlement, which changes after a break in access to that entitlement, or when another entitlement (which my business logic says represents a higher or lower level of service) becomes active.

It seems like this conceptually possible because the entitlements carries an original purchase date and a product identifier, so your backend clearly knows which purchase caused the entitlement to become active and there is ultimately a transaction ID for that purchase.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings