diff --git a/app/Services/Billing/PlatformEmailClient.php b/app/Services/Billing/PlatformEmailClient.php index 2057b7e..80b9c10 100644 --- a/app/Services/Billing/PlatformEmailClient.php +++ b/app/Services/Billing/PlatformEmailClient.php @@ -7,6 +7,13 @@ use Illuminate\Support\Facades\Log; class PlatformEmailClient { + private ?string $lastError = null; + + public function lastError(): ?string + { + return $this->lastError; + } + private function base(): string { return rtrim((string) config('smtp.platform_api_url', 'https://ladill.com/api/smtp'), '/'); @@ -19,7 +26,11 @@ class PlatformEmailClient public function send(string $ownerPublicId, string $to, string $subject, string $html, ?string $text = null): bool { + $this->lastError = null; + if (! $this->isConfigured()) { + $this->lastError = 'Outbound email is not configured on this Events instance.'; + return false; } @@ -36,12 +47,14 @@ class PlatformEmailClient ])); if ($res->status() === 402) { + $this->lastError = (string) ($res->json('error') ?: 'Insufficient Bird email credits. Add funds in Billing and try again.'); Log::warning('Platform email send: insufficient balance', ['user' => $ownerPublicId]); return false; } if ($res->failed()) { + $this->lastError = (string) ($res->json('error') ?: 'The email could not be sent. Please try again.'); Log::warning('Platform email send failed', ['status' => $res->status(), 'body' => $res->body()]); return false; @@ -49,6 +62,7 @@ class PlatformEmailClient return (bool) ($res->json('success') ?? true); } catch (\Throwable $e) { + $this->lastError = 'The email could not be sent. Please try again.'; Log::warning('Platform email send error', ['error' => $e->getMessage()]); return false; diff --git a/app/Services/Events/EventEmailService.php b/app/Services/Events/EventEmailService.php index 6372fdd..9bb865c 100644 --- a/app/Services/Events/EventEmailService.php +++ b/app/Services/Events/EventEmailService.php @@ -9,6 +9,11 @@ class EventEmailService { public function __construct(private readonly PlatformEmailClient $platform) {} + public function lastError(): ?string + { + return $this->platform->lastError(); + } + public function sendProgrammeShare( string $ownerPublicId, string $to, diff --git a/app/Services/Events/EventSpeakerInviteService.php b/app/Services/Events/EventSpeakerInviteService.php index 10a627a..a811550 100644 --- a/app/Services/Events/EventSpeakerInviteService.php +++ b/app/Services/Events/EventSpeakerInviteService.php @@ -249,7 +249,8 @@ class EventSpeakerInviteService if (! $sent) { return [ 'ok' => false, - 'error' => 'The invitation email could not be sent. Check your Ladill wallet balance and try again.', + 'error' => $this->email->lastError() + ?: 'The invitation email could not be sent. Check your Bird email balance and verified sending domain, then try again.', ]; }