8000 [Webhook][RemoteEvent] fix SendgridPayloadConverter category support · symfony/symfony@c389e45 · GitHub
[go: up one dir, main page]

Skip to content

Commit c389e45

Browse files
committed
[Webhook][RemoteEvent] fix SendgridPayloadConverter category support
1 parent 02cafa9 commit c389e45

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Symfony/Component/Mailer/Bridge/Sendgrid/RemoteEvent/SendgridPayloadConverter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ public function convert(array $payload): AbstractMailerEvent
5151
$event->setDate($date);
5252
$event->setRecipientEmail($payload['email']);
5353
$event->setMetadata([]);
54-
$event->setTags($payload['category'] ?? []);
54+
55+
$tags = [];
56+
// If you send single categories as an array, they will be returned by the webhook as an array.
57+
// If you send single categories as a string, they will be returned by the webhook as a string.
58+
if (isset($payload['category'])) {
59+
$tags = \is_array($payload['category']) ? $payload['category'] : [$payload['category']];
60+
}
61+
$event->setTags($tags);
5562

5663
return $event;
5764
}

src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/RemoteEvent/SendgridPayloadConverterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,20 @@ public function testInvalidDate()
9797
'email' => 'test@example.com',
9898
]);
9999
}
100+
101+
public function testWithStringCategory()
102+
{
103+
$converter = new SendgridPayloadConverter();
104+
105+
$event = $converter->convert([
106+
'event' => 'processed',
107+
'sg_message_id' => '123456',
108+
'timestamp' => '123456789',
109+
'email' => 'test@example.com',
110+
'category' => 'cat facts',
111+
]);
112+
113+
$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
114+
$this->assertSame(['cat facts'], $event->getTags());
115+
}
100116
}

0 commit comments

Comments
 (0)
0