Skip to content

Instantly share code, notes, and snippets.

@paulw11
Last active June 29, 2022 06:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulw11/fa76e10f785e055338ce06673787c6d2 to your computer and use it in GitHub Desktop.
Save paulw11/fa76e10f785e055338ce06673787c6d2 to your computer and use it in GitHub Desktop.
iOS Receipt validator
if let receiptURL = NSBundle.mainBundle().appStoreReceiptURL {
print("Fetching local receipt")
if let receipt = NSData(contentsOfURL: receiptURL) {
print("fetched")
let b64 = receipt.base64EncodedStringWithOptions([]).stringByReplacingOccurrencesOfString("+", withString: "%2B")
self.validateReceipt(b64)
} else {
print("Could not retrieve app store receipt")
}
} else {
print("No receipt URL")
}
<?php
require __DIR__ . '/vendor/autoload.php';
$receipt = $_POST['receipt'];
$sandbox = $_GET['sandbox'] == "true";
$result = verify_app_store_in_app($receipt, $sandbox);
echo $result;
function verify_app_store_in_app($receipt, $is_sandbox)
{
//$sandbox should be TRUE if you want to test against itunes sandbox servers
if ($is_sandbox)
$verify_host = "https://sandbox.itunes.apple.com/verifyReceipt";
else
$verify_host = "https://buy.itunes.apple.com/verifyReceipt";
$json='{"receipt-data" : "'.$receipt.'","password" : "<<iTunes Shared Secret here>>" }';
//opening socket to itunes
$response = \Httpful\Request::post($verify_host) // Build a PUT request...
->sendsJson() // tell it we're sending (Content-Type) JSON...
->body($json) // attach a body/payload...
->send();
return $response;
}
@jbarros35
Copy link

["status": 21002]

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