The following services form the internal infrastructure of the library. Under normal usage they are called automatically byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Eseperio/verifactu-php/llms.txt
Use this file to discover all available pages before exploring further.
VerifactuService — you rarely need to interact with them directly. Each section notes whether direct use is recommended.
CertificateManagerService
Namespace:eseperio\verifactu\services\CertificateManagerService
Handles loading, parsing, and validating the digital certificate (.pfx, .p12, or .pem) used for XML signing and SOAP mutual-TLS authentication. Supports both PHP’s built-in openssl_pkcs12_read() and an automatic CLI fallback (openssl pkcs12 -legacy) for older PKCS#12 bundles encrypted with RC2-40.
Direct use: Optional. Most applications let VerifactuService manage certificates automatically. Call these methods directly when you want to pre-validate a certificate at deployment time.
getCertificate($certPath, $certPassword = ''): string|false
Extracts and returns the X.509 certificate block in PEM format (-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----).
\RuntimeException if the file is not found, the password is wrong, or the format is unsupported.
getPrivateKey($certPath, $certPassword = ''): string|null
Extracts and returns the private key in PEM format. Returns null if the private key could not be extracted from a PFX/P12 bundle.
isValid($certPath, $certPassword = ''): bool
Returns true if the certificate is currently within its validity window (validFrom ≤ now ≤ validTo).
createSoapCompatiblePemTemp(string $certPath, string $certPassword = ''): string
Combines the certificate and private key into a single PEM file in the system temp directory, sets permissions to 0600, and registers a PHP shutdown function to delete it. Returns the absolute path to the temporary file.
This is the method called internally by VerifactuService before creating the SoapClient — PHP’s SoapClient requires a combined PEM file when using mutual TLS.
\RuntimeException if the temp file cannot be written.
SoapClientFactoryService
Namespace:eseperio\verifactu\services\SoapClientFactoryService
Creates and configures a PHP \SoapClient instance for communicating with the AEAT VERI*FACTU endpoints. Configures mutual TLS using the combined PEM produced by CertificateManagerService::createSoapCompatiblePemTemp().
Direct use: Rarely needed. VerifactuService creates the client lazily on first operation and caches it. Use directly when building a custom SOAP pipeline.
createSoapClient(string $wsdl, string $certPath, string $certPassword, array $options = []): \SoapClient
Path or URL to the AEAT WSDL file. Local file paths are automatically prefixed with
file:// so that libxml can resolve relative imports within the WSDL.Path to the combined PEM file produced by
createSoapCompatiblePemTemp(). This is set as local_cert in the SoapClient options.Certificate passphrase (set as
passphrase in SoapClient options). Pass '' for unprotected PEM files.Additional
SoapClient constructor options that override or extend the defaults. Use ['location' => '<url>'] to override the SOAP endpoint (e.g. for the AEAT pre-production environment).SoapClient options applied:
| Option | Value |
|---|---|
trace | 1 (enables __getLastRequest() / __getLastResponse()) |
exceptions | true |
local_cert | $certPath |
passphrase | $certPassword |
cache_wsdl | WSDL_CACHE_NONE |
\RuntimeException if the certificate file is not found or SoapClient construction fails.
ResponseParserService
Namespace:eseperio\verifactu\services\ResponseParserService
Parses the raw SOAP XML response returned by the AEAT web service into strongly-typed PHP model objects. Uses DOMDocument and DOMXPath with local-name() queries to avoid namespace binding issues.
Direct use: Unlikely. VerifactuService always calls the appropriate parse method after each SOAP operation.
parseInvoiceResponse($xmlResponse): InvoiceResponse
Parses the response to a RegFactuSistemaFacturacion call (both registration and cancellation) and returns an InvoiceResponse.
InvoiceResponse properties:
| Property | Type | Description |
|---|---|---|
csv | string|null | Secure verification code (Código Seguro de Verificación). |
header | array|null | Parsed Cabecera block as an associative array. |
waitTime | string|null | TiempoEsperaEnvio — throttling wait time in seconds. |
submissionStatus | string|null | EstadoEnvio — overall status of the submission batch. |
submissionData | array|null | DatosPresentacion block as an associative array. |
lineResponses | array | Array of per-invoice line response objects (see above). |
\RuntimeException if the XML response cannot be parsed.
parseQueryResponse($xmlResponse): QueryResponse
Parses the response to a ConsultaFactuSistemaFacturacion call and returns a QueryResponse.
QueryResponse properties:
| Property | Type | Description |
|---|---|---|
header | array|null | Parsed Cabecera block. |
period | array|null | PeriodoImputacion block (year and period). |
paginationIndicator | string|null | IndicadorPaginacion — "S" if additional pages are available. |
queryResult | string|null | ResultadoConsulta — "ConDatos" or "SinDatos". |
foundRecords | array | Array of matching invoice records as associative arrays. |
paginationKey | array|null | ClavePaginacion — pass this in the next query to retrieve the next page. |
EventDispatcherService
Namespace:eseperio\verifactu\services\EventDispatcherService
Submits system events (RegistroEvento) to the AEAT VERI*FACTU event endpoint. Spanish law requires that certain computer system events — such as system startup, shutdown, and configuration changes — be reported to the tax authority via the EventosSIF SOAP operation.
Direct use: Required for applications that must comply with the computer system event reporting obligation. This service is not called by VerifactuService.
dispatch(EventRecord $event, array $config): InvoiceResponse
Validates, serialises, signs, and submits an EventRecord to AEAT. Uses the same signing and SOAP infrastructure as VerifactuService.
The event record to dispatch. Must pass its own
validate() check.Configuration array with the following required keys:
wsdl— path or URL to the AEAT WSDL.certPath— path to the digital certificate.certPassword— certificate password.
InvoiceResponse — the parsed AEAT response for the event submission.
Throws:
\InvalidArgumentException—EventRecordvalidation failed.\SoapFault— SOAP-level error from the AEAT endpoint.
- Validate
EventRecord. - Serialise to
RegistroEventoXML via the internalbuildEventXml()method. - Sign with
XmlSignerService::signXml(). - Create a
SoapClientviaSoapClientFactoryService(with a PEM temp file fromCertificateManagerService). - Call the
EventosSIFSOAP operation. - Parse and return via
ResponseParserService::parseInvoiceResponse().
InvoiceSerializer
Namespace:eseperio\verifactu\services\InvoiceSerializer
Converts the PHP model objects (InvoiceSubmission, InvoiceCancellation, InvoiceQuery) into DOMDocument instances that conform to the AEAT SuministroInformacion.xsd, SuministroLR.xsd, and ConsultaLR.xsd schemas. All monetary amounts are formatted to 2 decimal places with a dot separator; dates are converted from YYYY-MM-DD to the DD-MM-YYYY format required by AEAT.
Direct use: Unlikely in application code. VerifactuService calls these methods automatically. You may call them directly for debugging, pre-validation, or integration testing.
Namespace constants
| Constant | Value |
|---|---|
SF_NAMESPACE | https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroInformacion.xsd |
SFLR_NAMESPACE | https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd |
QUERY_NAMESPACE | https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/ConsultaLR.xsd |
DS_NAMESPACE | http://www.w3.org/2000/09/xmldsig# |
toInvoiceXml(InvoiceSubmission $invoice, bool $validate = false): \DOMDocument
Serialises an InvoiceSubmission to a RegistroAlta DOM document.
$validate = true the output is validated against SuministroInformacion.xsd; throws \Exception if invalid.
toCancellationXml(InvoiceCancellation $cancellation, bool $validate = false): \DOMDocument
Serialises an InvoiceCancellation to a RegistroAnulacion DOM document.
toQueryXml(InvoiceQuery $query, bool $validate = true): \DOMDocument
Serialises an InvoiceQuery to a ConsultaFactuSistemaFacturacion DOM document.
$validate = true).
wrapXmlWithRegFactuStructure(\DOMDocument $doc, string $nif, string $name, ?string $fechaFinVeriFactu = null): \DOMDocument
Wraps a RegistroAlta or RegistroAnulacion DOM document inside the top-level sfLR:RegFactuSistemaFacturacion envelope required by the SOAP body. Adds the Cabecera block with ObligadoEmision (issuer NIF and name) and optionally a RemisionVoluntaria / FechaFinVeriFactu element.
formatDate(string $date): string
Converts YYYY-MM-DD to DD-MM-YYYY. If the input is already in DD-MM-YYYY format (or any other format), it is returned unchanged.