Question

I am testing in app purchase with MKStoreKit.

I'm getting response's status 21002 and wonder why.
Do I need to set up a certificate or something to talk to apple server?

Below is the php code that MKStoreKit uses

<?php

$devmode = TRUE; // change this to FALSE after testing in sandbox                                                                                                                                                                                                             

$receiptdata = $_POST['receiptdata'];
$udid = $_POST['udid'];

if($devmode)
 {
     $appleURL = "https://sandbox.itunes.apple.com/verifyReceipt";
 }   
 else
 {
     $appleURL = "https://buy.itunes.apple.com/verifyReceipt";
 }

$receipt = json_encode(array("receipt-data" => $receiptdata));
$response_json = do_post_request($appleURL, $receipt);
$response = json_decode($response_json);

file_put_contents('php://stderr', print_r($response->{'status'}, true));
file_put_contents('php://stderr', print_r($udid, true));

if($response->{'status'} == 0)
 {
     file_put_contents('php://stderr', print_r("yes", true));
     error_log('udid: %s', $udid);
     error_log('quantity: %d', $response->{'receipt'}->quantity);
     echo ('YES');
 }   
 else
 {
     echo ('NO');
 }

function do_post_request($url, $data, $optional_headers = null)
{
    $params = array('http' => array(
            'method' => 'POST',
            'content' => $data
                                    ));
    if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    if (!$fp) {
        throw new Exception("Problem with $url, $php_errormsg");
    }
    $response = @stream_get_contents($fp);
    if ($response === false) {
        throw new Exception("Problem reading data from $url, $php_errormsg");
    }
    return $response;
}

?>
Was it helpful?

Solution 2

MKStore Kit has a bug with sending receiptdata to server

You should base64 encode receiptData not asciiStringEncoding.

Used the following link's code to base64 and I get status 0. Verify receipt for in App purchase

OTHER TIPS

Please check Verify Purchase

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top