Verify receipt for in App purchase

Verify receipt for in App purchase

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Verify receipt for in App purchase

Validating an in-app purchase receipt isn't about checking a database flag; it is a cryptographic verification process that proves a transaction actually occurred on Apple's side without relying on client-side trust. The core problem described in the source material—receiving an "invalid status" despite the rest of the flow working fine—usually stems from one of two specific issues: a mismatched receipt data payload or incorrect signature verification logic.

The standard approach involves fetching the raw receipt string from the iOS device, decoding it into JSON, and then sending that payload to your server for validation. On the PHP side, you must configure curl to communicate securely with Apple's sandbox (https://sandbox.itunes.apple.com/verifyReceipt) or production environment (https://buy.itunes.apple.com/verifyReceipt). Crucially, the request body must be JSON-encoded and signed with a SHA-1 digest of the receipt data.

Here is how the validation payload should look when sent via curl:

$receiptData = $rawReceiptString; // The base64 decoded receipt string from iOS
$payload = json_encode([
    'receipt-data' => $receiptData,
    'sandbox' => true // Set to false for production environment
]);

$digest = hash_hmac('sha1', $payload, config('services.apple.key'));

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://sandbox.itunes.apple.com/verifyReceipt',
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_HTTPHEADER => [
        'Authorization: Apple-Data-SHA1 ' . base64_encode($digest),
        'Content-Type: application/json'
    ]
]);

$response = curl_exec($ch);

A common pitfall is assuming that the receipt string received by your PHP backend is identical to what was sent in the original request. If you are storing the receipt in a database before validation, ensure you are validating against the original receipt data provided in the initial POST request, not a stored version that might have been truncated or altered. The source material mentions forwarding data to the store after passing it through PHP; if you are caching this data locally for later processing, you must guarantee the integrity of that cache.

Another frequent error involves the receipt-field parameter. When validating, Apple expects specific fields depending on the environment. If you are testing in the sandbox, ensure your environment variable or configuration explicitly flags the request as a sandbox call. Using the production endpoint (buy.itunes.apple.com) with a receipt generated in the simulator (sandbox) will invariably return an invalid status because the signatures do not match between environments.

Furthermore, the response from Apple contains a status field. A status of 0 indicates success, while any other integer represents an error code defined in the Receipt Error Codes documentation. Developers often ignore this field and proceed to parse the JSON body even when the HTTP status code is 200 but the receipt-status inside the JSON is non-zero. Always check the status key in the JSON response before attempting to access properties like original_transaction_id.

If your PHP server returns an invalid receipt, double-check that the SHA-1 digest calculation matches exactly what the iOS client provided. The digest must be calculated using the raw payload string passed to curl, not a modified version. Additionally, ensure that your Apple Team ID and Private Key are correctly configured in your Xcode project or keychain access entry, as mismatches here will cause validation failures even if the network request is technically correct.

For production deployments, consider implementing a retry mechanism for transient network errors, but never re-validate a receipt more than once per transaction window to avoid rate limiting issues. If you require third-party payment processing, note that Apple's direct validation method bypasses those intermediaries entirely, so you must handle the is_trial_period and original_purchase_date fields manually based on the verified response.

For those looking for deeper integration patterns or specific billing implementations in PHP ecosystems, resources like LaravelCompany offer useful insights into building robust backend services around these APIs.

Our network