Skip to content

Commit 4bc9f45

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: Remove comment about AppVeyor in `phpunit` [Webhook][RemoteEvent] fix SendgridPayloadConverter category support Update old Appveyor skip conditions sync the Dutch translation file with changes from the 7.2 branch [Yaml] fix inline notation with inline comment fix(property-info): make sure that SerializerExtractor returns null for invalid class metadata [RemoteEvent][Webhook] fix SendgridRequestParser & SendgridPayloadConverter in case of missing sg_message_id fix_50486 - memory leak
2 parents cc6feab + 18dca2e commit 4bc9f45

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

RemoteEvent/SendgridPayloadConverter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function convert(array $payload): AbstractMailerEvent
3131
'deferred' => MailerDeliveryEvent::DEFERRED,
3232
'bounce' => MailerDeliveryEvent::BOUNCE,
3333
};
34-
$event = new MailerDeliveryEvent($name, $payload['sg_message_id'], $payload);
34+
$event = new MailerDeliveryEvent($name, $payload['sg_message_id'] ?? $payload['sg_event_id'], $payload);
3535
$event->setReason($payload['reason'] ?? '');
3636
} else {
3737
$name = match ($payload['event']) {
@@ -41,7 +41,7 @@ public function convert(array $payload): AbstractMailerEvent
4141
'spamreport' => MailerEngagementEvent::SPAM,
4242
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
4343
};
44-
$event = new MailerEngagementEvent($name, $payload['sg_message_id'], $payload);
44+
$event = new MailerEngagementEvent($name, $payload['sg_message_id'] ?? $payload['sg_event_id'], $payload);
4545
}
4646

4747
if (!$date = \DateTimeImmutable::createFromFormat('U', $payload['timestamp'])) {
@@ -51,7 +51,7 @@ public function convert(array $payload): AbstractMailerEvent
5151
$event->setDate($date);
5252
$event->setRecipientEmail($payload['email']);
5353
$event->setMetadata([]);
54-
$event->setTags($payload['category'] ?? []);
54+
$event->setTags((array) ($payload['category'] ?? []));
5555

5656
return $event;
5757
}

Tests/RemoteEvent/SendgridPayloadConverterTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,35 @@ public function testInvalidDate()
9797
'email' => '[email protected]',
9898
]);
9999
}
100+
101+
public function testAsynchronousBounce()
102+
{
103+
$converter = new SendgridPayloadConverter();
104+
105+
$event = $converter->convert([
106+
'event' => 'bounce',
107+
'sg_event_id' => '123456',
108+
'timestamp' => '123456789',
109+
'email' => '[email protected]',
110+
]);
111+
112+
$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
113+
$this->assertSame('123456', $event->getId());
114+
}
115+
116+
public function testWithStringCategory()
117+
{
118+
$converter = new SendgridPayloadConverter();
119+
120+
$event = $converter->convert([
121+
'event' => 'processed',
122+
'sg_message_id' => '123456',
123+
'timestamp' => '123456789',
124+
'email' => '[email protected]',
125+
'category' => 'cat facts',
126+
]);
127+
128+
$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
129+
$this->assertSame(['cat facts'], $event->getTags());
130+
}
100131
}

Webhook/SendgridRequestParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function doParse(Request $request, string $secret): ?AbstractMailerEve
4848
!isset($content[0]['email'])
4949
|| !isset($content[0]['timestamp'])
5050
|| !isset($content[0]['event'])
51-
|| !isset($content[0]['sg_message_id'])
51+
|| !isset($content[0]['sg_event_id'])
5252
) {
5353
throw new RejectWebhookException(406, 'Payload is malformed.');
5454
}

0 commit comments

Comments
 (0)