Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f112d9

Browse filesBrowse files
committed
feature #42748 [Notifier] Add Esendex message ID to SentMessage object (benr77)
This PR was merged into the 5.4 branch. Discussion ---------- [Notifier] Add Esendex message ID to SentMessage object | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The Esendex API request returns a unique message ID for each SMS sent. This commit simply extracts the message ID and adds it to the returned SentMessage object. Commits ------- 3489e44 [Notifier] Add Esendex message ID to SentMessage object
2 parents 5caa07a + 3489e44 commit 6f112d9
Copy full SHA for 6f112d9

File tree

3 files changed

+37
-1
lines changed
Filter options

3 files changed

+37
-1
lines changed

‎src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
CHANGELOG
22
=========
33

4+
* Add returned message ID to `SentMessage`
5+
46
5.3
57
---
68

‎src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ protected function doSend(MessageInterface $message): SentMessage
6969

7070
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
7171
'auth_basic' => sprintf('%s:%s', $this->email, $this->password),
72+
'headers' => [
73+
'Accept' => 'application/json',
74+
],
7275
'json' => [
7376
'accountreference' => $this->accountReference,
7477
'messages' => [$messageData],
@@ -82,7 +85,15 @@ protected function doSend(MessageInterface $message): SentMessage
8285
}
8386

8487
if (200 === $statusCode) {
85-
return new SentMessage($message, (string) $this);
88+
$result = $response->toArray();
89+
$sentMessage = new SentMessage($message, (string) $this);
90+
91+
$messageId = $result['batch']['messageheaders'][0]['id'] ?? null;
92+
if ($messageId) {
93+
$sentMessage->setMessageId($messageId);
94+
}
95+
96+
return $sentMessage;
8697
}
8798

8899
$message = sprintf('Unable to send the SMS: error %d.', $statusCode);

‎src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Notifier\Message\SmsMessage;
2020
use Symfony\Component\Notifier\Test\TransportTestCase;
2121
use Symfony\Component\Notifier\Transport\TransportInterface;
22+
use Symfony\Component\Uid\Uuid;
2223
use Symfony\Contracts\HttpClient\HttpClientInterface;
2324
use Symfony\Contracts\HttpClient\ResponseInterface;
2425

@@ -88,4 +89,26 @@ public function testSendWithErrorResponseContainingDetailsThrowsTransportExcepti
8889

8990
$transport->send(new SmsMessage('phone', 'testMessage'));
9091
}
92+
93+
public function testSendWithSuccessfulResponseDispatchesMessageEvent()
94+
{
95+
$messageId = Uuid::v4()->toRfc4122();
96+
$response = $this->createMock(ResponseInterface::class);
97+
$response->expects($this->exactly(2))
98+
->method('getStatusCode')
99+
->willReturn(200);
100+
$response->expects($this->once())
101+
->method('getContent')
102+
->willReturn(json_encode(['batch' => ['messageheaders' => [['id' => $messageId]]]]));
103+
104+
$client = new MockHttpClient(static function () use ($response): ResponseInterface {
105+
return $response;
106+
});
107+
108+
$transport = $this->createTransport($client);
109+
110+
$sentMessage = $transport->send(new SmsMessage('phone', 'testMessage'));
111+
112+
$this->assertSame($messageId, $sentMessage->getMessageId());
113+
}
91114
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.