I have an in-app purchase for which I want to verify the store receipt. I'd like to verify this from a random machine on the Internet by using Apple's itunes API. The receipt is stored in Parse after the transaction is completed. I'm following the guide on the Apple developer website. First I get the transaction from Parse:
curl -X GET \
-H "X-Parse-Application-Id: [...]" \
-H "X-Parse-REST-API-Key: [...]" \
https://api.parse.com/1/classes/Transactions/123456789
which looks like:
{
"transactionReceipt":{"__type":"Bytes","base64":"asdfqwertyASDFQWERTY="},
"transactionType":"Purchased",
"transactionIdentifier":"[...]",
"transactionDate":{"__type":"Date","iso":"2012-09-10T06:58:44.071Z"},
"createdAt":"2012-09-10T06:58:37.234Z",
"updatedAt":"2012-09-10T06:58:37.234Z",
"objectId":"HyPWJBlWzt"
}
I then take the base64 value inside transactionReceipt and curl it against the Apple endpoint to get the receipt:
curl -H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST
-d '{"receipt-data":"asdfqwertyASDFQWERTY="}' \
https://buy.itunes.apple.com/verifyReceipt
And all I get back is a not tremendously helpful:
{"status":21002, "exception":"java.lang.IllegalStateException"}
which I believe corresponds to a "The data in the receipt-data property was malformed.". Getting curl to dump the entire operation with --trace-ascii didn't reveal anything I thought was relevant, I'm sure the issue is not with the connection itself.
Slightly stumped here. It does look like the transaction was found on their end (tweaking a few bytes in the receipt-data throws a java.lang.IllegalArgumentException), so I'm guessing it's got something to do with the transaction itself. Has anybody seen this before?
Thanks!
I landed here after searching for the same error message. I eventually solved it - the best advice I can give is to double-check that the receipt is valid and that you're posting it to the correct URL. I got your exact error when I was using an invalid receipt (or perhaps just the wrong kind - it was an app receipt, not an in-app-purchase receipt), and a similar error when using a valid sandbox receipt posted to the 'production' verification url.
I was originally using the example receipt data from http://images.worldofapple.com/validating_051110.pdf, after uudecoding it and reencoding it as base64 . I tried posting to:
Both gave the same error {"status":21002, "exception":"java.lang.IllegalStateException"}
. I now suspect the root cause is that this is an app receipt, not an in-app purchase receipt.
I then got another example receipt from https://gist.github.com/sauloarruda/2559455
At https://buy.itunes.apple.com/verifyReceipt I got a similarly useless response:
{"status":21007}
Finally at https://sandbox.itunes.apple.com/verifyReceipt I got the expected response:
{
"receipt":{"original_purchase_date_pst":"2012-04-30 08:05:55 America/Los_Angeles", "original_transaction_id":"1000000046178817", "original_purchase_date_ms":"1335798355868", "transaction_id":"1000000046178817", "quantity":"1", "product_id":"com.mindmobapp.download", "bvrs":"20120427", "purchase_date_ms":"1335798355868", "purchase_date":"2012-04-30 15:05:55 Etc/GMT", "original_purchase_date":"2012-04-30 15:05:55 Etc/GMT", "purchase_date_pst":"2012-04-30 08:05:55 America/Los_Angeles", "bid":"com.mindmobapp.MindMob", "item_id":"521129812"}, "status":0}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With