Solved

Determine all uses added or removed from an entitlement / subscription in the past week.

  • 17 January 2022
  • 3 replies
  • 77 views

Badge +1

Hello!

 

I’m currently implementing a job for application that has 2 use cases.

  1. Determine all users who have been ADDED to an entitlement this week
  2. Determine all users who have been REMOVED from an entitlement this week

The entitlement in question is a monthly subscription to one of our premium features, and I have to manually make a report of all users who were added / removed from this subscription / entitlement, so we can manually turn on/off this premium feature for them.

(But NOT a user who successfully renewed their subscription this cycle and therefore isn’t added or removed, just continuing their subscription)

 

We store a lot of information from revenue cat: 

My first stab at attempting to do this is looking at all the webhook events a user has received in the past week. And seeing if they have an: initial_purchase, expiration, renewal, cancelation, un-cancelation, ect. and determining if they have been added/removed from those events.

 

This approach is becoming more complicated than I anticipated, there are a lot of edge cases to manage:

  • Cancelation / un-cancelation 
    •  does this mean their subscription is good until the end of the billing cycle? Ect.
  • Renewal 
    • Does this mean they are just continuing their subscription from last month, or did they resubscribe after a cancelation? ect.
  • Ect. Ect.

 

I was wondering if anyone has seen this type of use case before and how the best approach to implementing this?

 

I’m starting to think that using the information from our subscription or entitlement tables will be more manageable? Maybe use the expires_date on the subscription or entitlement to determine if the user has lapsed on their entitlements?

 

Happy to provide more info or details if needed about this - Thanks in advance!

 

 

icon

Best answer by ryan 24 January 2022, 22:07

View original

3 replies

Userlevel 5
Badge +9

Hey @Gabe!

For starters, I always recommend apps first try to use the subscription status from the RevenueCat SDK to manage entitlement access which saves you from having to worry about any of this. That said, there are some valid use-cases that require the subscription status be checked from your server instead of the SDK.

So the first thing I would do is ask yourself if it’s possible to use the subscription status from the SDK instead of your server?

The entitlement in question is a monthly subscription to one of our premium features, and I have to manually make a report of all users who were added / removed from this subscription / entitlement, so we can manually turn on/off this premium feature for them.

 

The simplest approach here could be to generate a Customer List of all the active, and expired customers. You could run this whenever you need your report.

If you need a little more automation than that, the next tool I would look at our ETL exports. These would get delivered daily and you could write a SQL query to get Active and Expired customers over any time period.

The third approach would be to sync subscription status in real-time with your server, so you could query your database whenever you need to to get active/expired subs. This is the most involved approach, and usually starts with listening to webhook events and updating the expiration_date of each customer as new webhooks come through. Use expiration_date here instead of trying to make “subscription statuses”, you can then derive statuses based off of the expiration date (e.g. Active == expiration > now()).

Badge +1

Thanks for detailed response Ryan. 

 

Still need to test our implementation but I did more or less exactly as you said in your third approach. 

  • We refresh the statues of users as webhooks come in, ensuring its up to date.
  • Check if the users entitlement is active or expired (expiration > now()) 
  • Check the list of active users who we haven’t manually enabled
  • Check the list of expired users who we haven’t manually disabled
  • ????
  • Profit

 

Userlevel 5
Badge +9

I have an outline for a blog post I want to write to get into the nitty gritty of keeping your database in-sync via webhooks, but the high level approach I like to use is:

  1. Create a sync function on your server that calls the GET /subscriber endpoint to pull the entitlements + expiration_date for the customer.

  2. Any webhook event from RevenueCat, sync()

I like this approach because it simplifies your code from having to handle each webhook payload differently, and makes it easy to add fallbacks and redundancy (e.g. you can go back and re-sync if something ever falls over).

Reply