curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); $response = curl_exec($ch); $errno = curl_errno($ch); $errmsg = curl_error($ch); curl_close($ch); if ($errno != 0) { throw new Exception($errmsg, $errno); } $data = json_decode($response); if (!is_object($data)) { throw new Exception('Invalid response data'); } if (!isset($data->status) || $data->status != 0) { print 'Status Code: ' . $data->status . '<br/>'; throw new Exception('Invalid receipt'); } return array('quantity' => $data->receipt->quantity, 'product_id' => $data->receipt->product_id, 'transaction_id' => $data->receipt->transaction_id, 'purchase_date' => $data->receipt->purchase_date, 'app_item_id' => $data->receipt->app_item_id, 'bid' => $data->receipt->bid, 'bvrs' => $data->receipt->bvrs); } $receipt = $_GET['receipt']; $isSandbox = (bool) $_GET['sandbox']; try { if (strpos($receipt, '{') !== false) { $receipt = base64_encode($receipt); } $info = validateReceipt($receipt, $isSandbox); echo 'Success'; } catch (Exception $ex) { echo $ex->getMessage() . '<br />'; } ?>
<?php //$devmode = TRUE; // change this to FALSE after testing in sandbox $receiptdata = $_POST['receiptdata']; //$data = isset($_POST['data']) ? json_decode($_POST['data']) : ""; $achat_id = $_POST['achatid']; $username = $_POST['username']; $password = $_POST['password']; //print_r($response); $response = validateReceipt($receiptdata); if ($response->{'status'} == 21007) { $response = validateReceipt($receiptdata, TRUE); } else { if ($response->{'status'} == 21008) { $response = validateReceipt($receiptdata, FALSE); } } if ($response->{'status'} == 0) { //echo ('YES'); require "../UpdateAchatConsumable.php"; } else { //echo ('NO'); echo json_encode(array("resultat" => "false", "data" => $response)); //print_r($response); } function validateReceipt($receiptdata, $devmode = FALSE) { if ($devmode) { $appleURL = "https://sandbox.itunes.apple.com/verifyReceipt"; } else { $appleURL = "https://buy.itunes.apple.com/verifyReceipt";