. */ namespace App\Libraries; use Ovh\Api; use Illuminate\Support\Facades\Log; class OvhSMS { private $api; private $smsService; public function __construct() { if (empty(config('ovh.app_key'))) { Log::error('OVH SMS API not configured'); } $this->api = new Api( config('ovh.app_key'), config('ovh.app_secret'), config('ovh.app_endpoint'), config('ovh.app_consumer_key') ); try { $smsServices = $this->api->get('/sms'); if (!empty($smsServices)) { $this->smsService = $smsServices[0]; } } catch (\Exception $e) { Log::channel('events')->info('OVH SMS API unreachable, check the errors log'); Log::error('OVH SMS API not reachable: ' . $e->getMessage()); } } public function send(string $to, string $message) { if (!$this->smsService) { Log::error('OVH SMS API not configured'); return; } $content = (object) [ 'charset' => 'UTF-8', 'class' => 'phoneDisplay', 'coding' => '7bit', 'message' => $message, 'noStopClause' => true, 'priority' => 'high', 'receivers' => [ $to ], 'sender' => config('ovh.app_sender'), 'senderForResponse' => false, 'validityPeriod' => 2880 ]; Log::channel('events')->info('OVH SMS sending', ['to' => $to, 'message' => $message]); try { $this->api->post('/sms/'. $this->smsService . '/jobs', $content); // One credit removed $this->api->get('/sms/'. $this->smsService . '/jobs'); } catch (\Exception $e) { Log::channel('events')->info('OVH SMS not sent, check the errors log'); Log::error('OVH SMS not sent: ' . $e->getMessage()); } } }