Deploy Ladill Events / deploy (push) Successful in 41s
Surface specific send failures, allow resend, use ladl.link portal URLs, and replace stacked speaker forms with a single add-to-list pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Billing;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class PlatformEmailClient
|
|
{
|
|
private function base(): string
|
|
{
|
|
return rtrim((string) config('smtp.platform_api_url', 'https://ladill.com/api/smtp'), '/');
|
|
}
|
|
|
|
private function token(): string
|
|
{
|
|
return (string) config('smtp.platform_api_key', '');
|
|
}
|
|
|
|
public function send(string $ownerPublicId, string $to, string $subject, string $html, ?string $text = null): bool
|
|
{
|
|
if (! $this->isConfigured()) {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
$res = Http::withToken($this->token())->acceptJson()->timeout(30)
|
|
->post($this->base().'/messages/send', array_filter([
|
|
'user' => $ownerPublicId,
|
|
'from' => config('smtp.from'),
|
|
'from_name' => config('smtp.from_name'),
|
|
'to' => $to,
|
|
'subject' => $subject,
|
|
'html' => $html,
|
|
'text' => $text,
|
|
]));
|
|
|
|
if ($res->status() === 402) {
|
|
Log::warning('Platform email send: insufficient balance', ['user' => $ownerPublicId]);
|
|
|
|
return false;
|
|
}
|
|
|
|
if ($res->failed()) {
|
|
Log::warning('Platform email send failed', ['status' => $res->status(), 'body' => $res->body()]);
|
|
|
|
return false;
|
|
}
|
|
|
|
return (bool) ($res->json('success') ?? true);
|
|
} catch (\Throwable $e) {
|
|
Log::warning('Platform email send error', ['error' => $e->getMessage()]);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function isConfigured(): bool
|
|
{
|
|
return $this->token() !== '';
|
|
}
|
|
}
|