PHP code example of sn01615 / i-os-receipt-validator-php

1. Go to this page and download the library: Download sn01615/i-os-receipt-validator-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sn01615 / i-os-receipt-validator-php example snippets


$data = new \stdClass();
$data->receipt = $_POST['receipt-data'];
$data->sandbox = $_POST['sandbox'];

$endpoint = $data->sandbox ? \itunesReceiptValidator::SANDBOX_URL : \itunesReceiptValidator::PRODUCTION_URL;

try {
    $rv = new \itunesReceiptValidator($endpoint, $data->receipt);

    $data->environment = ($rv->getEndpoint() === \itunesReceiptValidator::SANDBOX_URL) ? 'Sandbox' : 'Production';

    $data->info = $rv->validateReceipt();
    # TODO 业务逻辑处理

    $data->result = 'Success';
} catch (\Exception $ex) {
    $data->result = 'Fail';
}

print_r($data);