Fixdd additonal issues identified by Davidson CI
pauljd/davidson-ci: Davidson CI / quality (push) Successful in 15s
pauljd/davidson-ci: Davidson CI / ai-review (push) Successful in 1m16s

This commit is contained in:
2026-09-09 20:32:51 +01:00
parent 8630b6133e
commit 0a64c09066
2 changed files with 19 additions and 8 deletions
+1 -1
View File
@@ -35,7 +35,7 @@
function openCheckout(items){
Paddle.Checkout.open({
items: items,
customData: JSON.stringify({user_id: "<?php echo htmlspecialchars(createTicket((int) ($_SESSION['user_id'] ?? 0), 'purchase'), ENT_QUOTES, 'UTF-8'); ?>"})
customData: {user_id: "<?php echo htmlspecialchars(createTicket((int) ($_SESSION['user_id'] ?? 0), 'purchase'), ENT_QUOTES, 'UTF-8'); ?>"}
});
}
</script>
+18 -7
View File
@@ -84,17 +84,28 @@ $pdo->exec('CREATE TABLE IF NOT EXISTS transactions (
)');
$pdo->exec('CREATE INDEX IF NOT EXISTS idx_transactions_user_id ON transactions (user_id)');
$existingStmt = $pdo->prepare('SELECT 1 FROM processed_webhook_events WHERE event_id = :event_id');
$existingStmt->execute(['event_id' => $eventId]);
if ($existingStmt->fetch()) {
respond(200, ['status' => 'already_processed']);
}
$creditsPerPrice = [
'pri_01m1v28mknf5pjm5c99cvxa5k4' => 20,
'pri_01m1v2aegbrdvwhw1jf7b0s6va' => 50,
];
$pdo->beginTransaction();
try {
// Claim the event ID first, inside the transaction: SQLite's unique constraint
// makes this the atomic compare-and-set that decides whether this delivery is
// the one that gets to apply credits. A losing concurrent delivery fails here
// before touching the user's balance.
$claimStmt = $pdo->prepare('INSERT INTO processed_webhook_events (event_id) VALUES (:event_id)');
$claimStmt->execute(['event_id' => $eventId]);
} catch (PDOException $e) {
$pdo->rollBack();
if (str_contains($e->getMessage(), 'UNIQUE constraint failed')) {
respond(200, ['status' => 'already_processed']);
}
throw $e;
}
if (($event['event_type'] ?? '') === 'transaction.completed') {
$data = $event['data'] ?? [];
$ticket = $data['custom_data']['user_id'] ?? null;
@@ -123,6 +134,6 @@ if (($event['event_type'] ?? '') === 'transaction.completed') {
}
}
$pdo->prepare('INSERT INTO processed_webhook_events (event_id) VALUES (:event_id)')->execute(['event_id' => $eventId]);
$pdo->commit();
respond(200, ['status' => 'ok']);