tikhop / TPInAppReceipt

Reading and Validating In App Purchase Receipt Locally.
MIT License
631 stars 93 forks source link

Does this work getting receipts for a full paid app purchase? Not an in-app purchase, a purchase of the actual app? #112

Closed mobile-appz closed 11 months ago

mobile-appz commented 11 months ago

Hi I'm converting a paid app to a subscription app (which will be released as an update not as a new app) and need to verify which users have previously paid for the app. Can this library do this? There is nothing to say so in the documentation as far as I can see? Also, how can this be tested if so before release?

tikhop commented 11 months ago

Hi @mobile-appz, thanks for bringing this up. Unfortunately, the library doesn't provide a single method for such a case. Nevertheless, you can still achieve this using this library. To determine whether a user has previously purchased an app or not, you simply need to read the local receipt and retrieve the original app version. If the version is lower than the latest one (with a subscription), then it means the user has purchased the app before:

do {
  let receipt = try InAppReceipt.localReceipt() 
  let originalAppVersion = receipt.originalAppVersion

  let currentVersion = ...

  if originalAppVersion < currentVersion {
    // User paid for the app 
  }
} catch {
  print(error)
}
mobile-appz commented 11 months ago

Thank you very much, that's good news and extremely helpful.