Pular para o conteúdo principal

NFS-e Nacional PHP

Uma biblioteca robusta e agnóstica para emissão de notas (Contribuinte) e gestão fiscal (Município), construída sobre a nova API Nacional.

Exemplo Rápido: Emitindo uma Nota (DPS)

use Nfse\Dto\Nfse\DpsData;
use Nfse\Support\IdGenerator;

// 1. Gere o ID único
$id = IdGenerator::generateDpsId('CNPJ_TRESTADOR', 'COD_MUN', 'SERIE', 'NUMERO');

// 2. Crie o objeto DPS
$dps = new DpsData([
'@attributes' => ['versao' => '1.00'],
'infDPS' => [
'@attributes' => ['Id' => $id],
'tpAmb' => 2,
'dhEmi' => date('Y-m-d\TH:i:s'),
'verAplic' => 'App 1.0',
'serie' => '1',
'nDPS' => '1001',
'dCompet' => date('Y-m-d'),
'tpEmit' => 1,
'cLocEmi' => '3550308', // São Paulo
'prest' => ['CNPJ' => '12345678000199'],
'toma' => [
'CPF' => '11122233344',
'xNome' => 'Tomador de Exemplo'
],
'serv' => [
'locPrest' => ['cLocPrestacao' => '3550308'],
'cServ' => [
'cTribNac' => '01.01',
'xDescServ' => 'Descrição do Serviço'
]
],
'valores' => [
'vServPrest' => [
'vReceb' => 100.00,
'vServ' => 100.00
],
'trib' => [
'tribMun' => [
'tribISSQN' => 1,
'tpRetISSQN' => 2, // Sem retenção
'pAliq' => 5.00
]
]
]
]
]);

// 3. Envie
try {
$nfseData = $contribuinte->emitir($dps);
echo "Sucesso! Nota emitida: " . $nfseData->infNfse->numeroNfse;
} catch (\Exception $e) {
echo "Erro: " . $e->getMessage();
}