I am implementing Auto Renewing subscriptions in my App. I am able to complete all the Purchases and Restorations perfectly. But i am kind of struck on what would be best ways to save the receipt details. Below are my questions.
I am aware of some approaches. But want to know the best approaches. Please guide me the best steps to achieve the above objectives. Thank you.
I'll try to answer your questions but you would probably be benefited from watching the WWDC StoreKit videos, 1 and 2.
I would store purchase state in the same place you are storing all other client side state.
I would not save the whole receipt. This would be overkill, just extract the information you need and save it. The receipt is always accessible from the Bundle.appStoreReceiptURL
so you don't need to store it.
For subscriptions, you need to verify the receipt with Apple's verifyReceipt
endpoint, and find the latest expires_date
for the given IAP product identifier. Store this date (in defaults or elsewhere) and use that to compute the user's status.
The proper way to get the latest expiration is to send the receipt to your own server, store it, and periodically check it against the verifyReceipt
endpoint and update the expiration from the latest_receipt_info
field in the response. A less good solution is to make sure you always have an SKPaymentQueue
observer setup in your app, because when a recurring subscriptions renews a new transaction will appear on the queue. If you process this, read the new receipt data, and finish the transaction, you don't need a whole backend, however, without verifying the receipt independently from your backend, it will be vulnerable to IAP crackers.
When you send a receipt to /verifyReceipt
you will receive a JSON response that contains a key latest_receipt_info
that will have the most recent transactions. This will be true no matter how old the receipt is.
IAP and especially subscriptions is not a simple system so I highly recommend taking the time to watch the WWDC videos and to read Apple's guides on StoreKit.