I am looking to status poll in order to see the subscription (auto-renewing) status of my users at any point in time. The process is simple: if you have the receipt data string for a user, you can send it to Apple (serverside) and they will return a decrypted JSON of the receipt. Here is my code to acquire the receipt data upon purchase of an auto-renewing subscription:
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
do {
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
print(receiptData)
//Encrypted receipt data
let receiptString = receiptData.base64EncodedString(options: [])
} }
As I test with the sandbox user buying different subscriptions in my app over and over again, I see that the receipt data string changes but it is unclear whether old strings yield up-to-date transaction history when given to Apple's server.
Consider the following: If a subscribed user cancels their subscription while not on the app, gets a new phone, and then downloads my app, to determine their subscription status is it right to use the receipt data string from their first purchase on their old phone to determine their current subscription status?
My question: Do I need to continuously update the value of a user's receipt data string in my database in order to view their subscription status months later? How about on a different device?
Best way to get the status update of subscription is to store all receipts in the database and backend services should connect with apple server to get latest updates.
Any action for subscription(cancel, extend, downgrade, upgrade) should be done from backend. Below are the benefits for that
In sandbox, it let you buy subscriptions frequently because recurring and cancel subscription process in minutes/hours based on duration you have selected in "In app purchase".
Initial meta data in the receipts does not change until customer cancel the subscription recurring. So you can save and use that receipt for further updates.