This commit is contained in:
David Bomba 2025-06-25 08:50:56 +10:00
parent 54ba4349f6
commit c8e0cdd090
5 changed files with 939 additions and 908 deletions

1342
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -20,126 +20,6 @@ class WSTest extends TestCase
<sum:Cabecera>
<sum1:ObligadoEmision>
<sum1:NombreRazon>Certificate One Telematics</sum1:NombreRazon>
<sum1:NIF>89890001K</sum1:NIF>
</sum1:ObligadoEmision>
</sum:Cabecera>
<sum:RegistroFactura>
<sum1:RegistroAlta>
<sum1:IDVersion>1.0</sum1:IDVersion>
<sum1:IDFactura>
<sum1:IDEmisorFactura>89890001K</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345678-G66</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>03-02-2025</sum1:FechaExpedicionFactura>
</sum1:IDFactura>
<sum1:NombreRazonEmisor>Certificate One Telematics</sum1:NombreRazonEmisor>
<sum1:Correccion>N</sum1:Correccion>
<sum1:RechazoPrevio>N</sum1:RechazoPrevio>
<sum1:TipoFactura>R3</sum1:TipoFactura>
<sum1:TipoRectificativa>I</sum1:TipoRectificativa>
<sum1:FacturasRectificadas>
<sum1:IDFacturaRectificada>
<sum1:IDEmisorFactura>89890001K</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345600-G66</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>01-04-2024</sum1:FechaExpedicionFactura>
</sum1:IDFacturaRectificada>
</sum1:FacturasRectificadas>
<sum1:FechaOperacion>03-02-2025</sum1:FechaOperacion>
<sum1:DescripcionOperacion>delivery date</sum1:DescripcionOperacion>
<sum1:Destinatarios>
<sum1:IDDestinatario>
<sum1:NombreRazon>Certificate Two Telematics</sum1:NombreRazon>
<sum1:NIF>89890002E</sum1:NIF>
</sum1:IDDestinatario>
</sum1:Destinatarios>
<sum1:Desglose>
<sum1:DetalleDesglose>
<sum1:ClaveRegimen>01</sum1:ClaveRegimen>
<sum1:CalificacionOperacion>S1</sum1:CalificacionOperacion>
<sum1:TipoImpositivo>4</sum1:TipoImpositivo>
<sum1:BaseImponibleOimporteNoSujeto>10.00</sum1:BaseImponibleOimporteNoSujeto>
<sum1:CuotaRepercutida>0.40</sum1:CuotaRepercutida>
</sum1:DetalleDesglose>
<sum1:DetalleDesglose>
<sum1:ClaveRegimen>01</sum1:ClaveRegimen>
<sum1:CalificacionOperacion>S1</sum1:CalificacionOperacion>
<sum1:TipoImpositivo>21</sum1:TipoImpositivo>
<sum1:BaseImponibleOimporteNoSujeto>100.00</sum1:BaseImponibleOimporteNoSujeto>
<sum1:CuotaRepercutida>21.00</sum1:CuotaRepercutida>
</sum1:DetalleDesglose>
<sum1:DetalleDesglose>
<sum1:ClaveRegimen>05</sum1:ClaveRegimen>
<sum1:CalificacionOperacion>S1</sum1:CalificacionOperacion>
<sum1:TipoImpositivo>10</sum1:TipoImpositivo>
<sum1:BaseImponibleOimporteNoSujeto>100.00</sum1:BaseImponibleOimporteNoSujeto>
<sum1:CuotaRepercutida>10.00</sum1:CuotaRepercutida>
</sum1:DetalleDesglose>
</sum1:Desglose>
<sum1:CuotaTotal>31.40</sum1:CuotaTotal>
<sum1:ImporteTotal>241.40</sum1:ImporteTotal>
<sum1:Encadenamiento>
<sum1:RegistroAnterior>
<sum1:IDEmisorFactura>89890001K</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345677-G33</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>15-04-2024</sum1:FechaExpedicionFactura>
<sum1:Huella>C9AF4AF1EF5EBBA700350DE3EEF12C2D355C56AC56F13DB2A25E0031BD2B7ED5</sum1:Huella>
</sum1:RegistroAnterior>
</sum1:Encadenamiento>
<sum1:SistemaInformatico>
<sum1:NombreRazon>CERTIFICATE ONE TELEMATICAS</sum1:NombreRazon>
<sum1:NIF>89890001K</sum1:NIF>
<sum1:NombreSistemaInformatico>SystemName</sum1:NombreSistemaInformatico>
<sum1:IdSistemaInformatico>77</sum1:IdSistemaInformatico>
<sum1:Version>1.0.03</sum1:Version>
<sum1:NumeroInstalacion>383</sum1:NumeroInstalacion>
<sum1:TipoUsoPosibleSoloVerifactu>S</sum1:TipoUsoPosibleSoloVerifactu>
<sum1:TipoUsoPosibleMultiOT>N</sum1:TipoUsoPosibleMultiOT>
<sum1:IndicadorMultiplesOT>N</sum1:IndicadorMultiplesOT>
</sum1:SistemaInformatico>
<sum1:FechaHoraHusoGenRegistro>2025-02-03T14:30:00+01:00</sum1:FechaHoraHusoGenRegistro>
<sum1:TipoHuella>01</sum1:TipoHuella>
<sum1:Huella>FF954378B64ED331A9B2366AD317D86E9DEC1716B12DD0ACCB172A6DC4C105AA</sum1:Huella>
</sum1:RegistroAlta>
</sum:RegistroFactura>
</sum:RegFactuSistemaFacturacion>
</soapenv:Body>
</soapenv:Envelope>
XML;
$endpoint = 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP';
$certPath = storage_path('aeat-cert2.pem');
$keyPath = storage_path('aeat-key2.pem');
$response = Http::withHeaders([
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => '',
])
->withOptions([
'cert' => $certPath,
'ssl_key' => $keyPath,
'verify' => false, // Optional: disable CA verification for testing
])
->post($endpoint, $soapXml);
\Log::info('Request with AEAT official test data:');
\Log::info($soapXml);
\Log::info('Response with AEAT official test data:');
\Log::info($response->body());
$this->assertTrue($response->successful());
}
public function test_send_aeat_example_without_cert()
{
$soapXml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sum="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd"
xmlns:sum1="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd">
<soapenv:Header/>
<soapenv:Body>
<sum:RegFactuSistemaFacturacion>
<sum:Cabecera>
<sum1:ObligadoEmision>
<sum1:NombreRazon>XXXXX</sum1:NombreRazon>
<sum1:NIF>99999910G</sum1:NIF>
</sum1:ObligadoEmision>
</sum:Cabecera>
@ -148,16 +28,16 @@ XML;
<sum1:IDVersion>1.0</sum1:IDVersion>
<sum1:IDFactura>
<sum1:IDEmisorFactura>99999910G</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>13-09-2024</sum1:FechaExpedicionFactura>
<sum1:NumSerieFactura>TEST-001</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>24-06-2025</sum1:FechaExpedicionFactura>
</sum1:IDFactura>
<sum1:NombreRazonEmisor>XXXXX</sum1:NombreRazonEmisor>
<sum1:NombreRazonEmisor>Certificate One Telematics</sum1:NombreRazonEmisor>
<sum1:TipoFactura>F1</sum1:TipoFactura>
<sum1:DescripcionOperacion>Descripc</sum1:DescripcionOperacion>
<sum1:DescripcionOperacion>Test invoice</sum1:DescripcionOperacion>
<sum1:Destinatarios>
<sum1:IDDestinatario>
<sum1:NombreRazon>YYYY</sum1:NombreRazon>
<sum1:NIF>BBBB</sum1:NIF>
<sum1:NombreRazon>Test Recipient</sum1:NombreRazon>
<sum1:NIF>99999999A</sum1:NIF>
</sum1:IDDestinatario>
</sum1:Destinatarios>
<sum1:Desglose>
@ -171,9 +51,6 @@ XML;
</sum1:Desglose>
<sum1:CuotaTotal>21.00</sum1:CuotaTotal>
<sum1:ImporteTotal>121.00</sum1:ImporteTotal>
<sum1:Encadenamiento>
<sum1:PrimerRegistro>S</sum1:PrimerRegistro>
</sum1:Encadenamiento>
<sum1:SistemaInformatico>
<sum1:NombreRazon>SSSS</sum1:NombreRazon>
<sum1:NIF>99999910G</sum1:NIF>
@ -185,9 +62,9 @@ XML;
<sum1:TipoUsoPosibleMultiOT>S</sum1:TipoUsoPosibleMultiOT>
<sum1:IndicadorMultiplesOT>S</sum1:IndicadorMultiplesOT>
</sum1:SistemaInformatico>
<sum1:FechaHoraHusoGenRegistro>2024-09-13T19:20:30+01:00</sum1:FechaHoraHusoGenRegistro>
<sum1:FechaHoraHusoGenRegistro>2025-06-24T22:34:00+01:00</sum1:FechaHoraHusoGenRegistro>
<sum1:TipoHuella>01</sum1:TipoHuella>
<sum1:Huella>Huella</sum1:Huella>
<sum1:Huella>PLACEHOLDER_HUELLA</sum1:Huella>
</sum1:RegistroAlta>
</sum:RegistroFactura>
</sum:RegFactuSistemaFacturacion>
@ -195,29 +72,84 @@ XML;
</soapenv:Envelope>
XML;
// Calculate the correct hash for the XML content (excluding the signature)
$xmlForHash = $this->getXmlForHashCalculation($soapXml);
$correctHash = strtoupper(hash('sha256', $xmlForHash));
// Replace the placeholder with the correct hash
$soapXml = str_replace('PLACEHOLDER_HUELLA', $correctHash, $soapXml);
\Log::info('Calculated hash for XML: ' . $correctHash);
// Try the Requerimiento endpoint instead of Verifactu
// $endpoint = 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/RequerimientoSOAP';
$endpoint = 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP';
$certPath = storage_path('aeat-cert2.pem');
$keyPath = storage_path('aeat-key2.pem');
$signingService = new \App\Services\EDocument\Standards\Verifactu\Signing\SigningService($soapXml, file_get_contents($keyPath),file_get_contents($certPath));
$soapXml = $signingService->sign();
$response = Http::withHeaders([
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => '',
'SOAPAction' => 'RegFactuSistemaFacturacion',
])
->withOptions([
'cert' => $certPath,
'ssl_key' => $keyPath,
'verify' => false, // Optional: disable CA verification for testing
'timeout' => 30, // Increase timeout
])
->post($endpoint, $soapXml);
\Log::info('Request without certificate:');
\Log::info('Request with AEAT official test data:');
\Log::info($soapXml);
\Log::info('Response without certificate:');
\Log::info($response->body());
\Log::info('Status code: ' . $response->status());
\Log::info('Response with AEAT official test data:');
\Log::info('Response Status: ' . $response->status());
\Log::info('Response Headers: ' . json_encode($response->headers()));
\Log::info('Response Body: ' . $response->body());
// This might fail, but we want to see the response
$this->assertTrue(true); // Just to see the response
// Don't assert success yet, let's see what the actual response is
if (!$response->successful()) {
\Log::error('Request failed with status: ' . $response->status());
\Log::error('Response body: ' . $response->body());
}
public function test_send_aeat_example_to_alternative_endpoint()
$this->assertTrue($response->successful());
}
/**
* Extract the XML content that should be used for hash calculation
* This excludes the signature and focuses on the business data
*/
private function getXmlForHashCalculation(string $fullXml): string
{
$doc = new \DOMDocument();
$doc->loadXML($fullXml);
// Find the RegistroAlta element
$registroAlta = $doc->getElementsByTagNameNS('https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd', 'RegistroAlta')->item(0);
if (!$registroAlta) {
throw new \Exception('RegistroAlta element not found');
}
// Create a new document with just the RegistroAlta content
$hashDoc = new \DOMDocument('1.0', 'UTF-8');
$hashDoc->preserveWhiteSpace = false;
$hashDoc->formatOutput = false;
// Import the RegistroAlta node
$importedNode = $hashDoc->importNode($registroAlta, true);
$hashDoc->appendChild($importedNode);
// Return the XML string for hash calculation
return $hashDoc->saveXML();
}
public function test_send_brand_new_invoice_to_verifactu()
{
// Create a completely new invoice with fresh data
$soapXml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
@ -228,36 +160,144 @@ XML;
<sum:RegFactuSistemaFacturacion>
<sum:Cabecera>
<sum1:ObligadoEmision>
<sum1:NombreRazon>Certificate One Telematics</sum1:NombreRazon>
<sum1:NIF>89890001K</sum1:NIF>
<sum1:NombreRazon>NUEVA EMPRESA TEST SL</sum1:NombreRazon>
<sum1:NIF>99999910G</sum1:NIF>
</sum1:ObligadoEmision>
</sum:Cabecera>
<sum:RegistroFactura>
<sum1:RegistroAlta>
<sum1:IDVersion>1.0</sum1:IDVersion>
<sum1:IDFactura>
<sum1:IDEmisorFactura>89890001K</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345678-G66</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>03-02-2025</sum1:FechaExpedicionFactura>
<sum1:IDEmisorFactura>99999910G</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>FAC-2025-001</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>24-06-2025</sum1:FechaExpedicionFactura>
</sum1:IDFactura>
<sum1:NombreRazonEmisor>Certificate One Telematics</sum1:NombreRazonEmisor>
<sum1:Correccion>N</sum1:Correccion>
<sum1:RechazoPrevio>N</sum1:RechazoPrevio>
<sum1:TipoFactura>R3</sum1:TipoFactura>
<sum1:TipoRectificativa>I</sum1:TipoRectificativa>
<sum1:FacturasRectificadas>
<sum1:IDFacturaRectificada>
<sum1:IDEmisorFactura>89890001K</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345600-G66</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>01-04-2024</sum1:FechaExpedicionFactura>
</sum1:IDFacturaRectificada>
</sum1:FacturasRectificadas>
<sum1:FechaOperacion>03-02-2025</sum1:FechaOperacion>
<sum1:DescripcionOperacion>delivery date</sum1:DescripcionOperacion>
<sum1:NombreRazonEmisor>NUEVA EMPRESA TEST SL</sum1:NombreRazonEmisor>
<sum1:TipoFactura>F1</sum1:TipoFactura>
<sum1:DescripcionOperacion>Venta de servicios informáticos</sum1:DescripcionOperacion>
<sum1:Destinatarios>
<sum1:IDDestinatario>
<sum1:NombreRazon>Certificate Two Telematics</sum1:NombreRazon>
<sum1:NIF>89890002E</sum1:NIF>
<sum1:NombreRazon>CLIENTE TEST SA</sum1:NombreRazon>
<sum1:NIF>B12345678</sum1:NIF>
</sum1:IDDestinatario>
</sum1:Destinatarios>
<sum1:Desglose>
<sum1:DetalleDesglose>
<sum1:ClaveRegimen>01</sum1:ClaveRegimen>
<sum1:CalificacionOperacion>S1</sum1:CalificacionOperacion>
<sum1:TipoImpositivo>21</sum1:TipoImpositivo>
<sum1:BaseImponibleOimporteNoSujeto>500.00</sum1:BaseImponibleOimporteNoSujeto>
<sum1:CuotaRepercutida>105.00</sum1:CuotaRepercutida>
</sum1:DetalleDesglose>
</sum1:Desglose>
<sum1:CuotaTotal>105.00</sum1:CuotaTotal>
<sum1:ImporteTotal>605.00</sum1:ImporteTotal>
<sum1:SistemaInformatico>
<sum1:NombreRazon>INVOICE NINJA</sum1:NombreRazon>
<sum1:NIF>99999910G</sum1:NIF>
<sum1:NombreSistemaInformatico>InvoiceNinja</sum1:NombreSistemaInformatico>
<sum1:IdSistemaInformatico>001</sum1:IdSistemaInformatico>
<sum1:Version>5.0</sum1:Version>
<sum1:NumeroInstalacion>001</sum1:NumeroInstalacion>
<sum1:TipoUsoPosibleSoloVerifactu>S</sum1:TipoUsoPosibleSoloVerifactu>
<sum1:TipoUsoPosibleMultiOT>N</sum1:TipoUsoPosibleMultiOT>
<sum1:IndicadorMultiplesOT>N</sum1:IndicadorMultiplesOT>
</sum1:SistemaInformatico>
<sum1:FechaHoraHusoGenRegistro>2025-06-24T22:40:00+01:00</sum1:FechaHoraHusoGenRegistro>
<sum1:TipoHuella>01</sum1:TipoHuella>
<sum1:Huella>PLACEHOLDER_HUELLA</sum1:Huella>
</sum1:RegistroAlta>
</sum:RegistroFactura>
</sum:RegFactuSistemaFacturacion>
</soapenv:Body>
</soapenv:Envelope>
XML;
// Calculate the correct hash for the XML content
$xmlForHash = $this->getXmlForHashCalculation($soapXml);
$correctHash = strtoupper(hash('sha256', $xmlForHash));
// Replace the placeholder with the correct hash
$soapXml = str_replace('PLACEHOLDER_HUELLA', $correctHash, $soapXml);
\Log::info('Brand new invoice - Calculated hash: ' . $correctHash);
// Try the Sello endpoint for certificate-based access
$endpoint = 'https://prewww10.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP';
$certPath = storage_path('aeat-cert2.pem');
$keyPath = storage_path('aeat-key2.pem');
// Sign the XML
$signingService = new \App\Services\EDocument\Standards\Verifactu\Signing\SigningService($soapXml, file_get_contents($keyPath), file_get_contents($certPath));
$soapXml = $signingService->sign();
// Send the request
$response = Http::withHeaders([
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => '',
])
->withOptions([
'cert' => $certPath,
'ssl_key' => $keyPath,
'verify' => false,
'timeout' => 30,
])
->post($endpoint, $soapXml);
\Log::info('Brand new invoice request:');
\Log::info($soapXml);
\Log::info('Brand new invoice response:');
\Log::info('Response Status: ' . $response->status());
\Log::info('Response Headers: ' . json_encode($response->headers()));
\Log::info('Response Body: ' . $response->body());
// Check if the response contains an error
$responseBody = $response->body();
if (strpos($responseBody, 'Error interno en el servidor') !== false) {
\Log::error('SOAP response contains server error: ' . $responseBody);
$this->fail('SOAP response contains server error: ' . $responseBody);
}
// Check if the response contains a success message
if (strpos($responseBody, 'RegFactuSistemaFacturacionResponse') !== false) {
\Log::info('SOAP response contains success message');
}
$this->assertTrue($response->successful());
}
public function test_send_official_example_to_verifactu()
{
// Use the exact structure from the official AEAT example
$soapXml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sum="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd"
xmlns:sum1="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd">
<soapenv:Header/>
<soapenv:Body>
<sum:RegFactuSistemaFacturacion>
<sum:Cabecera>
<sum1:ObligadoEmision>
<sum1:NombreRazon>99999910G</sum1:NombreRazon>
<sum1:NIF>99999910G</sum1:NIF>
</sum1:ObligadoEmision>
</sum:Cabecera>
<sum:RegistroFactura>
<sum1:RegistroAlta>
<sum1:IDVersion>1.0</sum1:IDVersion>
<sum1:IDFactura>
<sum1:IDEmisorFactura>99999910G</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>24-06-2025</sum1:FechaExpedicionFactura>
</sum1:IDFactura>
<sum1:NombreRazonEmisor>99999910G</sum1:NombreRazonEmisor>
<sum1:TipoFactura>F1</sum1:TipoFactura>
<sum1:DescripcionOperacion>Test invoice following official example</sum1:DescripcionOperacion>
<sum1:Destinatarios>
<sum1:IDDestinatario>
<sum1:NombreRazon>B12345678</sum1:NombreRazon>
<sum1:NIF>B12345678</sum1:NIF>
</sum1:IDDestinatario>
</sum1:Destinatarios>
<sum1:Desglose>
@ -275,38 +315,31 @@ XML;
<sum1:BaseImponibleOimporteNoSujeto>100.00</sum1:BaseImponibleOimporteNoSujeto>
<sum1:CuotaRepercutida>21.00</sum1:CuotaRepercutida>
</sum1:DetalleDesglose>
<sum1:DetalleDesglose>
<sum1:ClaveRegimen>05</sum1:ClaveRegimen>
<sum1:CalificacionOperacion>S1</sum1:CalificacionOperacion>
<sum1:TipoImpositivo>10</sum1:TipoImpositivo>
<sum1:BaseImponibleOimporteNoSujeto>100.00</sum1:BaseImponibleOimporteNoSujeto>
<sum1:CuotaRepercutida>10.00</sum1:CuotaRepercutida>
</sum1:DetalleDesglose>
</sum1:Desglose>
<sum1:CuotaTotal>31.40</sum1:CuotaTotal>
<sum1:ImporteTotal>241.40</sum1:ImporteTotal>
<sum1:CuotaTotal>21.40</sum1:CuotaTotal>
<sum1:ImporteTotal>131.40</sum1:ImporteTotal>
<sum1:Encadenamiento>
<sum1:RegistroAnterior>
<sum1:IDEmisorFactura>89890001K</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>12345677-G33</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>15-04-2024</sum1:FechaExpedicionFactura>
<sum1:Huella>C9AF4AF1EF5EBBA700350DE3EEF12C2D355C56AC56F13DB2A25E0031BD2B7ED5</sum1:Huella>
<sum1:IDEmisorFactura>99999910G</sum1:IDEmisorFactura>
<sum1:NumSerieFactura>44</sum1:NumSerieFactura>
<sum1:FechaExpedicionFactura>24-06-2025</sum1:FechaExpedicionFactura>
<sum1:Huella>HuellaRegistroAnterior</sum1:Huella>
</sum1:RegistroAnterior>
</sum1:Encadenamiento>
<sum1:SistemaInformatico>
<sum1:NombreRazon>CERTIFICATE ONE TELEMATICAS</sum1:NombreRazon>
<sum1:NIF>89890001K</sum1:NIF>
<sum1:NombreSistemaInformatico>SystemName</sum1:NombreSistemaInformatico>
<sum1:NombreRazon>99999910G</sum1:NombreRazon>
<sum1:NIF>99999910G</sum1:NIF>
<sum1:NombreSistemaInformatico>InvoiceNinja</sum1:NombreSistemaInformatico>
<sum1:IdSistemaInformatico>77</sum1:IdSistemaInformatico>
<sum1:Version>1.0.03</sum1:Version>
<sum1:NumeroInstalacion>383</sum1:NumeroInstalacion>
<sum1:TipoUsoPosibleSoloVerifactu>S</sum1:TipoUsoPosibleSoloVerifactu>
<sum1:TipoUsoPosibleMultiOT>N</sum1:TipoUsoPosibleMultiOT>
<sum1:IndicadorMultiplesOT>N</sum1:IndicadorMultiplesOT>
<sum1:TipoUsoPosibleSoloVerifactu>N</sum1:TipoUsoPosibleSoloVerifactu>
<sum1:TipoUsoPosibleMultiOT>S</sum1:TipoUsoPosibleMultiOT>
<sum1:IndicadorMultiplesOT>S</sum1:IndicadorMultiplesOT>
</sum1:SistemaInformatico>
<sum1:FechaHoraHusoGenRegistro>2025-02-03T14:30:00+01:00</sum1:FechaHoraHusoGenRegistro>
<sum1:FechaHoraHusoGenRegistro>2025-06-24T22:40:00+01:00</sum1:FechaHoraHusoGenRegistro>
<sum1:TipoHuella>01</sum1:TipoHuella>
<sum1:Huella>FF954378B64ED331A9B2366AD317D86E9DEC1716B12DD0ACCB172A6DC4C105AA</sum1:Huella>
<sum1:Huella>PLACEHOLDER_HUELLA</sum1:Huella>
</sum1:RegistroAlta>
</sum:RegistroFactura>
</sum:RegFactuSistemaFacturacion>
@ -314,11 +347,25 @@ XML;
</soapenv:Envelope>
XML;
// Try the alternative test endpoint (prewww10.aeat.es)
$endpoint = 'https://prewww10.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP';
$certPath = storage_path('aeat-cert.pem');
$keyPath = storage_path('aeat-key.pem');
// Calculate the correct hash for the XML content
$xmlForHash = $this->getXmlForHashCalculation($soapXml);
$correctHash = strtoupper(hash('sha256', $xmlForHash));
// Replace the placeholder with the correct hash
$soapXml = str_replace('PLACEHOLDER_HUELLA', $correctHash, $soapXml);
\Log::info('Official example - Calculated hash: ' . $correctHash);
// Try the standard Verifactu endpoint
$endpoint = 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP';
$certPath = storage_path('aeat-cert2.pem');
$keyPath = storage_path('aeat-key2.pem');
// Sign the XML
$signingService = new \App\Services\EDocument\Standards\Verifactu\Signing\SigningService($soapXml, file_get_contents($keyPath), file_get_contents($certPath));
$soapXml = $signingService->sign();
// Send the request
$response = Http::withHeaders([
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => '',
@ -326,15 +373,30 @@ XML;
->withOptions([
'cert' => $certPath,
'ssl_key' => $keyPath,
'verify' => false, // Optional: disable CA verification for testing
'verify' => false,
'timeout' => 30,
])
->post($endpoint, $soapXml);
\Log::info('Request to alternative endpoint (prewww10.aeat.es):');
\Log::info('Official example request:');
\Log::info($soapXml);
\Log::info('Response from alternative endpoint:');
\Log::info($response->body());
\Log::info('Status code: ' . $response->status());
\Log::info('Official example response:');
\Log::info('Response Status: ' . $response->status());
\Log::info('Response Headers: ' . json_encode($response->headers()));
\Log::info('Response Body: ' . $response->body());
// Check if the response contains an error
$responseBody = $response->body();
if (strpos($responseBody, 'Error interno en el servidor') !== false) {
\Log::error('SOAP response contains server error: ' . $responseBody);
$this->fail('SOAP response contains server error: ' . $responseBody);
}
// Check if the response contains a success message
if (strpos($responseBody, 'RegFactuSistemaFacturacionResponse') !== false) {
\Log::info('SOAP response contains success message');
}
$this->assertTrue($response->successful());
}
}

View File

@ -1,24 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIEATCCAumgAwIBAgI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rgsx011CCkeqAEbUa9vIp+nQNYQ7t1eIWYLzar3mTvbyTofplhlr3B
yue5kTHOmCdDY24BigbBix730/BKwzi48Pga3wtD0Yj1hr16rm7esusIYOAJJbJD
7U/KAICry0JaNZmTKNZPU55fHF8BR4mwp5eiapBl9nlHgXrwFQief/2YCLB19fa4
NeuZH4PCpXAeAk7PsPuIi8IFtD588HSDSraXe4ex185H1SL7N9rG2JTjqAO3tzrq
pt/+9gZUkhzJb4kywzQHvuaIEyGhr8cShvpnk4lklCyHG2tTN/jrtCpqdSOAWVgV
iQIDAQAB
-----END PUBLIC KEY-----