Question

Restore Purchase programatically?

  • 11 January 2023
  • 2 replies
  • 27 views

Badge

Hello,

I have a question about restoring purchases. I have an app using anonymous user ids. App starts with an intro slider, the last slider page is a pre-paywall view where the user can choose to either restore purchase or goto subscriptions ( hence the paywall). Restore purchase works as intended if the user has an ongoing subscription.  I also saw that if a user with an ongoing subscription by misstake continued to the paywall view and tried to buy another subscription this was detected by the call to Purchases.shared.purchase… and a relevant alert in Swedish was presented, perfect!

But my question is there a way to programatically check if a user is eligible to restore a purchase when the user has made a new installation of the app? Then I could disable the goto subscription button on the pre-paywall view.

 

Best Regards, Tomas


2 replies

Userlevel 1
Badge +3

Hey @Tomas M ,

In order to programmatically check if a user is eligible to restore a purchase, you’d have to inspect their receipt, which can get complicated. We’re actually working on a library that can load and parse the iOS receipt (keep an eye on our repo: https://github.com/RevenueCat/purchases-ios), then what would do is see if the receipt has purchases and if yes, compare with purchases from getCustomerInfo and restore purchases if they differ. But, this is quite a lot of work and still pretty error prone - for example, if the receipt isn’t up to date, getCustomerInfo is cached, etc. 

 

All this to say, it’s best just to allow the user to restore purchases manually and if you’re allowing that, it’s probably not worth it to go through all of that work. But - if you think it will improve your user experience, it’s definitely possible!

Badge

Hi Kaitlin,

Thank you for your answer.  It seems rather complicated, so I think I continue to use manual restore functionality. 
 

Regards Tomas

 

Reply