Deploy Ladill Events / deploy (push) Successful in 28s
Attendee and speaker comms use encrypted tenant relay credentials and skip platform-key fallback and Bird wallet double-debit. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Events;
|
|
|
|
use App\Services\Messaging\CustomerEmailClient;
|
|
use App\Services\Messaging\MessagingCredentialsService;
|
|
|
|
/**
|
|
* Sends Ladill Events transactional email to attendees and speakers via the
|
|
* customer's Ladill Bird relay when configured in Integrations.
|
|
*/
|
|
class EventMailer
|
|
{
|
|
private ?string $lastError = null;
|
|
|
|
public function __construct(
|
|
private readonly MessagingCredentialsService $credentials,
|
|
private readonly CustomerEmailClient $customerEmail,
|
|
) {}
|
|
|
|
public function lastError(): ?string
|
|
{
|
|
return $this->lastError;
|
|
}
|
|
|
|
public function isConfiguredForOwner(string $ownerPublicId): bool
|
|
{
|
|
return $this->credentials->forOwner($ownerPublicId)->hasValidBird();
|
|
}
|
|
|
|
/** @deprecated Use isConfiguredForOwner() — attendee email requires per-account Bird credentials. */
|
|
public function isConfigured(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function send(
|
|
string $ownerPublicId,
|
|
string $to,
|
|
string $subject,
|
|
string $html,
|
|
?string $text = null,
|
|
?string $replyToEmail = null,
|
|
?string $replyToName = null,
|
|
): bool {
|
|
$this->lastError = null;
|
|
|
|
$credential = $this->credentials->forOwner($ownerPublicId);
|
|
if (! $credential->hasValidBird()) {
|
|
$this->lastError = 'Connect Ladill Bird in Integrations before sending attendee email.';
|
|
|
|
return false;
|
|
}
|
|
|
|
$apiKey = $credential->birdApiKey();
|
|
if (! $apiKey) {
|
|
$this->lastError = 'Bird credentials could not be decrypted. Reconnect Bird in Integrations.';
|
|
|
|
return false;
|
|
}
|
|
|
|
$sent = $this->customerEmail->send(
|
|
$apiKey,
|
|
(string) $credential->bird_from_email,
|
|
$credential->bird_from_name,
|
|
$to,
|
|
$subject,
|
|
$html,
|
|
$text,
|
|
);
|
|
|
|
if (! $sent) {
|
|
$this->lastError = $this->customerEmail->lastError() ?: 'The email could not be sent.';
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|