views:

66

answers:

2

I'm trying to verify a sandbox transactionReceipt at https://sandbox.itunes.apple.com/verifyReceipt using php and cURL.

The original receipt when it arrives at my server looks like:

{ "signature" = "AksOP5dmXwg 9WjlcE7PwBEFZgcqBnIb0Uv2lSKebWJJpcOZQRL6ejYyv20MzPFDSgAj3GRGoJXWZpyJLAU8qZSQFYQeGljWKZd3XTJN4j1E7fqOQRBdIXSDRJr1phB/11xp smk6m ... dgcxRHuOMZ2tm8npLUm7argOSzQ=="; "purchase-info" = "ewoJIml0ZW0taWQiID0gIj ... jAiOwp9"; "pod" = "100"; "signing-status" = "0"; }

1. Should it have the equals and semicolons?

Wrapping this up for transmission in the cURL I use:

$receipt = json_encode(array("receipt-data" => base64_encode($transactionReceipt)));

which gives:

{"receipt-data":"ewoJInNpZ25hdHVyZSIgPSAiQ ... <lots more of the same> ... XR1cyIgPSAiMCI7Cn0="} 

This results in: {"status":-42023} from Apple

If I use:

$receipt = json_encode(array("receipt-data" => $transactionReceipt));

which gives:

{"receipt-data":"{\n\t\"signature\" = \"AksOP5dmXwg 9WjlcE7PwBEFZgcqBnIb0Uv2lSKebWJJpcOZQRL6ejYyv20MzPFDSgAj3GRGoJXWZpyJLAU8qZSQFYQeGljWKZd3XTJN4j1E7fqOQRBdIXSDRJr1phB\/11xp smk6m ... dgcxRHuOMZ2tm8npLUm7argOSzQ==\";\n\t\"purchase-info\" = \"ewoJIml0ZW0taWQiID0gIjM3NTgyNzIyOCI7Cgkib3JpZ2luYWwtdHJhbnNhY3Rpb24taWQiID0gIjEwMDAwMDAwMDA1ODQyNDIiOwoJInB1cmNoYXNlLWRhdGUiID0gIj ... jAiOwp9\";\n\t\"pod\" = \"100\";\n\t\"signing-status\" = \"0\";\n}"}

I get: {"status":21002, "exception":"java.lang.IllegalArgumentException: Property list parsing failed while attempting to read unquoted string. No allowable characters were found. At line number: 1, column: 0."}

2. Can anyone please tell me what the receipt-data json is supposed to look like?

Thanks!

A: 

Hi.

I was banging with my head against the walls with the same problem... check this:

$dataToPost = json_encode(array("receipt-data" => $receivedData));

where $receivedData is the receipt base64 encoded.

Then:

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $dataToPost
    )
);

$context  = stream_context_create($opts);
$result = file_get_contents('https://sandbox.itunes.apple.com/verifyReceipt', false, $context);

It worked for me... give it a try and let me know!

Adri
@Adri, Thanks for your reply. Unfortunately, this still gives me a {"status":-42023} response from apple, so perhaps it's the original transaction receipt that is at fault - not the code posting it to Apple.Any chance you could post a value of $receivedData that worked for you, or at least an excerpt? Just to check the format ...
Al
This is an excerpt of a valid receipt: "ewoJInNpZ25hdHVyZSIgPSAiQXE1SW5wa2FoMmpUVmFtVDIyeE44RnNxNFFOaHdr\r\nbFkvWUxNRDBiSi9BRG1...0d0lqc0tmUT09IjsKCSJwb2QiID0gIjEwMCI7Cgkic2lnbmlu\r\nZy1zdGF0dXMiID0gIjAiOwp9"I can send you an email with the complete receipt, if you wish...
Adri
I guess the only difference with my code is that I'm doing the base64 encode on the device and my server side page receives it, encode it to JSON and send's it to Apple
Adri
Hey Adri, That's really helpful. No need to post the full receipt just now. The fact that the \r and \n are preserved is interesting. Hmmmm, i'll try out doing the base64 on the phone and report back!
Al
A: 

Hi Adri,

I'm trying to verify a sandbox transactionReceipt using php , excerpt of your code and CURL. everything reported me same error status {"status":-42023} is this error in the receipt? could you kindly send me valid receipt if possible.

Thanks in advance. sara

sara