Need help with Restoring Subscription with Firebase Integration with Webhooks.

  • 14 August 2023
  • 5 replies

Badge +2

Info: Whole Backend = Firebase.
That includes, Auth system, DB, Functions, Extensions etc.

In the app, I have let's say an account with User 'X' with userId 'xid'. X makes a purchase through the RevenueCat SDK and it sends out webhooks that writes database entries in Firebase with the necessary User details, purchases and entitlements.

I read these entitlements entries in the DB and unlock features within the App. Here in lies the dilemma.

Let's say User 'X' has purchased a monthly subscription. Webhooks and Firebase Integration will give me the DB entries I need to do my unlocking features.

All good so far. Now user 'X' has decided to delete their account having the userId 'xid' from the App. All good so far. Bear in mind that subscription is still active in Playstore/Appstore.

Now user 'X' decides to create a new account again in the App. User 'X' now ends up with a new UserId of 'yid'. User 'X' now presses the 'Restore Purchases' button which calls "Purchases.restorePurchases()" function from the RevenueCat SDK. It works as intended. Subscription has been transffered to the New userId of 'yid'. So far so good!.

Here begins my troubles.

When user 'X' normally made a purchase, a webhook was sent out with all the details which was then processed by RevenueCat's Firebase Extension which added to the Customers Collection with all of User 'X' purchase history. Which I read the entitlements from and unlock features. At this point on the first purchase, the document Id was 'xid'.

But when user 'X' runs the restore functionality, I expected a webhook which would create an entry in Customers Collection with the document Id 'yid'. But no webhook is made on restore. Hence I've no Customer Collection entry with details of the user's purchases and entitlements.

How can I get RevenueCat to hook me up with a webhook with the details so that it processes it normally like it was a fresh purchase? So that I can read the entitlements from the Customers Collection and unlock features after pressing the restore button.

Thank you for your time.


5 replies

Userlevel 4
Badge +6

Hey @MonkeyDrone,

In the scenario you described, when user X restored purchases and they were transferred from ‘xid’ to ‘yid’, a `PURCHASES_TRANSFER` webhook should have been triggered, letting you know the app user id that purchases are being transferred away from and the app user id that purchases are being transferred to. It wouldn’t process this quite like an initial purchase, but should let you know that a transfer occurred successfully and then entitlements can be unlocked for the destination customer. Does that seem to work for your user case?

Badge +2

I can definitely see the transfer events indicating that transfer is taking place from ‘xid’ to ‘yid’.

That event only indicates the transfer.

The initial purchase event creates a whole document in the ‘customers’ collection with the userId such as ‘xid’. The Transfer does no action to create a document ‘yid’ under the ‘customers’ collection.

At this point I am more inclined to just replicate the document inside the ‘customers’ collection from ‘xid’ to ‘yid’.

Was hoping there was a more streamlined built-in solution that would do so automatically.

I’m still going through the process and logic of it all. I may have missed something.

What would be nice is a ‘Transfer_complete’ event which is pretty much similar to initial purchase event.


Badge +2

After some testing I can see that the restore action does create the correct customer collection db entry

the problem I seem to be facing is that there are aliases assigned to the ‘xid’ and ‘yid’. These aliases at times take the role of the primary user Id in the field like mentioned below

app_user_id "$RCAnonymousID:e42baa0e16464ed59a4af380f86a6790"
and the document that gets created is under that anonymousID.
Am I doing something wrong with the initialization of RevenueCat inside flutter?
Badge +2

Well I solved the problem. I had to configure revenuecat such that it only initialized with a user id.

No more anonymous IDs now. Each transfer event is updating the customer collection with the right information.

All works now. Thank you.

Badge +2


can you share how you configure revenueCat? I’m having the same problem