Skip to content

Commit 2ade00d

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

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-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 infobip 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('intermediateReport', 'true')
249+
->addTextHeader('notifyUrl', 'https://foo.bar')
250+
->addTextHeader('notifyContentType', 'application/json')
251+
->addTextHeader('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('intermediateReport', 'true')
410+
->addTextHeader('notifyUrl', 'https://foo.bar')
411+
->addTextHeader('notifyContentType', 'application/json')
412+
->addTextHeader('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+
intermediateReport: true
421+
notifyUrl: https://foo.bar
422+
notifyContentType: application/json
423+
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ private function formDataPart(Email $email, Envelope $envelope): FormDataPart
123123

124124
$this->attachmentsFormData($fields, $email);
125125

126+
$headers = $email->getHeaders();
127+
128+
if ($headers->has('intermediateReport')) {
129+
$fields['intermediateReport'] = $headers->getHeaderBody('intermediateReport');
130+
}
131+
132+
if ($headers->has('notifyUrl')) {
133+
$fields['notifyUrl'] = $headers->getHeaderBody('notifyUrl');
134+
}
135+
136+
if ($headers->has('notifyContentType')) {
137+
$fields['notifyContentType'] = $headers->getHeaderBody('notifyContentType');
138+
}
139+
140+
if ($headers->has('messageId')) {
141+
$fields['messageId'] = $headers->getHeaderBody('messageId');
142+
}
143+
126144
return new FormDataPart($fields);
127145
}
128146

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