1. Go to this page and download the library: Download iberfacil/es-aeat-vnif library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iberfacil / es-aeat-vnif example snippets
use Iberfacil\AeatVnif\VnifClient;
use Iberfacil\AeatVnif\Data\Taxpayer;
use Iberfacil\AeatVnif\Data\TaxpayerName;
$client = VnifClient::create('/etc/aeat/certificado.p12', getenv('AEAT_VNIF_CERT_PASSWORD'));
// Una persona física: nombre y apellidos por separado
$result = $client->check('00000000T', TaxpayerName::naturalPerson('Zefira', 'Lumina', 'Peralvillo'));
$result->result; // IdentificationResult::Identified
$result->aeatResult; // 'IDENTIFICADO' (literal de la AEAT)
$result->isIdentified(); // true
$result->sentName; // 'LUMINA PERALVILLO ZEFIRA'
$result->censusName; // 'LUMINÁ PERALVILLO ZÉFIRA' (como figura en el censo)
$result->nameWasCorrected(); // false: las letras coinciden, solo cambian las tildes
// Una entidad
$result = $client->check('B00000000', TaxpayerName::entity('Brumalia Ficticia, S.L.'));
// Un lote: los resultados llegan en el mismo orden que la entrada
$results = $client->checkBatch([
Taxpayer::naturalPerson('00000000T', 'Zefira', 'Lumina', 'Peralvillo'),
Taxpayer::entity('B00000000', 'Brumalia Ficticia SL'),
]);
foreach ($results as $r) {
if ($r->failure !== null) {
// NO PROCESADO: reintentar este contribuyente más tarde
}
}
use Iberfacil\AeatVnif\VnifOptions;
$options = new VnifOptions(
endpoint: VnifOptions::DEFAULT_ENDPOINT,
batchSize: 500, // contribuyentes por petición (1..10000)
timeoutSeconds: 30,
retries: 2, // reintentos ante fallo transitorio de red
retryDelayMs: 500, // espera inicial, se duplica en cada intento
);
$client = VnifClient::create($ruta, $password, $options);
use Iberfacil\AeatVnif\Laravel\Facades\AeatVnif;
use Iberfacil\AeatVnif\Data\TaxpayerName;
$result = AeatVnif::check('00000000T', TaxpayerName::naturalPerson('Zefira', 'Lumina', 'Peralvillo'));