Solved

Subscription expiration WebHook


Badge

Hello!

I’m implementing RevenueCat in my application in order to handle user’s subscriptions.

 

I have my own database and I want to set both “premiumLevel” and “expirationDate” (so I can use the benefits of Firestore sockets). I have a few questions:

  1. When a INITIAL_PURCHASE event is triggered, I am fetching the newest data in the subscribers endpoint and then getting the user’s id of my own database via aliases. Is that approach correct?
  2. When a EXPIRATION event is triggered, I am just updating my own database and setting premiumLevel to false and expirationDate to null (no request to subscribers), is that okay?
  3. Do I need to look up for other event types or the INITIAL_PURCHASE and EXPIRATION are enough to keep my database updated?
icon

Best answer by Jens 10 June 2022, 09:13

View original

2 replies

Userlevel 4
Badge +6

I have my own database and I want to set both “premiumLevel” and “expirationDate” (so I can use the benefits of Firestore sockets)

If you are using Firebase / Firestore, you might want to check out our Firebase Extension which takes care of handling webhooks and updating subscriber status for you.

When a INITIAL_PURCHASE event is triggered, I am fetching the newest data in the subscribers endpoint and then getting the user’s id of my own database via aliases. Is that approach correct?

I am not sure what you mean by “via aliases”. In general, if you have your own user ID, it’s best to use that as the RevenueCat app user ID (via logIn()), then you don’t have to do any mapping. In general, the approach sounds correct, though.

When a EXPIRATION event is triggered, I am just updating my own database and setting premiumLevel to false and expirationDate to null (no request to subscribers), is that okay?

Yes, that’s precisely the idea behind the EXPIRATION event.

Do I need to look up for other event types or the INITIAL_PURCHASE and EXPIRATION are enough to keep my database updated?

In addition, you should listen to the RENEWAL event as well. If a user subscribes, then cancels and later re-subscribes after their subscription has expired, you will get a RENEWAL event (after an EXPIRATION event when their initial subscription expires).

Badge

I have my own database and I want to set both “premiumLevel” and “expirationDate” (so I can use the benefits of Firestore sockets)

If you are using Firebase / Firestore, you might want to check out our Firebase Extension which takes care of handling webhooks and updating subscriber status for you.

When a INITIAL_PURCHASE event is triggered, I am fetching the newest data in the subscribers endpoint and then getting the user’s id of my own database via aliases. Is that approach correct?

I am not sure what you mean by “via aliases”. In general, if you have your own user ID, it’s best to use that as the RevenueCat app user ID (via logIn()), then you don’t have to do any mapping. In general, the approach sounds correct, though.

When a EXPIRATION event is triggered, I am just updating my own database and setting premiumLevel to false and expirationDate to null (no request to subscribers), is that okay?

Yes, that’s precisely the idea behind the EXPIRATION event.

Do I need to look up for other event types or the INITIAL_PURCHASE and EXPIRATION are enough to keep my database updated?

In addition, you should listen to the RENEWAL event as well. If a user subscribes, then cancels and later re-subscribes after their subscription has expired, you will get a RENEWAL event (after an EXPIRATION event when their initial subscription expires).

Hi Jens.

Thank you for your clarifying response.

Reply