$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) { logMessage(LogType::Error, $e->getMessage()); echo '{"error":{"text":"' . $e->getMessage() . '"}}'; }
<?php // ************************************************************************** // // This file implements the endpoint for the "purchase confirmation" API call. // require_once 'header.php'; $base64_receipt = stripcslashes($_POST['receipt_data']); $purchase_type = $_POST['type']; $data = verifyReceipt($base64_receipt); $receipt = $data->receipt; $product_id = $receipt->product_id; $transaction_id = $receipt->transaction_id; $log->LogDebug("Saving {$purchase_type} {$product_id} in the receipt database"); $file_db->query("INSERT OR IGNORE INTO receipts (transaction_id, app_id, user_id, product_id, type, base64_receipt)\n VALUES ('{$transaction_id}', '{$app_id}', '{$user_id}', '{$product_id}', '{$purchase_type}', '{$base64_receipt}')"); if ($purchase_type == 'auto-renewable-subscription') { markIssuesAsPurchased($data, $app_id, $user_id); } else { if ($purchase_type == 'issue') { markIssueAsPurchased($product_id, $app_id, $user_id); } else { if ($purchase_type == 'free-subscription') { // Nothing to do, as the server assumes free subscriptions won't be enabled } } }