Solved

When should I call syncPurchases?

  • 25 January 2023
  • 5 replies
  • 660 views

Badge +4

“This method will send all the purchases to the RevenueCat backend. Call this when using your own implementation for subscriptions anytime a sync is needed, like after a successful purchase.”

Source: https://sdk.revenuecat.com/android/5.0.0/purchases/com.revenuecat.purchases/-purchases/sync-purchases.html

If I understand correctly syncPurchases:
1. upload the local device’s receipt to RevenueCat
2. Transaction might under another app user id, so if needed transfer going to happen.
3. The user access all entitlement based on the device’s receipt

Is it correct? 
If yes, I don’t understand why need to call “like after a successful purchase.”.

I assume purchaseProduct make a full sync with RevenueCat backend after the purchase, because the app should send the current receipt to the RC server, so why needed syncPurchases?

icon

Best answer by Haley Pace 28 January 2023, 00:57

View original

5 replies

Userlevel 4
Badge +8

Yes, you are correct in your understanding of the method. Sorry for the confusion, that documentation is outdated, we will be updating it soon with the correct information. 

The use case of this method would instead be to trigger a sync once per subscriber programmatically the first time they open a version of your app containing RevenueCat. You should not call this programmatically on every app launch for every user. This can increase latency in your app and can unintentionally alias users together.

Userlevel 1
Badge +6

@Haley Pace , would it be correct to call Purchases.syncPurchases() after calling Purchases.login(userId)?

I have tried solving some entitlements syncronization issues with this logic, but now I wonder if this is correct or if it could potentially led my app to “ unintentionally alias users together”, like you commented above.

Userlevel 4
Badge +8

You can call this, but there is the potential for unwanted aliasing if you call syncPurchases() while that user is logged into an app store account used by a different user.

 

My recommendation would be to have a restore purchases button that the user can press if they are missing access to their purchases. Please see our post here for the benefits of having such a button: 

 

Userlevel 1
Badge +6

You can call this, but there is the potential for unwanted aliasing if you call syncPurchases() while that user is logged into an app store account used by a different user.

@Haley Pace  What do you mean by "while that user is logged into an app store account used by a different user"? Why and how would a user be logged into an app store account which is not his own?

Userlevel 4
Badge +8

By this I mean that some users may have multiple app store accounts of their own, or they could be using a device that is shared with other people so the app store account could change. 

Reply