Skip to main content
Solved

restorePurchase with information about the last user

  • December 6, 2024
  • 2 replies
  • 49 views

Forum|alt.badge.img

Hi, unfortunately I didn't find the answer to my problem in other questions or in the docs.

My app works like this:

 

  • Users are always logged in and there are no anonymous ids ever, so I always have customIds
  • Each user has  credits and balances in a given period, and it's tracked in a third-party database
  • The subscription gives credits each new period
  • I'm using react-native-purchases, developing from android and ios 

So, to implement a restore purchase in the app, I need to do in two steps:

  1. RevenuCat: call ‘restorePurchases’ and identify the user that had the active subscription
  2. Third-party online database: transfer the credits and balances from the old user to the new user

If I don't do this tranfer, the bussiness logic is broken. I would just need to get the old user ID of revenue cat (transfered from) to do this, but that's where the problem is.

In short
'’’
Revenuecat:
     Purchases.restorePurchases()
     Get old owner id
Third party database:
     Transfer balances from old owner to new owner
‘’’

At first, I though ‘originalAppUserId’ would have this info, but it doesn't seem so. ‘originalAppUserId’ is always the same as the current user, and from what I read in the docs and questions, it seems ‘originalAppUserId’ is used when accounts are merge with anonymous ids, which is not my case. At least in sandbox, they are always equal, and I can't find the original owner.

I haven't been able to find anything else in revenue cat SDK that would let me achieve this, which is a big problem. This is a big blind spot which users are able to break the system and have infinite expenses for me.

I might be able to achieve this in some not recommended ways, such as saving the milliseconds of the purchase in the third-party database and indexing the database through it, so I would able to hopefully find the original owner (and prone to errors): but this way would be a very bad practice. I read it's not possible to retrieve the receipt with the SDK, so one other less possibility of identifying the original owner.

How can I accomplish this with revenue cat? I think this is kinda essencial feature.

I'm trying to solve this with ‘Transfer to new App User ID’, as it would fully meet apple's policy, and the two other options (‘Transfer if there are no active subscriptions’ and ‘Keep with original App User ID’) are more like “couldn't solve it, let's leave it like that”.

Best answer by m-vichos

Hello ​@anto_dev 

Unfortunately, the app_user_id of the previous subscriber is not exposed in the SDK when a transfer happens. However you can get this information from the related webhook event. Check transferred_from and transferred_to fields in TRANSFER event.

Reference here: https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields

View original
Did this post help you find an answer to your question?
This post has been closed for comments

2 replies

Forum|alt.badge.img+1
  • RevenueCat Staff
  • 5 replies
  • Answer
  • December 6, 2024

Hello ​@anto_dev 

Unfortunately, the app_user_id of the previous subscriber is not exposed in the SDK when a transfer happens. However you can get this information from the related webhook event. Check transferred_from and transferred_to fields in TRANSFER event.

Reference here: https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields


Forum|alt.badge.img
  • Author
  • New Member
  • 1 reply
  • December 6, 2024

Thank you, manage to achieve that with firebase functions.


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