I need help with parsing the Apple receipt verification response (sandbox). So user makes the in-app purchase with the iPhone app, and sends me the receipt, which I validate using Apple Services () by PHP. The validation is okay, I get a response, so now I need to pull out a transaction ID so I can store it in the DB, but I don't know which receipt I should pull from the in_app key. There simply isn't a single receipt in there, but an array containing all of the previous receipts also. This response is gotten after a "Consumable" and "Non-Renewing Subscription" was made in the app.
I found a few articles covering this, but EACH were refering to the receipt directly, as it was a single property, which contains all the data, but not here.
Eg. https://github.com/chrismaddern/iOS-Receipt-Validator-PHP looks promising, but in the end he's opening the receipt in this way:
return $decoded_response->receipt;
Doesn't work for my response. I guess this is the old response or something.
This one also https://gist.github.com/jamesstout/5073237.
I'm dealing with this for the first time, any help would be appreciated, please tell me if you need additional information, I'll be glad to point it out.
UPDATE:
Note about items in in_app array, those are the receipts, but not sorted in any way, so for example, original_purchase_date_pst is for the first 4 items:
[0] 2015-01-12 10:33:13 Etc/GMT
[1] 2015-01-12 11:35:53 Etc/GMT
[2] 2015-01-12 11:12:36 Etc/GMT
[3] 2015-01-12 11:15:57 Etc/GMT
I mean I could iterate through the whole array, but it seems a bit weird that there isn't an easier way to fetch the latest receipt. And can I be sure that there will be the latest receipt in the list ? I'll need to fetch the transaction ID from it so I must be sure!
Thanks!