There is one thing I don't quite understand when it comes to In-App Subscription purchase.
I obtain the receipt on iOS client like this:
private func loadReceipt() -> Data? {
guard let url = Bundle.main.appStoreReceiptURL else {
return nil
}
do {
let receipt = try Data(contentsOf: url)
return receipt
} catch {
print("Error loading receipt data: \(error.localizedDescription)")
return nil
}
}
And send it for verification to my server (written in Python).
def verify_receipt(self, receipt):
r = requests.post(config.APPLE_STORE_URL, json=receipt)
request_date_ms = DateUtils.generate_ms_from_current_time()
for item in r.json()['latest_receipt_info']:
expires_date_ms = int(item['expires_date_ms'])
if expires_date_ms > request_date_ms:
return True
return False
I get the
expires_date_ms
from latest_receipt_info
, and if it's greater than the current time in milliseconds, then the subscription counts as still valid.1) Would you say this is a solid way of verifying if the subscription is valid?
2) What is the exact purpose of
latest_receipt
here? Is it a copy of the receipt that I just passed in? Could it be newer due to the latest attempt at subscribing? Should I save this one to the database for the current user, and test this receipt from now on going forward to see if the user is still subscribed?Thank you very much for your advice,