client = $client; $this->parameterBag = $parameterBag; $this->mailUtils = $mailUtils ; $this->utils = $utils ; $this->templating = $templating ; } public function send($params = []) { $user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ; if($user) { $phone = $this->utils->formatPhoneNumber($user->getPhone()) ; $message = '' ; if(isset($params[self::CONTENT_MESSAGE])) { $message = $params[self::CONTENT_MESSAGE] ; } elseif(isset($params[self::CONTENT_TEMPLATE])) { $template = $params[self::CONTENT_TEMPLATE] ; $paramsTemplate = [] ; if(isset($params[self::CONTENT_DATA]) && is_array($params[self::CONTENT_DATA])) { $paramsTemplate = $params[self::CONTENT_DATA] ; } $message = $this->templating->render($template, $paramsTemplate) ; } if($this->parameterBag->get('mailjet.dev.redirect.active') == 1) { $this->mailUtils->send([ MailUtils::SUBJECT => 'Notification par SMS à '.$phone, MailUtils::TO_EMAIL => $user->getEmail(), MailUtils::CONTENT_TEMPLATE => 'mail/notification', MailUtils::CONTENT_DATA => [ 'message' => $message ], ]); return true ; } else { $token = $this->parameterBag->get('mailjet.sms.token'); $from = $this->parameterBag->get('mailjet.sms.from'); if ($token && strlen($token) > 0) { $response = $this->client->request( 'POST', 'https://api.mailjet.com/v4/sms-send', [ 'headers' => [ 'Authorization' => 'Bearer ' . $token, ], 'json' => [ 'From' => $from, 'To' => $phone, 'Text' => $message, ] ] ); $statusCode = $response->getStatusCode(); if ($statusCode == 200) { $content = $response->getContent(); $content = $response->toArray(); return $content; } else { // log } } else { throw new \ErrorException('Le token SMS Mailjet n\'est pas défini.'); } } } return false; } }