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)
|
public function consultarPadron(string $niv)
|
||||||
{
|
{
|
||||||
$this->asegurarCargaCredenciales();
|
$this->asegurarCargaCredenciales();
|
||||||
@ -101,10 +145,10 @@ public function consultarPadron(string $niv)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Ejecutar la solicitud
|
$result = $this->ejecutarSolicitudSoap($ch, 'doConsPadron', $url, $soapBody, ['niv' => $niv]);
|
||||||
$response = curl_exec($ch);
|
$response = $result['response'];
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = $result['http_code'];
|
||||||
$error = curl_error($ch);
|
$error = $result['curl_error'];
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
throw new Exception("Error en la petición SOAP: {$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 {
|
try {
|
||||||
$response = curl_exec($ch);
|
$result = $this->ejecutarSolicitudSoap($ch, 'doConsRepRobo', $url, $soapBody, ['niv' => $niv, 'placa' => $placa]);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$response = $result['response'];
|
||||||
$error = curl_error($ch);
|
$httpCode = $result['http_code'];
|
||||||
|
$error = $result['curl_error'];
|
||||||
|
|
||||||
// Si hay error de conexión, retornar error
|
// Si hay error de conexión, retornar error
|
||||||
if ($error) {
|
if ($error) {
|
||||||
logger()->error('REPUVE verificarRobo: Error de conexión', [
|
|
||||||
'error' => $error,
|
|
||||||
'niv' => $niv,
|
|
||||||
'placa' => $placa,
|
|
||||||
]);
|
|
||||||
return [
|
return [
|
||||||
'is_robado' => false,
|
'is_robado' => false,
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
@ -297,11 +337,6 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
|||||||
|
|
||||||
// Si hay error HTTP, retornar error
|
// Si hay error HTTP, retornar error
|
||||||
if ($httpCode !== 200) {
|
if ($httpCode !== 200) {
|
||||||
logger()->error('REPUVE verificarRobo: HTTP error', [
|
|
||||||
'http_code' => $httpCode,
|
|
||||||
'niv' => $niv,
|
|
||||||
'placa' => $placa,
|
|
||||||
]);
|
|
||||||
return [
|
return [
|
||||||
'is_robado' => false,
|
'is_robado' => false,
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
@ -381,16 +416,12 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = curl_exec($ch);
|
$result = $this->ejecutarSolicitudSoap($ch, 'doConsRPV', $url, $soapBody, ['niv' => $niv, 'placa' => $placa]);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$response = $result['response'];
|
||||||
$error = curl_error($ch);
|
$httpCode = $result['http_code'];
|
||||||
|
$error = $result['curl_error'];
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
logger()->error('REPUVE consultarVehiculo: Error de conexión', [
|
|
||||||
'error' => $error,
|
|
||||||
'niv' => $niv,
|
|
||||||
'placa' => $placa,
|
|
||||||
]);
|
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
@ -399,11 +430,6 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($httpCode !== 200) {
|
if ($httpCode !== 200) {
|
||||||
logger()->error('REPUVE consultarVehiculo: HTTP error', [
|
|
||||||
'http_code' => $httpCode,
|
|
||||||
'niv' => $niv,
|
|
||||||
'placa' => $placa,
|
|
||||||
]);
|
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
@ -514,22 +540,14 @@ public function inscribirVehiculo(array $datos)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Ejecutar la petición
|
$result = $this->ejecutarSolicitudSoap($ch, 'inscribe', $url, $soapBody, [
|
||||||
$response = curl_exec($ch);
|
'niv' => $datos['niv'] ?? null,
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
'placa' => $datos['placa'] ?? null,
|
||||||
$curlError = curl_error($ch);
|
'nrpv' => $datos['nrpv'] ?? null,
|
||||||
|
|
||||||
// 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
|
|
||||||
]);
|
]);
|
||||||
|
$response = $result['response'];
|
||||||
|
$httpCode = $result['http_code'];
|
||||||
|
$curlError = $result['curl_error'];
|
||||||
|
|
||||||
if ($curlError) {
|
if ($curlError) {
|
||||||
$errorFromDb = Error::where('code', '103')->first();
|
$errorFromDb = Error::where('code', '103')->first();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user