Skip to content

Instantly share code, notes, and snippets.

@eduardo22i
Last active November 13, 2020 04:44
Show Gist options
  • Save eduardo22i/9adc2191f71ea612a7d071342e1e4a6f to your computer and use it in GitHub Desktop.
Save eduardo22i/9adc2191f71ea612a7d071342e1e4a6f to your computer and use it in GitHub Desktop.
A file to validate an AppStore payment receipt using PHP.
<?php
//
// Appstore Production Purchase Validation
//
// Created by Eduardo Irías on 6/3/16.
//
$filebinary = basename($_FILES['receipt-data']['name']);
if (!move_uploaded_file($_FILES['receipt-data']['tmp_name'], $filebinary)) {
$response["message"] = "Payment not verified";
$response["response"] = $_FILES['receipt-data']['name'];
$response["success"] = "0";
echo json_encode($response, JSON_PRETTY_PRINT);
exit;
}
$path = $filebinary;
$receipt = file_get_contents($path);
$json['receipt-data'] = base64_encode($receipt);
$post = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://buy.itunes.apple.com/verifyReceipt");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec ($ch);
curl_close ($ch);
$result = json_decode($result,true);
$response = array();
$response["response"] = $result;
if ($result["status"] == 0) {
$response["message"] = "Payment verified";
$response["success"] = "1";
} else {
$response["message"] = "Payment not verified";
$response["success"] = "0";
}
echo json_encode($response, JSON_PRETTY_PRINT);
?>
@Gameonn
Copy link

Gameonn commented Nov 13, 2020

Hi @eduardo22i,

I am already having the iOS purchase validations working. But the play store purchase validations are still not working. Do you have any idea about that?

Thanks,
Ankit J

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment