iosswiftin-app-purchaseicloud

Check to see if user actually payed for in-app purchase [iOS, Swift]


Here is a strange one for you :)

I have an iOS app that has a non-consumable product as a in-app purchase that the users could buy. It's kind of a lifetime subscription if you'd like.

The thing is that i had a bug in my code which allowed users to "subscribe" to my app by tapping on Restore Purchases button.

I fixed the bug now but i have a problem. Roughly 50 users are now subscribed but never payed for this service.

Is there a way to see if the user actually payed for this somehow? I would like to unsubscribe them if they did not pay.

The system works this way:

The user taps on Purchase, Apple takes care of the purchase for me and when processing the payment queue, if the purchase was a success i subscribe the user by adding their iCloud ID to my database. So the only piece of data that i have is their iCloud id and nothing else. I don't know which iCloud ID is a "payed" one and which is "cheating" :)


Solution

  • You can obtain the receipt from the user's device and check with Apple's endpoint to see if the user has a valid purchase. Ideally you should take the receipt from the app and send it to your server to perform the verification in your backend.

    Check this documentation to obtain receipt from the device - https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store

    Check this documentation to call verify the receipt with Apple's endpoint - https://developer.apple.com/documentation/appstorereceipts/verifyreceipt