Skip to content

Commit 03a8fd2

Browse files
committed
Fix: Lack of recipient in case DSN does not have optional LIST_ID parameter. According to https://developers.clicksend.com/docs/messaging/sms/other/send-sms#other/send-sms/t=request&path=messages/list_id we need to provide the "to" parameter or the "list_id" parameter.
Also fixed forwarding FROM_EMAIL parameter to request.
1 parent 82a1563 commit 03a8fd2

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/Symfony/Component/Notifier/Bridge/ClickSend/ClickSendTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ protected function doSend(MessageInterface $message): SentMessage
7575
$options['from'] = $message->getFrom() ?: $this->from;
7676
$options['source'] ??= $this->source;
7777
$options['list_id'] ??= $this->listId;
78-
$options['from_email'] ?? $this->fromEmail;
78+
$options['from_email'] ??= $this->fromEmail;
7979

8080
if (isset($options['from']) && !preg_match('/^[a-zA-Z0-9\s]{3,11}$/', $options['from']) && !preg_match('/^\+[1-9]\d{1,14}$/', $options['from'])) {
8181
throw new InvalidArgumentException(sprintf('The "From" number "%s" is not a valid phone number, shortcode, or alphanumeric sender ID.', $options['from']));
8282
}
8383

84-
if ($options['list_id'] ?? false) {
84+
if (!isset($options['list_id']) || !$options['list_id']) {
8585
$options['to'] = $message->getPhone();
8686
}
8787

src/Symfony/Component/Notifier/Bridge/ClickSend/Tests/ClickSendTransportTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public static function createTransport(?HttpClientInterface $client = null, stri
2828
{
2929
return new ClickSendTransport('test_username', 'test_key', $from, $source, $listId, $fromEmail, $client ?? new MockHttpClient());
3030
}
31+
public static function createTransportWithoutOptionalParameters(?HttpClientInterface $client = null): ClickSendTransport
32+
{
33+
return new ClickSendTransport('test_username', 'test_key', client: $client ?? new MockHttpClient());
34+
}
3135

3236
public static function invalidFromProvider(): iterable
3337
{
@@ -70,13 +74,40 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
7074
$body = json_decode($options['body'], true);
7175
self::assertIsArray($body);
7276
self::assertArrayHasKey('messages', $body);
77+
$message = reset($body['messages']);
78+
self::assertArrayHasKey('from_email', $message);
79+
self::assertArrayHasKey('list_id', $message);
80+
self::assertArrayNotHasKey('to', $message);
7381

7482
return $response;
7583
});
7684
$transport = $this->createTransport($client, $from);
7785
$transport->send($message);
7886
}
7987

88+
public function testNoInvalidArgumentExceptionIsThrownIfFromIsValidWithoutOptionalParameters()
89+
{
90+
$message = new SmsMessage('+33612345678', 'Hello!');
91+
$response = $this->createMock(ResponseInterface::class);
92+
$response->expects(self::exactly(2))->method('getStatusCode')->willReturn(200);
93+
$response->expects(self::once())->method('getContent')->willReturn('');
94+
$client = new MockHttpClient(function (string $method, string $url, array $options) use ($response): ResponseInterface {
95+
self::assertSame('POST', $method);
96+
self::assertSame('https://rest.clicksend.com/v3/sms/send', $url);
97+
98+
$body = json_decode($options['body'], true);
99+
self::assertIsArray($body);
100+
self::assertArrayHasKey('messages', $body);
101+
$message = reset($body['messages']);
102+
self::assertArrayNotHasKey('list_id', $message);
103+
self::assertArrayHasKey('to', $message);
104+
105+
return $response;
106+
});
107+
$transport = $this->createTransportWithoutOptionalParameters($client);
108+
$transport->send($message);
109+
}
110+
80111
public static function toStringProvider(): iterable
81112
{
82113
yield ['clicksend://rest.clicksend.com?from=test_from&source=test_source&list_id=99&from_email=foo%40bar.com', self::createTransport()];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy