Generate JSON object with transactionReceipt Generate JSON object with transactionReceipt json json

Generate JSON object with transactionReceipt


I have just fixed that after 2 days of struggling. You have to encode receipt using Base64 before inserting into json object. Like that (Ruby):

dataForVerification = {"receipt-data" => Base64.encode64(receipt)}.to_json

Base64 is not mentioned anywhere in the official docs (at least for SDK 3.0), only on a couple of blogs.

For instance, here the guy encodes the receipt in Base64 before passing it to the PHP server, but does not decode it back in PHP, thus sending Base64-encoded string to iTunes.


Re: "21002: java.lang.IllegalArgumentException: propertyListFromString parsed an object, but there's still more text in the string.:"

I fixed a similar issue in my code by wrapping the receipt data in {} before encoding.

The resulting receipt looks like:

{    "signature" = "A[...]OSzQ==";    "purchase-info" = "ew[...]fQ==";    "pod" = "100";    "signing-status" = "0";}

Here's the code I use:

receipt = "{%s}" % receipt    // This step was not specified - trial and errorencoded = base64.b64encode(receipt)fullpost = '{ "receipt-data" : "%s" }' % encodedreq = urllib2.Request(url, fullpost)response = urllib2.urlopen(req)

Apple's Response:

{"receipt":{"item_id":"371235", "original_transaction_id":"1012307", "bvrs":"1.0", "product_id":"com.foo.cup", "purchase_date":"2010-05-25 21:05:36 Etc/GMT", "quantity":"1", "bid":"com.foo.messenger", "original_purchase_date":"2010-05-25 21:05:36 Etc/GMT", "transaction_id":"11237"}, "status":0}

Good luck!