feat(logging): implement dedicated logging for Telepagos events and update logging configuration
This commit is contained in:
@@ -81,9 +81,7 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
$data = $this->handleResponse($response, 'authentication', [
|
||||
'username' => $username,
|
||||
]);
|
||||
$data = $this->handleResponse($response, 'authentication');
|
||||
|
||||
$token = $data['token'] ?? null;
|
||||
$expiresAtStr = $data['expires_at'] ?? null;
|
||||
@@ -110,7 +108,12 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
$response = $this->client()->$method($endpoint, $data);
|
||||
|
||||
if ($response->status() === 401) {
|
||||
Log::info('Telepagos 401 Unauthorized. Refreshing token and retrying...');
|
||||
Log::channel('telepagos')->info('Telepagos request returned 401; refreshing token and retrying.', [
|
||||
'method' => strtoupper($method),
|
||||
'endpoint' => $endpoint,
|
||||
'client_id' => $this->clientContext?->id,
|
||||
'integration_code' => $this->integrationCode,
|
||||
]);
|
||||
|
||||
$this->clearToken();
|
||||
|
||||
@@ -175,9 +178,11 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
{
|
||||
if ($response->failed() || $response->json('status') !== 'ok') {
|
||||
$errorMessage = $response->json('message') ?? $response->body();
|
||||
Log::error("Telepagos {$actionDescription} failed: {$errorMessage}", array_merge([
|
||||
Log::channel('telepagos')->error("Telepagos {$actionDescription} failed: {$errorMessage}", array_merge([
|
||||
'response_status' => $response->status(),
|
||||
'response_body' => $response->json() ?? $response->body(),
|
||||
'response_body' => $this->sanitizeForLog($response->json() ?? $response->body()),
|
||||
'client_id' => $this->clientContext?->id,
|
||||
'integration_code' => $this->integrationCode,
|
||||
], $context));
|
||||
|
||||
throw new Exception("Telepagos {$actionDescription} failed: {$errorMessage}");
|
||||
@@ -186,6 +191,30 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
return $response->json() ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove credentials and tokens before serializing provider responses.
|
||||
*/
|
||||
protected function sanitizeForLog(mixed $value): mixed
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$sensitiveKeys = ['authorization', 'password', 'token', 'access_token', 'refresh_token'];
|
||||
|
||||
foreach ($value as $key => $item) {
|
||||
if (in_array(strtolower((string) $key), $sensitiveKeys, true)) {
|
||||
$value[$key] = '[REDACTED]';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$value[$key] = $this->sanitizeForLog($item);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cached token.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user