Download the PHP package pedrocasado/nfse-php without Composer
On this page you can find all versions of the php package pedrocasado/nfse-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pedrocasado/nfse-php
More information about pedrocasado/nfse-php
Files in pedrocasado/nfse-php
Package nfse-php
Short Description Lib to communicate with Sistema Nacional (NFS-e)
License LGPL-3.0-or-later GPL-3.0-or-later MIT
Informations about the package nfse-php
NFSePHP
Library to communicate with the Sistema Nacional da NFS-e (Sefin Nacional): create and cancel NFS-e via the national REST API.
Version 3 is a complete refactor from v2. It targets the Sefin Nacional environment only (no Nota Carioca or other SOAP providers). DPS and evento XML follow the official XSDs; certificate-based signing and optional PSR-3 logging are built in.
Install
Certificate
Use a PFX (PKCS#12) certificate issued for your company. The library needs the PFX binary content and password (e.g. read from file or env).
Create NFS-e (DPS)
Build an InfDpsDTO (prestador, tomador, serviço, valores, competência, etc.), then call createNFSe. The service builds the DPS XML, signs it, optionally validates against the XSD, then sends it gzip+base64 to the Sefin endpoint. Environment (homolog/prod) is taken from InfDpsDTO->tpAmb (1 = production, 2 = homologation) unless you override the base URL.
Cancel NFS-e (Evento)
Use EventoCancelamentoDTO with the NFS-e key, author (CNPJ or CPF), reason code and description, then call cancelNFSe. The service builds the evento XML (pedRegEvento layout per schema 1.00), signs infPedReg, sends it gzip+base64 to /{chave}/eventos.
Configuration
-
Endpoint
By default the base URL is chosen fromtpAmb(1 → production, 2 → homologation). You can override it when constructingDpsService: -
Logger (PSR-3)
Pass aPsr\Log\LoggerInterfaceto send debug output (XML dumps, validation errors, request URLs) to your app logger: -
Debug flag
If you don’t inject a logger but set$debug = true, the same information is written to stderr. -
DTO validation
createNFSe(infDpsDTO: $dto, validateDTOs: true)runs Symfony Validator onInfDpsDTO(and nested DTOs). UsevalidateDTOs: falseto skip. - XSD validation
When enabled (e.g. in debug), the signed DPS and evento XML are validated against the bundled XSDs. On failure anInvalidXSDExceptionis thrown (or only logged, depending on flow).
Response parsing
-
DPS
DpsResponseholdsstatusCode,rawBody, and optionalresponse(SefinNacionalResponse). Useresponse->isSuccess()/response->isError(),response->getErros(),response->getNfseXml(). - Evento
EventoResponseholdsstatusCode,rawBody, and optionalresponse(EventoCancelamentoResponseDTO). Useresponse->getEventoXml()to decode the returned gzip+base64 evento XML.
The Sefin API can return errors in erro or erros, with codigo/Codigo and descricao/Descricao; the library normalizes these when parsing.
Tests
Tests cover DTOs (including validation), response parsing (Sefin and Evento), and response helpers. See tests/README.md for details and ideas for XML-building tests.
Changelog / v2 → v3
- Target: Sefin Nacional (REST, JSON body, gzip+base64 XML). No Nota Carioca or SOAP.
- DPS: Build from
InfDpsDTO, signinfDPS, POST to Sefin; response parsed intoSefinNacionalResponse. - Cancelamento: Evento de cancelamento (e101101) with
pedRegEvento/infPedReglayout (schema 1.00), signinfPedReg, POST to/{chave}/eventos. - Certificate: PFX content + password; PEM paths used for HTTP client mTLS.
- Logging: Optional PSR-3 logger or
$debugstderr fallback. - Validation: Symfony Validator on DTOs; optional XSD validation for signed XML.
License
LGPL-3.0-or-later / GPL-3.0-or-later / MIT.
All versions of nfse-php with dependencies
ext-curl Version *
ext-dom Version *
ext-libxml Version *
ext-openssl Version *
ext-xml Version *
ext-zlib Version *
symfony/serializer Version ^7.4|^8.0
symfony/http-client Version ^7.4|^8.0
symfony/validator Version ^7.4|^8.0
nfephp-org/sped-common Version ^5.1
psr/log Version ^3.0