From 54ba4349f60c88e2cf6f93386eb06abaf371fa96 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 22 Jun 2025 10:33:26 +1000 Subject: [PATCH] Tests for verifactu --- .../EInvoice/Verifactu/Models/WSTest.php | 340 ++++++++++++++++++ 1 file changed, 340 insertions(+) create mode 100644 tests/Feature/EInvoice/Verifactu/Models/WSTest.php diff --git a/tests/Feature/EInvoice/Verifactu/Models/WSTest.php b/tests/Feature/EInvoice/Verifactu/Models/WSTest.php new file mode 100644 index 0000000000..152055ff60 --- /dev/null +++ b/tests/Feature/EInvoice/Verifactu/Models/WSTest.php @@ -0,0 +1,340 @@ + + + + + + + + Certificate One Telematics + 89890001K + + + + + 1.0 + + 89890001K + 12345678-G66 + 03-02-2025 + + Certificate One Telematics + N + N + R3 + I + + + 89890001K + 12345600-G66 + 01-04-2024 + + + 03-02-2025 + delivery date + + + Certificate Two Telematics + 89890002E + + + + + 01 + S1 + 4 + 10.00 + 0.40 + + + 01 + S1 + 21 + 100.00 + 21.00 + + + 05 + S1 + 10 + 100.00 + 10.00 + + + 31.40 + 241.40 + + + 89890001K + 12345677-G33 + 15-04-2024 + C9AF4AF1EF5EBBA700350DE3EEF12C2D355C56AC56F13DB2A25E0031BD2B7ED5 + + + + CERTIFICATE ONE TELEMATICAS + 89890001K + SystemName + 77 + 1.0.03 + 383 + S + N + N + + 2025-02-03T14:30:00+01:00 + 01 + FF954378B64ED331A9B2366AD317D86E9DEC1716B12DD0ACCB172A6DC4C105AA + + + + + +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 = << + + + + + + + XXXXX + 99999910G + + + + + 1.0 + + 99999910G + 12345 + 13-09-2024 + + XXXXX + F1 + Descripc + + + YYYY + BBBB + + + + + 01 + S1 + 21 + 100.00 + 21.00 + + + 21.00 + 121.00 + + S + + + SSSS + 99999910G + NombreSistemaInformatico + 77 + 1.0.03 + 383 + N + S + S + + 2024-09-13T19:20:30+01:00 + 01 + Huella + + + + + +XML; + + $endpoint = 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP'; + + $response = Http::withHeaders([ + 'Content-Type' => 'text/xml; charset=utf-8', + 'SOAPAction' => '', + ]) + ->withOptions([ + 'verify' => false, // Optional: disable CA verification for testing + ]) + ->post($endpoint, $soapXml); + + \Log::info('Request without certificate:'); + \Log::info($soapXml); + \Log::info('Response without certificate:'); + \Log::info($response->body()); + \Log::info('Status code: ' . $response->status()); + + // This might fail, but we want to see the response + $this->assertTrue(true); // Just to see the response + } + + public function test_send_aeat_example_to_alternative_endpoint() + { + $soapXml = << + + + + + + + Certificate One Telematics + 89890001K + + + + + 1.0 + + 89890001K + 12345678-G66 + 03-02-2025 + + Certificate One Telematics + N + N + R3 + I + + + 89890001K + 12345600-G66 + 01-04-2024 + + + 03-02-2025 + delivery date + + + Certificate Two Telematics + 89890002E + + + + + 01 + S1 + 4 + 10.00 + 0.40 + + + 01 + S1 + 21 + 100.00 + 21.00 + + + 05 + S1 + 10 + 100.00 + 10.00 + + + 31.40 + 241.40 + + + 89890001K + 12345677-G33 + 15-04-2024 + C9AF4AF1EF5EBBA700350DE3EEF12C2D355C56AC56F13DB2A25E0031BD2B7ED5 + + + + CERTIFICATE ONE TELEMATICAS + 89890001K + SystemName + 77 + 1.0.03 + 383 + S + N + N + + 2025-02-03T14:30:00+01:00 + 01 + FF954378B64ED331A9B2366AD317D86E9DEC1716B12DD0ACCB172A6DC4C105AA + + + + + +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'); + + $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 to alternative endpoint (prewww10.aeat.es):'); + \Log::info($soapXml); + \Log::info('Response from alternative endpoint:'); + \Log::info($response->body()); + \Log::info('Status code: ' . $response->status()); + $this->assertTrue($response->successful()); + } +} \ No newline at end of file