|
|
@@ -5,28 +5,55 @@ namespace Lc\ShopBundle\Services; |
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface; |
|
|
|
use Twig\Environment; |
|
|
|
|
|
|
|
class MailjetSMS |
|
|
|
class MailjetSmsUtils |
|
|
|
{ |
|
|
|
const TO_USER = 'to-user' ; |
|
|
|
const CONTENT_MESSAGE = 'content-message' ; |
|
|
|
const CONTENT_TEMPLATE = 'content-template' ; |
|
|
|
const CONTENT_DATA = 'content-data' ; |
|
|
|
|
|
|
|
protected $client; |
|
|
|
protected $parameterBag; |
|
|
|
protected $mailUtils ; |
|
|
|
protected $utils ; |
|
|
|
protected $templating ; |
|
|
|
|
|
|
|
public function __construct(HttpClientInterface $client, ParameterBagInterface $parameterBag, UtilsManager $utilsManager) |
|
|
|
{ |
|
|
|
public function __construct( |
|
|
|
HttpClientInterface $client, |
|
|
|
ParameterBagInterface $parameterBag, |
|
|
|
MailUtils $mailUtils, |
|
|
|
Utils $utils, |
|
|
|
Environment $templating |
|
|
|
) { |
|
|
|
$this->client = $client; |
|
|
|
$this->parameterBag = $parameterBag; |
|
|
|
$this->mailUtils = $utilsManager->getMailUtils() ; |
|
|
|
$this->utils = $utilsManager->getUtils() ; |
|
|
|
$this->mailUtils = $mailUtils ; |
|
|
|
$this->utils = $utils ; |
|
|
|
$this->templating = $templating ; |
|
|
|
} |
|
|
|
|
|
|
|
public function send($user, $message) |
|
|
|
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, |