Skip to content

[RemoteEvent][Webhook] Fix SendgridRequestParser and SendgridPayloadConverter #59376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function convert(array $payload): AbstractMailerEvent
'deferred' => MailerDeliveryEvent::DEFERRED,
'bounce' => MailerDeliveryEvent::BOUNCE,
};
$event = new MailerDeliveryEvent($name, $payload['sg_message_id'], $payload);
$event = new MailerDeliveryEvent($name, $payload['sg_message_id'] ?? $payload['sg_event_id'], $payload);
$event->setReason($payload['reason'] ?? '');
} else {
$name = match ($payload['event']) {
Expand All @@ -41,7 +41,7 @@ public function convert(array $payload): AbstractMailerEvent
'spamreport' => MailerEngagementEvent::SPAM,
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
};
$event = new MailerEngagementEvent($name, $payload['sg_message_id'], $payload);
$event = new MailerEngagementEvent($name, $payload['sg_message_id'] ?? $payload['sg_event_id'], $payload);
}

if (!$date = \DateTimeImmutable::createFromFormat('U', $payload['timestamp'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ public function testInvalidDate()
'email' => 'test@example.com',
]);
}

public function testAsynchronousBounce()
{
$converter = new SendgridPayloadConverter();

$event = $converter->convert([
'event' => 'bounce',
'sg_event_id' => '123456',
'timestamp' => '123456789',
'email' => 'test@example.com',
]);

$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
$this->assertSame('123456', $event->getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function doParse(Request $request, string $secret): ?AbstractMailerEve
!isset($content[0]['email'])
|| !isset($content[0]['timestamp'])
|| !isset($content[0]['event'])
|| !isset($content[0]['sg_message_id'])
|| !isset($content[0]['sg_event_id'])
) {
throw new RejectWebhookException(406, 'Payload is malformed.');
}
Expand Down
Loading