Handling Empty in_app Data in iOS Order Verification and Verification Result in receipt.app_item_id

Body:

Hello,

We are currently implementing iOS order verification and have encountered an issue. Some of the receipts we verify return with an empty in_app array, which makes it impossible to determine whether there is a valid in-app purchase.

Below is the code we’re using for verification and the result we receive:

Code Example:

public function iosVerifyReceipt($receipt, $password = '', $sandbox = false)
{
    $url = $sandbox ? 'https://sandbox.itunes.apple.com/verifyReceipt' : 'https://buy.itunes.apple.com/verifyReceipt';

    if (empty($password)) {
        $data = json_encode(['receipt-data' => $receipt]);
    } else {
        $data = json_encode(['receipt-data' => $receipt, 'password' => $password]);
    }

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($result, true);
    $result = $result ?? [];
    $result['sandbox'] = $sandbox;

    if ($result['status'] != 0) {
        Log::warning('ios verify receipt failed', ['receipt' => $receipt, 'result' => $result, 'sandbox' => $sandbox]);
        if ($result['status'] == 21007) {
            return $this->iosVerifyReceipt($receipt, $password, true);
        }
    }

    return $result;
}



// Order validation check 

if (empty($result) || $result['status'] != 0) {
    throw new BadRequestHttpException("Ios Order Verify Error");
}

$appItemId = $result['receipt']['app_item_id'] ?? "";
if ($appItemId != MY_APP_ID) {
    throw new BadRequestHttpException("Ios Order Verify Error");
}

$inApp = array_filter($result['receipt']['in_app'] ?? [], function ($item) use ($transactionId, $order) {
    return $item['transaction_id'] == $transactionId && $item['product_id'] == $order->getProductId();
});

if (empty($inApp)) {
    throw new BadRequestHttpException("Ios Order Verify Error");
}

Array
(
    [receipt] => Array
        (
            [receipt_type] => Production
            [adam_id] => *
            [app_item_id] => *
            [bundle_id] => *
            [application_version] => *
            [download_id] => *
            [version_external_identifier] => *
            [receipt_creation_date] => 2025-02-11 04:06:47 Etc/GMT
            [receipt_creation_date_ms] => *
            [receipt_creation_date_pst] => 2025-02-10 20:06:47 America/Los_Angeles
            [request_date] => 2025-02-11 15:54:56 Etc/GMT
            [request_date_ms] => *
            [request_date_pst] => 2025-02-11 07:54:56 America/Los_Angeles
            [original_purchase_date] => 2025-02-11 04:02:41 Etc/GMT
            [original_purchase_date_ms] => *
            [original_purchase_date_pst] => 2025-02-10 20:02:41 America/Los_Angeles
            [original_application_version] => 5511
            [preorder_date] => 2025-01-17 21:12:28 Etc/GMT
            [preorder_date_ms] => *
            [preorder_date_pst] => 2025-01-17 13:12:28 America/Los_Angeles
            [in_app] => Array
                (
                )

        )

    [environment] => Production
    [status] => 0
    [sandbox] => 
)


Problem Description: • We are noticing that in some orders, the in_app array is returned as empty. This causes difficulty in verifying the presence of in-app purchases. • Our validation logic assumes that if in_app is empty, the order is invalid, but we would like clarification on whether this is correct or if such a scenario is normal under certain conditions.

Actions Taken: • We have reviewed Apple’s documentation and other related resources, but no clear explanation is given about when in_app might be empty. • Can we safely rely on an empty in_app array to consider the order invalid, or should we investigate further for potential issues like delays or errors during the verification process?

We would appreciate your guidance on how to handle such cases. Thank you for your support!

Handling Empty in_app Data in iOS Order Verification and Verification Result in receipt.app_item_id
 
 
Q