Files
tomtomgames/bump_version.php
Myron Blair 674ec71682 Add in-admin refund processing for Square token purchases; commit earlier pending security fixes
Refund feature: token_purchases had no way to refund a completed Square
payment - the existing resolve_purchase action only approves/rejects
manual (Zelle etc) payments still in pending status. Adds a real
refund_purchase action (api/admin.php) that calls Squares actual Refunds
API via a new SquarePayment::refund() method, updates status to the new
refunded enum value, logs the refund ID, and claws back the tokens
credited on purchase (clamped at 0 if the customer already spent some,
reported back as a shortfall so staff know). UI: admin/index.php shows a
Refund button on completed card purchases with a square_payment_id.

Tested in sandbox: full refund with full token clawback, and a shortfall
scenario (user already spent below the credited amount) to confirm
clamping works correctly rather than going negative.

Also committing two earlier pending fixes from this session that were
never committed: .htaccess .py/!install!! blocking hardening and moving
bump_version.PHPs BUMP_KEY out of the web-reachable file into
includes/config.php.
2026-07-05 15:45:50 +00:00

53 lines
1.7 KiB
PHP

<?php
/**
* TomTomGames Version Manager
* Run after uploading a new build to update the DB version.
* Usage: https://tomtomgames.com/bump_version.php?key=ADMIN_KEY&version=1.0.2&notes=Your+notes+here
*
* Or auto-bump: ?key=ADMIN_KEY&bump=patch (1.0.1 → 1.0.2)
* ?key=ADMIN_KEY&bump=minor (1.0.1 → 1.1.0)
* ?key=ADMIN_KEY&bump=major (1.0.1 → 2.0.0)
*/
require_once __DIR__ . '/../includes/config.php'; // BUMP_KEY now defined there, not in this web-reachable file
if (($_GET['key'] ?? '') !== BUMP_KEY) {
http_response_code(403);
echo json_encode(['error' => 'Forbidden']);
exit;
}
require_once __DIR__ . '/../includes/db.php';
// Get current version
$current = db()->query("SELECT version FROM app_version ORDER BY id DESC LIMIT 1")->fetchColumn() ?: '1.0.0';
[$major, $minor, $patch] = array_map('intval', explode('.', $current));
// Determine new version
if (!empty($_GET['version'])) {
$newVersion = trim($_GET['version']);
} elseif (!empty($_GET['bump'])) {
switch ($_GET['bump']) {
case 'major': $newVersion = ($major+1).'.0.0'; break;
case 'minor': $newVersion = $major.'.'.($minor+1).'.0'; break;
default: $newVersion = $major.'.'.$minor.'.'.($patch+1); break;
}
} else {
// Default: bump patch
$newVersion = $major.'.'.$minor.'.'.($patch+1);
}
$notes = trim($_GET['notes'] ?? 'Build ' . date('Y-m-d H:i:s'));
db()->prepare("INSERT INTO app_version (version, notes) VALUES (?, ?)")
->execute([$newVersion, $notes]);
header('Content-Type: application/json');
echo json_encode([
'success' => true,
'previous' => $current,
'new_version' => $newVersion,
'notes' => $notes,
'timestamp' => date('Y-m-d H:i:s'),
]);