Last active
November 13, 2020 04:44
-
-
Save eduardo22i/9adc2191f71ea612a7d071342e1e4a6f to your computer and use it in GitHub Desktop.
A file to validate an AppStore payment receipt using PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
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
Hi @eduardo221,
I know you wrote this 3 years ago (thanks), do you think it's still a valid example for today? I just need a simple php receipt verification script.
Also, if I just change the https://buy.itunes.apple.com/verifyReceipt to https://sandbxox.itunes.apple.com/verifyReceipt it should work for sandbox, right?
Thanks,
Adrian