'col-lg-4 col-md-3 col-sm-6 col-xs-6', 'bg_color' => 'bg-pink', 'icon' => 'sms', 'name' => 'SMS Credit', 'counter' => 0, ]; public function run() { $providerType = strtolower(config('sms.gateway_type', 'egyptian')); try { if ($providerType === 'telnyx') { $this->fetchTelnyxBalance(); } else { $this->fetchEgyptianBalance(); } } catch (\Exception $e) { $this->config['counter'] = 0; $this->config['name'] = 'SMS Provider Error'; } return view('sms::widgets.sms_widget_box', [ 'config' => $this->config, ]); } private function fetchTelnyxBalance(): void { $apiKey = config('sms.telnyx.api_key', ''); if (empty($apiKey)) { $this->config['counter'] = 0; $this->config['name'] = 'No SMS Provider Configured'; return; } $response = Http::withOptions(['verify' => false]) ->withToken($apiKey) ->get('https://api.telnyx.com/v2/balance'); if ($response->successful()) { $data = $response->json('data') ?? []; $balance = isset($data['balance']) ? (float) $data['balance'] : 0; $currency = $data['currency'] ?? 'USD'; $this->config['counter'] = $balance; $this->config['name'] = "Telnyx Balance ({$currency})"; } else { $this->config['counter'] = 0; $this->config['name'] = 'Telnyx Balance'; } } private function fetchEgyptianBalance(): void { $smsUser = CompanySettings::get('S_COMPANY_SMSUSER'); $smsPass = CompanySettings::get('S_COMPANY_SMSPASS'); if (empty($smsUser) || empty($smsPass)) { $this->config['counter'] = 0; $this->config['name'] = 'No SMS Provider Configured'; return; } $response = Http::withOptions(['verify' => false]) ->withBasicAuth($smsUser, $smsPass) ->get('https://api.socialbrand.agency/api/SMS/CheckCredit'); if ($response->successful()) { $this->config['counter'] = (int) trim($response->body()); } $this->config['name'] = 'Remaining SMS Credits'; } }