normalise($to); if ($apiKey === '' || $msisdn === null) { return false; } try { $res = Http::timeout(20) ->withHeaders(['api-key' => $apiKey]) ->acceptJson() ->post(rtrim((string) config('arkesel.base_url', 'https://sms.arkesel.com'), '/').'/api/v2/sms/send', [ 'sender' => $sender, 'message' => $message, 'recipients' => [$msisdn], ]); return $res->successful() && ($res->json('status') === 'success'); } catch (\Throwable $e) { Log::warning('CRM SMS send failed', ['to' => $msisdn, 'error' => $e->getMessage()]); return false; } } /** Normalise to E.164-without-plus (e.g. 233XXXXXXXXX). */ private function normalise(string $to): ?string { $digits = preg_replace('/\D+/', '', $to) ?? ''; $country = (string) config('arkesel.default_country_code', '233'); if (strlen($digits) < 9) { return null; } if (str_starts_with($digits, $country)) { return $digits; } if (str_starts_with($digits, '0')) { return $country.substr($digits, 1); } if (strlen($digits) === 9) { return $country.$digits; } return $digits; } }