From d7c03afb0cdbd3835c79482379d2805b3e9471e3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 26 Nov 2025 10:02:56 +1100 Subject: [PATCH] Minor fixes for pdfmock --- .../EmailPreferencesController.php | 22 ++++++------- .../Standards/Verifactu/AeatClient.php | 33 +++++++++++++++++-- app/Services/Pdf/PdfMock.php | 1 + 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/EmailPreferencesController.php b/app/Http/Controllers/ClientPortal/EmailPreferencesController.php index d2ef43fa20..0a858e6e29 100644 --- a/app/Http/Controllers/ClientPortal/EmailPreferencesController.php +++ b/app/Http/Controllers/ClientPortal/EmailPreferencesController.php @@ -40,20 +40,20 @@ class EmailPreferencesController extends Controller $class = "\\App\\Models\\" . ucfirst(Str::camel($entity)) . 'Invitation'; $invitation = $class::withTrashed()->where('key', $invitation_key)->firstOrFail(); - $invitation->contact->is_locked = $request->action === 'unsubscribe' ? true : false; - $invitation->contact->push(); + // $invitation->contact->is_locked = $request->action === 'unsubscribe' ? true : false; + // $invitation->contact->push(); - if ($invitation->contact->is_locked && !Cache::has("unsubscribe_notification_suppression:{$invitation_key}")) { - $nmo = new NinjaMailerObject(); - $nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($invitation->contact, $invitation->contact->company, true))->build()); - $nmo->company = $invitation->contact->company; - $nmo->to_user = $invitation->contact->company->owner(); - $nmo->settings = $invitation->contact->company->settings; + // if ($invitation->contact->is_locked && !Cache::has("unsubscribe_notification_suppression:{$invitation_key}")) { + // $nmo = new NinjaMailerObject(); + // $nmo->mailable = new NinjaMailer((new ClientUnsubscribedObject($invitation->contact, $invitation->contact->company, true))->build()); + // $nmo->company = $invitation->contact->company; + // $nmo->to_user = $invitation->contact->company->owner(); + // $nmo->settings = $invitation->contact->company->settings; - NinjaMailerJob::dispatch($nmo); + // NinjaMailerJob::dispatch($nmo); - Cache::put("unsubscribe_notification_suppression:{$invitation_key}", true, 3600); - } + // Cache::put("unsubscribe_notification_suppression:{$invitation_key}", true, 3600); + // } return back()->with('message', ctrans('texts.updated_settings')); } diff --git a/app/Services/EDocument/Standards/Verifactu/AeatClient.php b/app/Services/EDocument/Standards/Verifactu/AeatClient.php index 3dec6df1a6..18d5088582 100644 --- a/app/Services/EDocument/Standards/Verifactu/AeatClient.php +++ b/app/Services/EDocument/Standards/Verifactu/AeatClient.php @@ -14,10 +14,11 @@ namespace App\Services\EDocument\Standards\Verifactu; use Illuminate\Support\Facades\Http; use App\Services\EDocument\Standards\Verifactu\ResponseProcessor; +use App\Services\EDocument\Standards\Verifactu\Signing\SigningService; class AeatClient { - private string $base_url = 'https://www1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP'; + private string $base_url = 'https://www1.agenciatributaria.gob.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP'; private string $sandbox_url = 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP'; @@ -61,8 +62,34 @@ class AeatClient return $this; } + /** + * Sign SOAP envelope with XML Digital Signature + * + * @param string $xml - Unsigned SOAP envelope + * @return string - Signed SOAP envelope + */ + private function signSoapEnvelope(string $xml): string + { + try { + $signingService = new SigningService( + $xml, + file_get_contents($this->ssl_key), + file_get_contents($this->certificate) + ); + return $signingService->sign(); + } catch (\Exception $e) { + nlog("Error signing SOAP envelope: " . $e->getMessage()); + throw $e; + } + } + public function send($xml): array { + // Sign the SOAP envelope before sending + $signed_xml = $this->signSoapEnvelope($xml); + + nlog("AEAT Request URL: " . $this->base_url); + nlog("Signed SOAP envelope size: " . strlen($signed_xml) . " bytes"); $response = Http::withHeaders([ 'Content-Type' => 'text/xml; charset=utf-8', @@ -74,11 +101,13 @@ class AeatClient 'verify' => false, 'timeout' => 30, ]) - ->withBody($xml, 'text/xml') + ->withBody($signed_xml, 'text/xml') ->post($this->base_url); $success = $response->successful(); + nlog("AEAT Response HTTP Code: " . $response->status()); + $responseProcessor = new ResponseProcessor(); $parsedResponse = $responseProcessor->processResponse($response->body()); diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index ae11606c3c..45d98a6a19 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -957,6 +957,7 @@ class PdfMock '$contact.first_name' => 'Geo', '$company.vat_number' => 'vat number', '$contact.signature' => '', + '$verifactu_qr_code' => '', '$product.tax_name1' => '', '$product.tax_name2' => '', '$product.tax_name3' => '',