34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
require __DIR__ . '/../session.php';
|
|
require __DIR__ . '/../db.php';
|
|
start_app_session();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$pdo = getDbConnection();
|
|
enforce_session_version($pdo);
|
|
|
|
$userId = $_SESSION['user_id'] ?? null;
|
|
$waitSince = $_SESSION['purchase_wait_since'] ?? null;
|
|
$result = false;
|
|
|
|
if ($userId !== null && $waitSince !== null) {
|
|
$tableExists = $pdo->query("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'transactions'")->fetch();
|
|
|
|
if ($tableExists) {
|
|
// Matches processing.php's session-anchored wait start rather than a sliding
|
|
// "now minus N seconds" window, so this keeps recognizing a completed purchase
|
|
// no matter how long polling has been going on.
|
|
$stmt = $pdo->prepare('
|
|
SELECT 1 FROM transactions
|
|
WHERE user_id = :user_id
|
|
AND created_at >= :wait_since
|
|
LIMIT 1
|
|
');
|
|
$stmt->execute(['user_id' => (int) $userId, 'wait_since' => $waitSince]);
|
|
$result = (bool) $stmt->fetch();
|
|
}
|
|
}
|
|
|
|
echo json_encode(['result' => $result]);
|