7fb7f75050
Build Docker Image / build-backend (push) Successful in 18s
Co-authored-by: ISMAIL MASSERAN <topaz@Mac.dlinkrouter.local> Co-authored-by: ISMAIL MASSERAN <topaz@ISMAILs-Macbook.local> Reviewed-on: #16
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class StaffNotificationClient
|
|
{
|
|
/**
|
|
* Ask kaunter to persist a staff inbox row. Never throws.
|
|
*
|
|
* @param array $payload
|
|
* @return void
|
|
*/
|
|
public function notify(array $payload)
|
|
{
|
|
$base = rtrim((string) config('kaunter.url'), '/');
|
|
$secret = (string) config('kaunter.notification_secret');
|
|
|
|
if ($base === '' || $secret === '') {
|
|
Log::info('Staff notification skipped: KAUNTER_URL or INTERNAL_NOTIFICATION_SECRET is empty');
|
|
return;
|
|
}
|
|
|
|
$timeout = (int) config('kaunter.notification_timeout', 3);
|
|
if ($timeout < 1) {
|
|
$timeout = 3;
|
|
}
|
|
|
|
try {
|
|
$response = Http::timeout($timeout)
|
|
->withHeaders([
|
|
'X-Internal-Token' => $secret,
|
|
'Accept' => 'application/json',
|
|
])
|
|
->asJson()
|
|
->post($base . '/internal/notifications', $payload);
|
|
|
|
if (!$response->successful()) {
|
|
Log::warning('Staff notification to kaunter failed', [
|
|
'status' => $response->status(),
|
|
'body' => $response->body(),
|
|
'type' => isset($payload['type']) ? $payload['type'] : null,
|
|
]);
|
|
}
|
|
} catch (\Throwable $e) {
|
|
Log::warning('Staff notification to kaunter errored: '.$e->getMessage(), [
|
|
'type' => isset($payload['type']) ? $payload['type'] : null,
|
|
]);
|
|
}
|
|
}
|
|
}
|