function validate_receipt($receipt_data) {
// $url = "https://sandbox.itunes.apple.com/verifyReceipt/";
$url = "https://buy.itunes.apple.com/verifyReceipt";
$ch = curl_init($url);
$data_string = json_encode(array(
'receipt-data' => $receipt_data,
'password' => 'SHAREDAPPSECRET',
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200 != $httpCode) {
die("Error validating App Store transaction receipt. Response HTTP code $httpCode");
}
$decoded = json_decode($output, TRUE);
return $decoded;
}