feat(admin): improve payments and server settings
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs\Mail\Admin;
|
||||
|
||||
use App\Mail\Admin\AdminPaymentReceived;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class AdminPaymentReceivedJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 3;
|
||||
public int $timeout = 60;
|
||||
|
||||
public function __construct(public readonly array $data) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
$values = $setting ? json_decode((string) $setting->value, true) : [];
|
||||
$adminEmail = $values['admin_email'] ?? null;
|
||||
|
||||
if (!$adminEmail) {
|
||||
Log::warning('AdminPaymentReceivedJob: admin_email not configured in settings.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Mail::to($adminEmail)->send(new AdminPaymentReceived([
|
||||
...$this->data,
|
||||
'company_name' => $values['company'] ?? config('app.name'),
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('AdminPaymentReceivedJob: failed to send email.', [
|
||||
'reference' => $this->data['reference'] ?? null,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user