Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3. Shared helpers in api/helpers.php (DB, auth, request/response, security). PDO prepared statements throughout. Same JSON response shapes as CFML.
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Worker Tier + Activation Status
|
|
* POST: { UserID: int }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$userID = (int) ($data['UserID'] ?? 0);
|
|
|
|
global $userId;
|
|
if ($userID <= 0) $userID = $userId;
|
|
|
|
if ($userID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'UserID is required.']);
|
|
}
|
|
|
|
try {
|
|
$qUser = queryOne("
|
|
SELECT StripeConnectedAccountID, StripePayoutsEnabled,
|
|
ActivationBalanceCents, ActivationCapCents
|
|
FROM Users WHERE ID = ?
|
|
", [$userID]);
|
|
|
|
if (!$qUser) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'user_not_found']);
|
|
}
|
|
|
|
$payoutsEnabled = ((int) ($qUser['StripePayoutsEnabled'] ?? 0)) === 1;
|
|
$hasAccount = !empty(trim($qUser['StripeConnectedAccountID'] ?? ''));
|
|
$balanceCents = (int) ($qUser['ActivationBalanceCents'] ?? 0);
|
|
$capCents = (int) ($qUser['ActivationCapCents'] ?? 0);
|
|
$remainingCents = max(0, $capCents - $balanceCents);
|
|
$isComplete = ($remainingCents === 0);
|
|
$progressPercent = $capCents > 0 ? (int) round(($balanceCents / $capCents) * 100) : 100;
|
|
if ($progressPercent > 100) $progressPercent = 100;
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'TIER' => $payoutsEnabled ? 1 : 0,
|
|
'STRIPE' => [
|
|
'HasAccount' => $hasAccount,
|
|
'PayoutsEnabled' => $payoutsEnabled,
|
|
'SetupIncomplete' => $hasAccount && !$payoutsEnabled,
|
|
],
|
|
'ACTIVATION' => [
|
|
'BalanceCents' => $balanceCents,
|
|
'CapCents' => $capCents,
|
|
'RemainingCents' => $remainingCents,
|
|
'IsComplete' => $isComplete,
|
|
'ProgressPercent' => $progressPercent,
|
|
],
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => $e->getMessage()]);
|
|
}
|