Last active
June 29, 2022 06:16
-
-
Save paulw11/fa76e10f785e055338ce06673787c6d2 to your computer and use it in GitHub Desktop.
iOS Receipt validator
This file contains hidden or 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
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") | |
} |
This file contains hidden or 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 | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
["status": 21002]