Esempio n. 1
0
         $stmt->bindParam("product_id", $iTunesReceiptInfo->receipt->product_id);
         $stmt->bindParam("type", $type);
         $stmt->bindParam("transaction_id", $iTunesReceiptInfo->receipt->transaction_id);
         $stmt->bindParam("user_id", $user_id);
         $stmt->bindParam("purchase_date", $iTunesReceiptInfo->receipt->purchase_date);
         $stmt->bindParam("original_transaction_id", $iTunesReceiptInfo->receipt->original_transaction_id);
         $stmt->bindParam("original_purchase_date", $iTunesReceiptInfo->receipt->original_purchase_date);
         $stmt->bindParam("app_item_id", $iTunesReceiptInfo->receipt->item_id);
         $stmt->bindParam("version_external_identifier", $iTunesReceiptInfo->receipt->version_external_identifier);
         $stmt->bindParam("bid", $iTunesReceiptInfo->receipt->bid);
         $stmt->bindParam("bvrs", $iTunesReceiptInfo->receipt->bvrs);
         $stmt->bindParam("base64_receipt", $receiptdata);
         $stmt->execute();
         // If successful, record the user's purchase
         if ($type == 'auto-renewable-subscription') {
             markIssuesAsPurchased($iTunesReceiptInfo, $app_id, $user_id);
         } else {
             if ($type == 'issue') {
                 markIssueAsPurchased($iTunesReceiptInfo->receipt->product_id, $app_id, $user_id);
             } else {
                 if ($type == 'free-subscription') {
                     // Nothing to do, as the server assumes free subscriptions don't need to be handled in this way
                 }
             }
         }
         logAnalyticMetric(AnalyticType::ApiInteraction, 1, NULL, $app_id, $user_id);
     } catch (PDOException $e) {
         logMessage(LogType::Error, $e->getMessage());
         echo '{"error":{"text":"' . $e->getMessage() . '"}}';
     }
 } catch (Exception $e) {
<?php

// **************************************************************************
//
// This file implements the endpoint for the "purchases" API call.
//
require_once 'header.php';
$app_id = $_GET['app_id'];
$user_id = $_GET['user_id'];
// Retrieve latest receipts
$result = $file_db->query("SELECT base64_receipt FROM receipts\n    WHERE app_id='{$app_id}' AND user_id='{$user_id}' AND type='auto-renewable-subscription'\n    ORDER BY transaction_id DESC LIMIT 0, 1");
$base64_latest_receipt = $result->fetchColumn();
if ($base64_latest_receipt) {
    $data = verifyReceipt($base64_latest_receipt);
    markIssuesAsPurchased($data, $app_id, $user_id);
    $subscribed = $data->status == 0;
} else {
    $subscribed = false;
}
$result = $file_db->query("SELECT product_id FROM purchased_issues\n    WHERE app_id='{$app_id}' AND user_id='{$user_id}'");
$purchased_product_ids = $result->fetchAll(PDO::FETCH_COLUMN);
echo json_encode(array('issues' => $purchased_product_ids, 'subscribed' => $subscribed));