<?php
require_once '../../includes/config.php';
require_once '../../includes/successtopup.php';
requireAdmin();

$api_key    = getSetting('successtopup_key');
$api_secret = getSetting('successtopup_secret');

// Keys আছে কিনা চেক করো
if (!$api_key || !$api_secret) {
    jsonResponse(false, '❌ API Key বা Secret সেভ নেই! Settings থেকে আগে সেভ করুন।');
}

$result = successTopupBalance();

if (isset($result['result']) && $result['result'] === true) {
    $balance      = number_format($result['balance'] ?? 0, 2);
    $driveBalance = number_format($result['driveBalance'] ?? 0, 2);
    jsonResponse(true, '✅ Balance: ৳'.$balance.' | Drive: ৳'.$driveBalance, [
        'balance'      => $result['balance'] ?? 0,
        'driveBalance' => $result['driveBalance'] ?? 0,
    ]);
} else {
    $msg = $result['message'] ?? 'অজানা সমস্যা';
    jsonResponse(false, '❌ '.$msg);
}
