feat: agrega función para Repuve nacional con logging detallado
This commit is contained in:
parent
28d008bf54
commit
fc897f5130
@ -68,6 +68,50 @@ private function loadCredentials(): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ejecuta una solicitud cURL con logging completo de conexión, datos enviados,
|
||||
* tiempo de respuesta y respuesta recibida.
|
||||
*
|
||||
* @return array{response: string|false, http_code: int, curl_error: string, elapsed_ms: float}
|
||||
*/
|
||||
private function ejecutarSolicitudSoap(\CurlHandle $ch, string $operacion, string $url, string $soapBody, array $contexto = []): array
|
||||
{
|
||||
logger()->info("REPUVE Nacional [{$operacion}]: Enviando solicitud al servidor", array_merge([
|
||||
'url' => $url,
|
||||
'soap_body' => $soapBody,
|
||||
], $contexto));
|
||||
|
||||
$inicio = microtime(true);
|
||||
$response = curl_exec($ch);
|
||||
$elapsedMs = round((microtime(true) - $inicio) * 1000, 2);
|
||||
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
|
||||
if ($curlError) {
|
||||
logger()->error("REPUVE Nacional [{$operacion}]: Sin conexión con el servidor", array_merge([
|
||||
'url' => $url,
|
||||
'curl_error' => $curlError,
|
||||
'elapsed_ms' => $elapsedMs,
|
||||
], $contexto));
|
||||
} else {
|
||||
logger()->info("REPUVE Nacional [{$operacion}]: Respuesta recibida", array_merge([
|
||||
'url' => $url,
|
||||
'http_code' => $httpCode,
|
||||
'elapsed_ms' => $elapsedMs,
|
||||
'response_length' => strlen($response ?: ''),
|
||||
'response' => $response,
|
||||
], $contexto));
|
||||
}
|
||||
|
||||
return [
|
||||
'response' => $response,
|
||||
'http_code' => $httpCode,
|
||||
'curl_error' => $curlError,
|
||||
'elapsed_ms' => $elapsedMs,
|
||||
];
|
||||
}
|
||||
|
||||
public function consultarPadron(string $niv)
|
||||
{
|
||||
$this->asegurarCargaCredenciales();
|
||||
@ -101,10 +145,10 @@ public function consultarPadron(string $niv)
|
||||
]);
|
||||
|
||||
try {
|
||||
// Ejecutar la solicitud
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
$result = $this->ejecutarSolicitudSoap($ch, 'doConsPadron', $url, $soapBody, ['niv' => $niv]);
|
||||
$response = $result['response'];
|
||||
$httpCode = $result['http_code'];
|
||||
$error = $result['curl_error'];
|
||||
|
||||
if ($error) {
|
||||
throw new Exception("Error en la petición SOAP: {$error}");
|
||||
@ -277,17 +321,13 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
$result = $this->ejecutarSolicitudSoap($ch, 'doConsRepRobo', $url, $soapBody, ['niv' => $niv, 'placa' => $placa]);
|
||||
$response = $result['response'];
|
||||
$httpCode = $result['http_code'];
|
||||
$error = $result['curl_error'];
|
||||
|
||||
// Si hay error de conexión, retornar error
|
||||
if ($error) {
|
||||
logger()->error('REPUVE verificarRobo: Error de conexión', [
|
||||
'error' => $error,
|
||||
'niv' => $niv,
|
||||
'placa' => $placa,
|
||||
]);
|
||||
return [
|
||||
'is_robado' => false,
|
||||
'has_error' => true,
|
||||
@ -297,11 +337,6 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
||||
|
||||
// Si hay error HTTP, retornar error
|
||||
if ($httpCode !== 200) {
|
||||
logger()->error('REPUVE verificarRobo: HTTP error', [
|
||||
'http_code' => $httpCode,
|
||||
'niv' => $niv,
|
||||
'placa' => $placa,
|
||||
]);
|
||||
return [
|
||||
'is_robado' => false,
|
||||
'has_error' => true,
|
||||
@ -381,16 +416,12 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null)
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$error = curl_error($ch);
|
||||
$result = $this->ejecutarSolicitudSoap($ch, 'doConsRPV', $url, $soapBody, ['niv' => $niv, 'placa' => $placa]);
|
||||
$response = $result['response'];
|
||||
$httpCode = $result['http_code'];
|
||||
$error = $result['curl_error'];
|
||||
|
||||
if ($error) {
|
||||
logger()->error('REPUVE consultarVehiculo: Error de conexión', [
|
||||
'error' => $error,
|
||||
'niv' => $niv,
|
||||
'placa' => $placa,
|
||||
]);
|
||||
return [
|
||||
'success' => false,
|
||||
'has_error' => true,
|
||||
@ -399,11 +430,6 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null)
|
||||
}
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
logger()->error('REPUVE consultarVehiculo: HTTP error', [
|
||||
'http_code' => $httpCode,
|
||||
'niv' => $niv,
|
||||
'placa' => $placa,
|
||||
]);
|
||||
return [
|
||||
'success' => false,
|
||||
'has_error' => true,
|
||||
@ -514,22 +540,14 @@ public function inscribirVehiculo(array $datos)
|
||||
]);
|
||||
|
||||
try {
|
||||
// Ejecutar la petición
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
|
||||
// Loguear para debug
|
||||
logger()->info('REPUVE Inscripción Request', [
|
||||
'url' => $url,
|
||||
'soap_body' => $soapBody
|
||||
]);
|
||||
|
||||
logger()->info('REPUVE Inscripción Response', [
|
||||
'http_code' => $httpCode,
|
||||
'curl_error' => $curlError,
|
||||
'response' => $response
|
||||
$result = $this->ejecutarSolicitudSoap($ch, 'inscribe', $url, $soapBody, [
|
||||
'niv' => $datos['niv'] ?? null,
|
||||
'placa' => $datos['placa'] ?? null,
|
||||
'nrpv' => $datos['nrpv'] ?? null,
|
||||
]);
|
||||
$response = $result['response'];
|
||||
$httpCode = $result['http_code'];
|
||||
$curlError = $result['curl_error'];
|
||||
|
||||
if ($curlError) {
|
||||
$errorFromDb = Error::where('code', '103')->first();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user