Skip to content
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
16 changes: 15 additions & 1 deletion src/Endpoints/EmailEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EmailEndpoint extends Endpoint
private ?string $idempotencyKey = null;

/**
* Set the custom headeres.
* Set the custom headers.
*
* @example ["Key" => "Value"]
*
Expand Down Expand Up @@ -169,6 +169,20 @@ public function idempotencyKey(string $key): self
return $this;
}

/**
* Set custom metadata.
*
* @example ["key" => "value"]
*
* @param array<string, string> $metadata The metadata object.
*/
public function metadata(array $metadata): self
{
$this->payload['metadata'] = $metadata;

return $this;
}

/**
* Send the composed email using the current payload.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Endpoints/EmailEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,23 @@
->subject('Test Subject')
->send();
});

test('it handles metadata', function () {
$this->httpClient
->shouldReceive('post')
->once()
->with('/v1/send', [
'from' => 'sender@example.com',
'to' => ['recipient@example.com'],
'subject' => 'Test Subject',
'metadata' => ['foo' => 'bar'],
], [])
->andReturn(['message_id' => '123', 'status' => 'pending']);

$this->endpoint
->from('sender@example.com')
->to('recipient@example.com')
->subject('Test Subject')
->metadata(['foo' => 'bar'])
->send();
});
Loading