From 6afdd80bfc0ef4c5effe1008c371e289ca4c792e Mon Sep 17 00:00:00 2001 From: Pauljd Date: Fri, 11 Sep 2026 11:04:36 +0100 Subject: [PATCH] Davidson CI testing & AI refinement --- api/purchase-boolean.php | 14 +++++++++----- processing.php | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/api/purchase-boolean.php b/api/purchase-boolean.php index eda0766..70b4387 100644 --- a/api/purchase-boolean.php +++ b/api/purchase-boolean.php @@ -9,19 +9,23 @@ $pdo = getDbConnection(); enforce_session_version($pdo); $userId = $_SESSION['user_id'] ?? null; +$waitSince = $_SESSION['purchase_wait_since'] ?? null; $result = false; -if ($userId !== null) { +if ($userId !== null && $waitSince !== null) { $tableExists = $pdo->query("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'transactions'")->fetch(); if ($tableExists) { - $stmt = $pdo->prepare(" + // 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 >= datetime('now', '-40 seconds') + AND created_at >= :wait_since LIMIT 1 - "); - $stmt->execute(['user_id' => (int) $userId]); + '); + $stmt->execute(['user_id' => (int) $userId, 'wait_since' => $waitSince]); $result = (bool) $stmt->fetch(); } } diff --git a/processing.php b/processing.php index fa4400f..a5665b4 100644 --- a/processing.php +++ b/processing.php @@ -2,6 +2,15 @@ require __DIR__ . '/session.php'; start_app_session(); +// Anchor completion checks to when this page actually loaded rather than a sliding +// window from "now" at poll time, so a delayed navigation or a browser tab that's +// backgrounded and resumed later still sees credits that were added while it wasn't +// polling. Reset on every fresh load of this page (not on the polling requests below, +// which hit a separate endpoint) so a later, unrelated visit doesn't inherit a stale +// anchor. The 10-second backdate also covers a webhook that finishes just before this +// redirect lands. +$_SESSION['purchase_wait_since'] = gmdate('Y-m-d H:i:s', time() - 10); + $pageTitle = 'Processing'; ?>