IllegalStateException when using Curl to check app store receipt?

I have an in-app purchase for which I want to check the receipt of the store. I would like to test this on a random machine on the Internet using the itunes API. The receipt is stored in Parse after the transaction is completed. I follow 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 is as follows:

 { "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" } 

Then I take the base64 value inside the Receipt transaction and twist it with the Apple endpoint to get a 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 that I get is not very useful:

 {"status":21002, "exception":"java.lang.IllegalStateException"} 

which, it seems to me, corresponds to "Data in the receipt property was distorted." Getting curl to flush the whole operation with -trace-ascii didn’t show anything that I thought was relevant, I'm sure the problem is not with the connection itself.

A little exaggerated. It looks like the transaction was found from the end (setting multiple bytes in the receipt data raises java.lang.IllegalArgumentException), so I assume that it is somehow related to the transaction itself. Has anyone seen this before?

Thanks!

+6
source share
1 answer

I landed here after searching for the same error message. In the end, I decided - the best advice I can give is to check that the receipt is valid and that you are sending it to the correct URL. I got your exact error when I used an invalid receipt (or maybe just the wrong kind - this is an admission receipt, not an in-app purchase receipt) and a similar error when using a valid check note, a production one. '

I initially used the example receipt data from http://images.worldofapple.com/validating_051110.pdf after uudecoding and transcoded it as base64. I tried to send:

Both gave the same error {"status":21002, "exception":"java.lang.IllegalStateException"} . I now suspect that the main reason is that this is an application receipt, not an in-app purchase receipt.

Then I got another example from https://gist.github.com/sauloarruda/2559455

At https://buy.itunes.apple.com/verifyReceipt I got the same useless answer: {"status":21007}

Finally, https://sandbox.itunes.apple.com/verifyReceipt I got the expected answer:

{ "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}

+1
source

Source: https://habr.com/ru/post/925076/


All Articles