Skip to content

Commit 469a10c

Browse files
committed
Add new attributes to Infobip API transport to support reporting behavior
1 parent 24a5f20 commit 469a10c

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

src/Symfony/Component/Mailer/Bridge/Infobip/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.3
5+
---
6+
7+
* Add reporting behavior thanks to new attributes support
8+
49
6.2
510
---
611

src/Symfony/Component/Mailer/Bridge/Infobip/Tests/Transport/InfobipApiTransportTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,51 @@ public function testSendEmailWithAttachmentsShouldCalledInfobipWithTheRightParam
241241
);
242242
}
243243

244+
public function testSendEmailWithHeadersShouldCalledInfobipWithTheRightParameters()
245+
{
246+
$email = $this->basicValidEmail();
247+
$email->getHeaders()
248+
->addTextHeader('X-Infobip-IntermediateReport', 'true')
249+
->addTextHeader('X-Infobip-NotifyUrl', 'https://foo.bar')
250+
->addTextHeader('X-Infobip-NotifyContentType', 'application/json')
251+
->addTextHeader('X-Infobip-MessageId', 'RANDOM-CUSTOM-ID');
252+
253+
$this->transport->send($email);
254+
255+
$options = $this->response->getRequestOptions();
256+
$this->arrayHasKey('body');
257+
$this->assertStringMatchesFormat(<<<'TXT'
258+
%a
259+
--%s
260+
Content-Type: text/plain; charset=utf-8
261+
Content-Transfer-Encoding: 8bit
262+
Content-Disposition: form-data; name="intermediateReport"
263+
264+
true
265+
--%s
266+
Content-Type: text/plain; charset=utf-8
267+
Content-Transfer-Encoding: 8bit
268+
Content-Disposition: form-data; name="notifyUrl"
269+
270+
https://foo.bar
271+
--%s
272+
Content-Type: text/plain; charset=utf-8
273+
Content-Transfer-Encoding: 8bit
274+
Content-Disposition: form-data; name="notifyContentType"
275+
276+
application/json
277+
--%s
278+
Content-Type: text/plain; charset=utf-8
279+
Content-Transfer-Encoding: 8bit
280+
Content-Disposition: form-data; name="messageId"
281+
282+
RANDOM-CUSTOM-ID
283+
--%s--
284+
TXT,
285+
$options['body']
286+
);
287+
}
288+
244289
public function testSendMinimalEmailWithSuccess()
245290
{
246291
$email = (new Email())
@@ -357,6 +402,31 @@ public function testSendEmailWithAttachmentsWithSuccess()
357402
);
358403
}
359404

405+
public function testSendEmailWithHeadersWithSuccess()
406+
{
407+
$email = $this->basicValidEmail();
408+
$email->getHeaders()
409+
->addTextHeader('X-Infobip-IntermediateReport', 'true')
410+
->addTextHeader('X-Infobip-NotifyUrl', 'https://foo.bar')
411+
->addTextHeader('X-Infobip-NotifyContentType', 'application/json')
412+
->addTextHeader('X-Infobip-MessageId', 'RANDOM-CUSTOM-ID');
413+
414+
$sentMessage = $this->transport->send($email);
415+
416+
$this->assertInstanceOf(SentMessage::class, $sentMessage);
417+
$this->assertStringMatchesFormat(
418+
<<<'TXT'
419+
%a
420+
X-Infobip-IntermediateReport: true
421+
X-Infobip-NotifyUrl: https://foo.bar
422+
X-Infobip-NotifyContentType: application/json
423+
X-Infobip-MessageId: RANDOM-CUSTOM-ID
424+
%a
425+
TXT,
426+
$sentMessage->toString()
427+
);
428+
}
429+
360430
public function testSentMessageShouldCaptureInfobipMessageId()
361431
{
362432
$this->response = new MockResponse('{"messages": [{"messageId": "somexternalMessageId0"}]}');

src/Symfony/Component/Mailer/Bridge/Infobip/Transport/InfobipApiTransport.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ final class InfobipApiTransport extends AbstractApiTransport
3333
{
3434
private const API_VERSION = '2';
3535

36+
private const HEADER_TO_MESSAGE = [
37+
'X-Infobip-IntermediateReport' => 'intermediateReport',
38+
'X-Infobip-NotifyUrl' => 'notifyUrl',
39+
'X-Infobip-NotifyContentType' => 'notifyContentType',
40+
'X-Infobip-MessageId' => 'messageId',
41+
];
42+
3643
private string $key;
3744

3845
public function __construct(string $key, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
@@ -123,6 +130,12 @@ private function formDataPart(Email $email, Envelope $envelope): FormDataPart
123130

124131
$this->attachmentsFormData($fields, $email);
125132

133+
foreach ($email->getHeaders()->all() as $header) {
134+
if ($convertConf = self::HEADER_TO_MESSAGE[$header->getName()] ?? false) {
135+
$fields[$convertConf] = $header->getBodyAsString();
136+
}
137+
}
138+
126139
return new FormDataPart($fields);
127140
}
128141

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