payfrit-api/api/beacons/wipe.php
John Mizerek 5d9be247c8 Add beacons/lookupByMac.php and beacons/wipe.php endpoints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-16 19:13:21 -07:00

44 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/../helpers.php';
runAuth();
global $businessId;
$data = readJsonBody();
$bizId = $businessId;
if ($bizId <= 0) $bizId = (int) ($data['BusinessID'] ?? 0);
if ($bizId <= 0) {
apiAbort(['OK' => false, 'ERROR' => 'no_business_selected']);
}
$beaconId = (int) ($data['BeaconID'] ?? 0);
if ($beaconId <= 0) {
apiAbort(['OK' => false, 'ERROR' => 'missing_beacon_id', 'MESSAGE' => 'BeaconID is required']);
}
$q = queryOne("
SELECT ID, BusinessID, ServicePointID FROM BeaconHardware
WHERE ID = ? AND BusinessID = ?
LIMIT 1
", [$beaconId, $bizId]);
if (!$q) {
apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Beacon not found or does not belong to this business']);
}
$servicePointId = (int) ($q['ServicePointID'] ?? 0);
// Clear the minor from the service point so it can be re-provisioned
if ($servicePointId > 0) {
queryTimed("UPDATE ServicePoints SET BeaconMinor = NULL WHERE ID = ? AND BusinessID = ?", [$servicePointId, $bizId]);
}
// Mark hardware as unassigned
queryTimed("
UPDATE BeaconHardware
SET Status = 'unassigned', BusinessID = NULL, ServicePointID = NULL,
ShardUUID = NULL, Major = NULL, Minor = NULL, UpdatedAt = NOW()
WHERE ID = ?
", [$beaconId]);
jsonResponse(['OK' => true, 'ERROR' => '', 'BeaconID' => $beaconId]);