Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xabbuh committed Jan 7, 2025
2 parents cc6feab + 18dca2e commit 4bc9f45
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions RemoteEvent/SendgridPayloadConverter.php
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 All @@ -51,7 +51,7 @@ public function convert(array $payload): AbstractMailerEvent
$event->setDate($date);
$event->setRecipientEmail($payload['email']);
$event->setMetadata([]);
$event->setTags($payload['category'] ?? []);
$event->setTags((array) ($payload['category'] ?? []));

return $event;
}
Expand Down
31 changes: 31 additions & 0 deletions Tests/RemoteEvent/SendgridPayloadConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,35 @@ 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());
}

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

$event = $converter->convert([
'event' => 'processed',
'sg_message_id' => '123456',
'timestamp' => '123456789',
'email' => 'test@example.com',
'category' => 'cat facts',
]);

$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
$this->assertSame(['cat facts'], $event->getTags());
}
}
2 changes: 1 addition & 1 deletion Webhook/SendgridRequestParser.php
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

0 comments on commit 4bc9f45

Please sign in to comment.