Files
ladill-events/app/Services/Billing/PlatformEmailClient.php
T
isaaccladandCursor 06fedcfc55
Deploy Ladill Events / deploy (push) Successful in 41s
Add virtual event sessions with Meet sync and platform-billed messaging.
Events can define hybrid/virtual sessions synced to Meet rooms; SMS and email use wallet-billed platform APIs instead of Termii and Laravel mail.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 22:08:09 +00:00

58 lines
1.7 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->token() === '') {
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;
}
}
}