I am trying to get latest status for auto renewable subscription. Apple documentation suggests to use latest_receipt_info. After you validate IAP receipt with iTunes, returned JSON has an array called latest_receipt_info. I searched but couldn't find a definite answer. I only have one type of subscription. Which element in this array shows the most recent subscription info? Is it the first, last or should I walk through each element and sort it out by myself? If I had to walk though each element what is the criteria for finding latest most recet susbscription info?
Getting latest receipt information with latest_receipt_info
You appear to have skipped some important details in the purchase and receipt validation process. If your app offers only an auto-renewing subscription In-App Purchase item, then when the updatedTransactions delegate method is called with the SKPaymentTransactionStatePurchased event, grab the appStoreReceiptURL, base64 encode the appStoreReceipt, forward the encoded receipt to your server, which then forwards the encoded receipt contents to the iTunes Store verifyReceipt server. If the status is 0, then review the contents of the “receipt” field. Within the “receipt” field, find the in_app item and search the array for the presence of the auto-renewing subscription identifier. If the auto-renewing subscription identifier is present in the in_app array - the user was charged by the iTunes Store for the auto-renewing subscription item. This also means that there will be a “latest_receipt_info” field along with the “receipt” field.
Of course, the receipt validation process can check directly for the “latest_receipt_info” field. However, if there is no auto-renewing subscription item in the receipt’s in_app array, there won’t be any latest_receipt_info field to scan.
If the latest_receipt_info field is present, then search for an record where the expires_date is greater than the current date AND where there is no cancellation_date set. You should also verify that the auto-renewing subscription identifier matches.
rich kubota - rkubota@apple.com
developer technical support CoreOS/Hardware/MFI
Hi rich,
Thanks for the response. I have already code in place for verifying receipt on my server. As you know latest_receipt_info is an array, and it can contain many transactions. I am asking, which element in this array shows the latest transaction. If the user purchased somehting, canceled/refunded, and purchased again latest_receipt_info will have more than one element. Which element shows the latest status? Is it the first, last or should I walk through each element in the array? If I walk through each element, should I check latest purchase date to find latest receipt. Since documentation doesn't talk about which element in the aray shows the latest transaction. It also doesn't talk about the means of getting latest transaction from this array.
For example once you said
With regards to the ordering of the items in the in_app array, I would make no assumption that the items are in chronological order. I would say the same holds true for the contents of the latest_receipt_info section. A developer made this assumption, and early last year encountered the situation that the second to the last item in the in_app array was the most current auto-renewing subscription item.
I will appreciate if you can tell me how can I get latest transaction info with latest_receipt_info array. Thanks.
A simple option is to use the new "exclude-old-transactions" parameter in the request to validate the receipt. The "latest" transaction is the array entry with the most recent transactionDate property.
For a quick test, you can use the following command in the Terminal.app.
curl -d '{ "exclude-old-transactions": true "password":"yyyy" "receipt-data": "xxxx"}' https://sandbox.itunes.apple.com/verifyReceipt
where
yyyy - is the shared-secret assigned to your account and
xxxx - is the base64 encoded receipt contents.
If you get status 21002 occurs, check the single and double quote characters to verify that your word processor didn't substitute them for the "curly" variety.
One other comment. In the case of an Apple Care refund to a user, the cancellation_date is associated only with the single transaction which was refunded. The user could opt to re-purchase the auto-renewing subscription item later on, which would result in a more recent transaction being present which does not have a cancellation_date field.
rich kubota - rkubota@apple.com
developer technical support CoreOS/Hardware/MFI
I think purchase_date or expiration_date is a better field to use as they are documented to be there.
That should have been expires_date not expiration_date
Here's another question on this topic. What is the format of the "expires_date" field. Some documentation says RFC3339 other documentation says "in a date-time format similar to the ISO 8601." ("similar to" doesn't inspire me with confidence). In my experience its neither RFC3339 or iso8601. I've been using: @"yyyy-MM-dd HH:mm:ss VV" which seems to work "most" of the time. Anybody have any insight into this?