diff --git a/src/Symfony/Component/Notifier/Bridge/Sendinblue/README.md b/src/Symfony/Component/Notifier/Bridge/Sendinblue/README.md index 24016686f9a41..60fe990dcb64e 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sendinblue/README.md +++ b/src/Symfony/Component/Notifier/Bridge/Sendinblue/README.md @@ -15,6 +15,9 @@ where: - `API_KEY` is your api key from your Sendinblue account - `PHONE` is your sender's phone number +You can also add **type**, **tag** and **webUrl** in parameter like the sender. +Those parameters are optional. + See more info at https://developers.sendinblue.com/reference#sendtransacsms Resources diff --git a/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransport.php b/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransport.php index 889bd1c454cf1..b804d6ce37fe0 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransport.php @@ -31,11 +31,17 @@ final class SendinblueTransport extends AbstractTransport private $apiKey; private $sender; + private $type; + private $tag; + private $webUrl; - public function __construct(string $apiKey, string $sender, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) + public function __construct(string $apiKey, string $sender, string $type, string $tag = null, string $webUrl = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) { $this->apiKey = $apiKey; $this->sender = $sender; + $this->type = $type; + $this->tag = $tag; + $this->webUrl = $webUrl; parent::__construct($client, $dispatcher); } @@ -57,11 +63,7 @@ protected function doSend(MessageInterface $message): SentMessage } $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [ - 'json' => [ - 'sender' => $this->sender, - 'recipient' => $message->getPhone(), - 'content' => $message->getSubject(), - ], + 'json' => $this->getPayload($message), 'headers' => [ 'api-key' => $this->apiKey, ], @@ -80,4 +82,22 @@ protected function doSend(MessageInterface $message): SentMessage return $message; } + + private function getPayload(MessageInterface $message): array + { + $payload = [ + 'sender' => $this->sender, + 'recipient' => $message->getPhone(), + 'content' => $message->getSubject(), + 'type' => $this->type, + ]; + if ($this->tag) { + $payload['tag'] = $this->tag; + } + if ($this->webUrl) { + $payload['webUrl'] = $this->webUrl; + } + + return $payload; + } } diff --git a/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransportFactory.php b/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransportFactory.php index 7f9d1f9b4b78c..f0424296d8f8d 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransportFactory.php +++ b/src/Symfony/Component/Notifier/Bridge/Sendinblue/SendinblueTransportFactory.php @@ -35,11 +35,14 @@ public function create(Dsn $dsn): TransportInterface $scheme = $dsn->getScheme(); $apiKey = $this->getUser($dsn); + $type = $dsn->getOption('type', 'transactional'); + $tag = $dsn->getOption('tag'); + $webUrl = $dsn->getOption('webUrl'); $host = 'default' === $dsn->getHost() ? null : $dsn->getHost(); $port = $dsn->getPort(); if ('sendinblue' === $scheme) { - return (new SendinblueTransport($apiKey, $sender, $this->client, $this->dispatcher))->setHost($host)->setPort($port); + return (new SendinblueTransport($apiKey, $sender, $type, $tag, $webUrl, $this->client, $this->dispatcher))->setHost($host)->setPort($port); } throw new UnsupportedSchemeException($dsn, 'sendinblue', $this->getSupportedSchemes()); diff --git a/src/Symfony/Component/Notifier/Bridge/Sendinblue/Tests/SendinblueTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Sendinblue/Tests/SendinblueTransportTest.php index a296697e4ad14..68cef29dc2cde 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sendinblue/Tests/SendinblueTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Sendinblue/Tests/SendinblueTransportTest.php @@ -70,7 +70,7 @@ public function testSendWithErrorResponseThrows(): void private function initTransport(?HttpClientInterface $client = null): SendinblueTransport { return (new SendinblueTransport( - 'api-key', '0611223344', $client ?: $this->createMock(HttpClientInterface::class) + 'api-key', '0611223344', 'transactional', null, null, $client ?: $this->createMock(HttpClientInterface::class) ))->setHost('host.test'); } }