1. Go to this page and download the library: Download devaction/cnpja-php 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/ */
// Retornam string com bytes PNG
$png = $client->getOfficeMap('37335118000180', ['zoom' => 17, 'width' => 640]);
$png = $client->getOfficeStreetView('37335118000180', ['fov' => 90, 'width' => 640]);
// Salvar em disco
file_put_contents('mapa.png', $png);
use Cnpja\Params\GetRfbParams;
use Cnpja\Params\CacheParams;
$rfb = $client->getRfb('37335118000180', new GetRfbParams(
cache: new CacheParams(strategy: 'CACHE_IF_ERROR'),
));
$rfb->taxId; // "37335118000180"
$rfb->name; // "CNPJA TECNOLOGIA LTDA"
$rfb->equity; // 1000.0
$rfb->nature->text; // "Sociedade Empresária Limitada"
$rfb->size->acronym; // "ME"
$rfb->jurisdiction; // "Uniao"
$rfb->status->text; // "Ativa"
$rfb->address->city; // "São Paulo"
$rfb->members[0]->person->name; // "João Silva"
// PDF do comprovante (bytes brutos)
$pdf = $client->getRfbCertificate('37335118000180', pages: 'REGISTRATION,MEMBERS');
file_put_contents('rfb.pdf', $pdf);
use Cnpja\Params\GetSimplesParams;
use Cnpja\Params\CacheParams;
$simples = $client->getSimples('37335118000180', new GetSimplesParams(
history: true, // +1 crédito — inclui histórico de períodos
cache: new CacheParams(strategy: 'CACHE_IF_ERROR'),
));
$simples->taxId; // "37335118000180"
$simples->simples->optant; // true
$simples->simples->since; // "2020-06-05"
$simples->simei->optant; // false
// Histórico de exclusões
foreach ($simples->simples->history as $entry) {
$entry->from; // "2012-12-26"
$entry->until; // "2013-12-31"
$entry->text; // "Excluída por Ato Administrativo..."
}
// PDF do comprovante
$pdf = $client->getSimplesCertificate('37335118000180');
use Cnpja\Params\GetCccParams;
use Cnpja\Params\CacheParams;
$ccc = $client->getCcc('37335118000180', 'ALL', new GetCccParams(
source: 'CCC',
cache: new CacheParams(strategy: 'CACHE_IF_ERROR'),
));
$ccc->taxId; // "37335118000180"
$ccc->originState; // "PR"
foreach ($ccc->registrations as $reg) {
$reg->number; // "0962101427"
$reg->state; // "RS"
$reg->enabled; // true
$reg->statusDate; // "2021-01-21"
$reg->status->text; // "Bloqueado como destinatário na UF"
$reg->type->text; // "IE Substituto Tributário"
}
// PDF do comprovante
$pdf = $client->getCccCertificate('37335118000180', state: 'SP');
use Cnpja\Params\GetSuframaParams;
use Cnpja\Params\CacheParams;
$suframa = $client->getSuframa('37335118000180', new GetSuframaParams(
cache: new CacheParams(strategy: 'CACHE_IF_ERROR'),
));
$suframa->taxId; // "37335118000180"
$suframa->number; // "200400029"
$suframa->name; // "CNPJA TECNOLOGIA LTDA"
$suframa->approved; // true
$suframa->approvalDate; // "2021-01-01"
$suframa->status->text; // "Ativa"
foreach ($suframa->incentives as $incentive) {
$incentive->tribute; // "IPI"
$incentive->benefit; // "Isenção"
$incentive->purpose; // "Consumo Interno, Industrialização..."
$incentive->basis; // "Decreto 7.212 de 2010 (Art. 81)"
}
// PDF do comprovante
$pdf = $client->getSuframaCertificate('37335118000180');
use Cnpja\Exceptions\UnauthorizedException;
use Cnpja\Exceptions\NotFoundException;
use Cnpja\Exceptions\RateLimitException;
use Cnpja\Exceptions\ValidationException;
use Cnpja\Exceptions\ServiceUnavailableException;
try {
$office = $client->getOffice('37335118000180');
} catch (UnauthorizedException $e) {
// 401 — chave de API inválida ou ausente
echo $e->getMessage();
} catch (NotFoundException $e) {
// 404 — CNPJ não encontrado
echo $e->getMessage();
} catch (RateLimitException $e) {
// 429 — créditos insuficientes ou limite por minuto excedido
echo "Necessário: {$e->
use Cnpja\Params\CacheParams;
$cache = new CacheParams(
strategy: 'CACHE_IF_ERROR',
maxAge: 45, // dias — idade máxima do cache aceita
maxStale: 365, // dias — idade máxima aceita em caso de falha online
sync: false, // aguardar compensação síncrona de créditos
);