false, 'error' => 'School not found or not connected']);
exit();
}
$s = $client->getSellerStatus($config['partner_merchant_id'], $merchantId);
$merchants[$school] = array_merge($merchants[$school], [
'paypal_ready' => $s['paypal_ready'],
'email_confirmed' => $s['email_confirmed'],
'payments_receivable' => $s['payments_receivable'],
'oauth_ok' => $s['oauth_ok'],
'seller_email' => $s['seller_email'],
'status_issues' => $s['issues'],
'status_checked_at' => time(),
]);
file_put_contents($merchantsFile, json_encode($merchants, JSON_PRETTY_PRINT));
echo json_encode(array_merge(['success' => true], $s));
exit();
}
if ($_POST['action'] === 'check_all') {
$refreshed = 0;
foreach ($merchants as $school => &$data) {
$mid = $data['merchant_id'] ?? null;
if (!$mid) continue;
$s = $client->getSellerStatus($config['partner_merchant_id'], $mid);
$data = array_merge($data, [
'paypal_ready' => $s['paypal_ready'],
'email_confirmed' => $s['email_confirmed'],
'payments_receivable' => $s['payments_receivable'],
'oauth_ok' => $s['oauth_ok'],
'seller_email' => $s['seller_email'],
'status_issues' => $s['issues'],
'status_checked_at' => time(),
]);
$refreshed++;
}
unset($data);
file_put_contents($merchantsFile, json_encode($merchants, JSON_PRETTY_PRINT));
echo json_encode(['success' => true, 'refreshed' => $refreshed]);
exit();
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit();
}
// ── Load data (only needed for authenticated view) ─────────────────────────
$merchants = [];
$pending = [];
$total = 0;
$ready = 0;
$withIssues = 0;
$pendingCount = 0;
if ($_SESSION['admin'] ?? false) {
$merchantsFile = $dataDir . '/school_merchants.json';
if (file_exists($merchantsFile)) {
$merchants = json_decode(file_get_contents($merchantsFile), true) ?: [];
}
$pendingFile = $dataDir . '/pending_onboarding.json';
if (file_exists($pendingFile)) {
$pending = json_decode(file_get_contents($pendingFile), true) ?: [];
}
$total = count($merchants);
foreach ($merchants as $m) {
if ($m['paypal_ready'] ?? false) $ready++;
if (!empty($m['status_issues'])) $withIssues++;
}
foreach ($pending as $p) {
if (in_array($p['status'] ?? '', ['pending', 'waiting_for_paypal', 'incomplete_onboarding'])) {
$pendingCount++;
}
}
}
?>
PayPal Admin Dashboard
Welcome back
Sign in to manage your PayPal merchant connections.
= htmlspecialchars($error) ?>
🏫
Total Schools
= $total ?>
⚠️
With Issues
= $withIssues ?>
⏳
Pending
= $pendingCount ?>
🏫
No schools connected yet. Use the onboarding page to connect a school.
in_array($p['status'] ?? '', ['pending','waiting_for_paypal','incomplete_onboarding']));
?>
$p): ?>
= htmlspecialchars($p['school'] ?? $tid) ?>
Status: = htmlspecialchars($p['status']) ?>
· Started: = isset($p['created_at']) ? date('M j, Y', $p['created_at']) : '—' ?>
⏳ = htmlspecialchars(ucfirst(str_replace('_', ' ', $p['status']))) ?>