'application/json']; if (is_string($apiKey) && $apiKey !== '') { $headers['Authorization'] = 'Bearer '.$apiKey; } try { $response = Http::withHeaders($headers) ->timeout($timeout) ->acceptJson() ->get($url, [ 'site_code' => $player->site_code, 'site_player_id' => $player->site_player_id, 'currency_code' => $currencyCode, ]); } catch (\Throwable) { return null; } if (! $response->successful()) { return null; } $payload = $response->json(); if (! is_array($payload)) { return null; } $raw = data_get($payload, 'data.main_balance') ?? data_get($payload, 'main_balance'); if (! is_numeric($raw)) { return null; } return max(0, (int) $raw); } }