### NFe Workflow Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/README.md Demonstrates the typical steps involved in processing an NFe document, from configuration and creation to signing, transmission, and rendering. ```csharp // 1. Configure var config = new ConfiguracaoServico { ... }; // 2. Create document var nfe = new nfe { infNfe = new infNfe { ... } }; // 3. Sign var sig = AssinaturaDigital.Assina(nfe, id, cert); // 4. Transmit var resultado = servicos.NfeAutorizacao(new List { nfe }); // 5. Render var danfe = new DanfeNfceDocument(xmlString, logo); byte[] pdf = danfe.GeneratePdf(); ``` -------------------------------- ### Install libgdiplus on Ubuntu 18.x Source: https://github.com/hercules-net/zeusfiscal/blob/master/README.md Installs the necessary libgdiplus and libc6-dev libraries for printing on Ubuntu 18.x systems. ```bash apt-get install -y --no-install-recommends libgdiplus libc6-dev ``` -------------------------------- ### Complete ZeusFiscal Service Configuration Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Provides a comprehensive example of configuring all aspects of the ZeusFiscal service, including target settings, network timeouts, certificate details, XML validation, and auto-versioning. This configuration is used to instantiate the `ServicosNFe` service. ```csharp var configuracaoServico = new ConfiguracaoServico { // Target configuration cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, tpEmis = TipoEmissao.Normal, ModeloDocumento = ModeloDocumento.NFe, VersaoLayout = VersaoServico.Versao400, // Network and timeout TimeOut = 30000, // 30 seconds ProtocoloDeSeguranca = SecurityProtocolType.Tls12, ValidarCertificadoDoServidor = true, // Certificate Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Arquivo, Arquivo = @"C:\Certs\empresa.pfx", Senha = "senha123", ManterDadosEmCache = true, KeyStorageFlags = X509KeyStorageFlags.MachineKeySet, SignatureMethodSignedXml = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", DigestMethodReference = "http://www.w3.org/2001/04/xmlenc#sha256" }, // XML and Validation ValidarSchemas = true, SalvarXmlServicos = true, DiretorioSalvarXml = @"C:\Logs\XMLs", // Auto-versioning DefineVersaoServicosAutomaticamente = true, UnZip = true }; // Create service using (var servicos = new ServicosNFe(configuracaoServico)) { // Service calls... } ``` -------------------------------- ### Code Examples Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/COMPLETION.txt A collection of working code snippets demonstrating various functionalities, including NFe, CTe, MDFe examples, XML serialization, certificate configuration, and common workflows. ```APIDOC ## Code Examples - Minimal NFe example - Minimal CTe example - Minimal MDFe example - XML serialization - Certificate configuration (4 types) - Error handling patterns - Common workflows ``` -------------------------------- ### MDFe Service Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-mdfe-servicos.md Configuration setup for MDFe services using ConfiguracaoServico. This example shows how to set the document model, state, and environment type before initializing the ServicosMDFe client. ```csharp var config = ConfiguracaoServico.Instancia; config.ModeloDocumento = ModeloDocumento.MDFe; config.cUF = Estado.SP; config.tpAmb = TipoAmbiente.Producao; using (var servicos = new ServicosMDFe(config)) { // MDFe operations... } ``` -------------------------------- ### Install libgdiplus on Docker (Ubuntu 18.x) Source: https://github.com/hercules-net/zeusfiscal/blob/master/README.md Installs libgdiplus and related development libraries within a Dockerfile for Ubuntu 18.x. ```dockerfile RUN apt-get update \ && apt-get install -y --no-install-recommends libgdiplus libc6-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Example Usage of ConfiguracaoServico Singleton Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Demonstrates how to access the global configuration instance and modify its properties, such as setting the target state (cUF) and environment type (tpAmb). ```csharp // Access global configuration var config = ConfiguracaoServico.Instancia; config.cUF = Estado.SP; config.tpAmb = TipoAmbiente.Producao; ``` -------------------------------- ### Setup NFe Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md Configure the NFe service with your company's details, environment type, and digital certificate information. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Homologacao, // Test environment Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Arquivo, Arquivo = @"C:\\certs\\cert.pfx", Senha = "senha123" } }; ``` -------------------------------- ### Minimal MDFe Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md This snippet shows how to create and authorize an MDFe (Manifesto Eletrônico de Documentos Fiscais) document. It requires service configuration and a digital certificate. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Homologacao, ModeloDocumento = ModeloDocumento.MDFe, Certificado = new ConfiguracaoCertificado { /* ... */ } }; var mdfe = new mdfe { infMdfe = new infMdfe { ide = new ide { cUF = Estado.SP, dEmi = DateTime.Now, tpMDFe = TipoMdfe.Rodoviario }, emit = new emit { CNPJ = "12345678000190", xNome = "Transportadora" }, infModal = new infModal { versaoModal = "3.00", rodo = new rodo { /* Road transport details */ } }, infDoc = new infDoc { infNFe = new List { new infNFe { chNFe = "35200101234567000012340000000011234567890123" } } } } }; var cert = CertificadoDigital.ObterCertificado(config.Certificado); var signature = AssinaturaDigital.Assina(mdfe, mdfeId, cert); using (var servicos = new ServicosMDFe(config)) { var resultado = servicos.MdfeAutorizacao(new List { mdfe }); Console.WriteLine(resultado.cStat == "100" ? "Authorized" : "Failed"); } ``` -------------------------------- ### Certificate Loading Examples Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/README.md Shows how to load digital certificates for A1 (file-based) and A3 (hardware) types. Ensure correct file paths, passwords, and serial numbers are provided. ```csharp // File-based A1 var cert = CertificadoDigital.ObterCertificado( new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Arquivo, Arquivo = @"C:\cert.pfx", Senha = "password" }); // Hardware A3 var cert = CertificadoDigital.ObterCertificado( new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A3, Serial = "1234567890ABCDEF", Senha = "pin1234" }); ``` -------------------------------- ### Install Linux Rendering Dependencies Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-danfe.md Installs essential system libraries and fonts for FastReport rendering on Debian-based Linux distributions. Includes packages for graphics, printing, and specific fonts like Times New Roman. ```bash apt-get install -y libgdiplus libc6-dev libcups2-dev # For fonts (Times New Roman required by DANFE) apt-get install -y ttf-mscorefonts-installer fontconfig ``` -------------------------------- ### MDFe Document Rendering Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-mdfe-servicos.md Example demonstrating how to render an MDFe document using the DamdfeDoc class from the FastReport library. This includes loading an XML file and performing actions like previewing or printing. ```csharp var mdfeProc = FuncoesXml.ArquivoXmlParaClasse("mdfe-proc.xml"); var damdfe = new DamdfeDoc( mdfeProc, new ConfiguracaoDamdfe(/* ... */))); damdfe.Visualizar(); // Preview damdfe.Imprimir(); // Print ``` -------------------------------- ### Configure System Repository Certificate (A1Repositorio) Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Use this configuration for certificates installed in the Windows certificate store. The `Serial` number is required to identify the specific certificate. Ensure the certificate is installed in the location specified by `StoreLocation`. ```csharp // First, install certificate into Windows cert store var config = new ConfiguracaoServico { Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Repositorio, Serial = "1234567890ABCDEF", // Find via certmgr.msc StoreLocation = StoreLocation.CurrentUser } }; ``` -------------------------------- ### Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/COMPLETION.txt Comprehensive documentation for service and certificate configurations, including property details, type selection, algorithm options, and complete examples. ```APIDOC ## Configuration - ConfiguracaoServico: all 35+ properties - ConfiguracaoCertificado: all types and examples - Certificate type selection guide - Signature algorithm options - Complete configuration examples ``` -------------------------------- ### Minimal CTe Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md This snippet demonstrates how to create and authorize a CTe (Conhecimento de Transporte Eletrônico) document. Ensure you have the necessary configuration for the service and a valid digital certificate. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Homologacao, ModeloDocumento = ModeloDocumento.CTe, Certificado = new ConfiguracaoCertificado { /* ... */ } }; var cte = new cte { infCte = new infCte { ide = new ide { cUF = Estado.SP, dEmi = DateTime.Now, tpEmis = TipoEmissao.Normal, tpCte = TipoCte.Normal }, emit = new emit { CNPJ = "12345678000190", xNome = "Transportadora" }, dest = new dest { CNPJ = "98765432000111", xNome = "Destinatario" }, det = new det { /* Transport details */ } } }; var cert = CertificadoDigital.ObterCertificado(config.Certificado); var signature = AssinaturaDigital.Assina(cte, cteId, cert); using (var servicos = new ServicosCTe(config)) { var resultado = servicos.CteAutorizacao(new List { cte }); Console.WriteLine(resultado.cStat == "100" ? "Authorized" : "Failed"); } ``` -------------------------------- ### Install specific libgdiplus version on Debian 10 Source: https://github.com/hercules-net/zeusfiscal/blob/master/README.md Installs libgdiplus version 6.0.5 on Debian 10, which may resolve System.OutOfMemoryException errors. This involves adding the Mono project repository. ```bash RUN apt-get update && apt-get remove libgdiplus -y && apt autoremove -y && apt-get install -y apt-transport-https dirmngr gnupg ca-certificates RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF RUN echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list RUN apt-get update && apt-get install -y libgdiplus=6.0.5-0xamarin1+debian10b1 RUN apt show libgdiplus && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Add NFe to List Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/NFe.Danfe.Html/Readme.txt This code snippet shows how to add a constructed NFe XML string to a list of NFes. It includes commented-out lines for adding other NFe examples. ```csharp //listNfe.Add(list1); //listNfe.Add(list2); //listNfe.Add(list3); //listNfe.Add(list4); //listNfe.Add(list5); //listNfe.Add(list6); //listNfe.Add(list7); listNfe.Add(list8); ``` -------------------------------- ### Configure NFe Service Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-servicos.md Instantiates and configures the ConfiguracaoServico object for NFe services. This example sets up production environment, specifies the state, emission type, timeout, and certificate details. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, tpEmis = TipoEmissao.Normal, TimeOut = 30000, SalvarXmlServicos = true, DiretorioSalvarXml = @"C:\Temp\XMLs", Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Arquivo, Arquivo = @"C:\Certs\cert.pfx", Senha = "pwd123", ManterDadosEmCache = true } }; ``` -------------------------------- ### Load and Deserialize XML Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md Examples for loading and deserializing XML data into C# objects. Supports loading from a file or a string, with an option for lenient parsing that ignores element order. ```csharp // From file var nfeProc = FuncoesXml.ArquivoXmlParaClasse("nfe-proc.xml"); // From string string xml = File.ReadAllText("nfe.xml"); var nfe = FuncoesXml.XmlStringParaClasse(xml); // Lenient parsing (out-of-order elements) var nfe2 = FuncoesXml.XmlStringParaClasse(xml, ignorarOrdenacaoElementos: true); ``` -------------------------------- ### Instantiate EventoNfeDocument Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-danfe.md Instantiates the EventoNfeDocument with NFe XML, correction event XML, and an optional logo. Call GeneratePdf() to get the PDF bytes. ```csharp var nfeXml = FuncoesXml.ClasseParaXmlString(nfeProc); var eventoXml = FuncoesXml.ClasseParaXmlString(evento); var logo = File.ReadAllBytes("logo.png"); var documento = new EventoNfeDocument(nfeXml, eventoXml, logo); byte[] pdfBytes = documento.GeneratePdf(); ``` -------------------------------- ### Configure Registry Certificate (Windows Store) Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md Configure the service to use a certificate stored in the Windows certificate store. Provide the certificate serial number. Ensure the certificate is installed using certmgr.msc. ```csharp // First, install certificate to Windows cert store using certmgr.msc var config = new ConfiguracaoServico { Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Repositorio, Serial = "1234567890ABCDEF", // From Windows store StoreLocation = StoreLocation.CurrentUser } }; ``` -------------------------------- ### FastReport Preview and Print NFe DANFE Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-danfe.md Uses FastReport to preview or directly print an NFe DANFE. This example requires FastReport.Net DLLs or the FastReport NuGet package. ```csharp var nfeProc = FuncoesXml.ArquivoXmlParaClasse("nfe-proc.xml"); var danfe = new DanfeFrNfce( nfeProc, new ConfiguracaoDanfeNfce( NfceDetalheVendaNormal.DuasLinhas, NfceDetalheVendaContigencia.UmaLinha, null), "00001", "CAIXA001"); // Preview window danfe.Visualizar(); // Or print directly danfe.Imprimir(); ``` -------------------------------- ### Generate NFe DANFE to PDF with QuestPDF Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-danfe.md Loads an NFe from an XML file, creates a QuestPDF document, and generates a PDF file. Ensure you have the QuestPDF NuGet package installed. ```csharp // Load NFe from file var nfeProc = FuncoesXml.ArquivoXmlParaClasse("nfe-proc.xml"); // Create QuestPDF document var documento = new DanfeNfceDocument( FuncoesXml.ClasseParaXmlString(nfeProc), File.ReadAllBytes("logo.png")); documento.TamanhoImpressao(TamanhoImpressao.A4); // Generate PDF byte[] pdfBytes = documento.GeneratePdf(); // Save or send File.WriteAllBytes("danfe.pdf", pdfBytes); string base64 = Convert.ToBase64String(pdfBytes); ``` -------------------------------- ### Dockerfile for Linux Rendering Dependencies Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-danfe.md A Dockerfile snippet to set up a .NET 6.0 runtime environment with the necessary dependencies for FastReport-based DANFE rendering. It installs required libraries and fonts and cleans up package lists. ```dockerfile FROM mcr.microsoft.com/dotnet/runtime:6.0 RUN apt-get update && apt-get install -y --no-install-recommends \ libgdiplus libc6-dev libcups2-dev \ ttf-mscorefonts-installer fontconfig && \ apt-get clean && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Submit CTe for Authorization Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-cte-servicos.md Submits a list of signed CTe documents to the SEFAZ for authorization. The example shows the structure of a CTe object and how to obtain the authorization result, checking for a '100' status code indicating success. ```csharp var cte = new cte { infCte = new infCte { ide = new ide { cUF = Estado.SP, /* ... */ }, emit = new emit { CNPJ = "12345678000190", /* ... */ }, dest = new dest { CNPJ = "98765432000111", /* ... */ }, det = new det { /* Transport details */ } } }; // Sign CTe var signature = AssinaturaDigital.Assina( cte, "CTe35200101234567000012340000000011234567890123", cert); var cteList = new List { cte }; var resultado = servicos.CteAutorizacao(cteList); if (resultado.cStat == "100") Console.WriteLine("CTe authorized with protocol: " + resultado.protCte[0].infProt.nProt); ``` -------------------------------- ### Configure and Initialize Service Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/overview.md Demonstrates the common pattern for configuring and initializing a service class, such as ServicosNFe. Ensure your certificate configuration is correctly set up. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, tpEmis = TipoEmissao.Normal, Certificado = new ConfiguracaoCertificado { ... } }; var servicos = new ServicosNFe(config); var retorno = servicos.NfeAutorizacao(nfeList); ``` -------------------------------- ### Configure File-Based Certificate (A1Arquivo) Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Use this snippet to configure a certificate loaded from a .pfx or .p12 file. Ensure the `Arquivo` path is correct and the `Senha` is provided. `KeyStorageFlags` can be set for specific storage behaviors. ```csharp var config = new ConfiguracaoServico { Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1Arquivo, Arquivo = @"C:\Certs\empresa.pfx", Senha = "senha123", ManterDadosEmCache = true, KeyStorageFlags = X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet } }; ``` -------------------------------- ### Install Microsoft Core Fonts on Debian 10 Source: https://github.com/hercules-net/zeusfiscal/blob/master/README.md Installs the Microsoft Core Fonts package on Debian 10, including fontconfig for proper font handling. ```bash apt-get install -y ttf-mscorefonts-installer fontconfig ``` -------------------------------- ### Instantiate ServicosCTe with Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-cte-servicos.md Demonstrates how to create an instance of ServicosCTe using service configuration. The configuration object should specify the state, environment, document model, and certificate details. This instance is then used to call various CTe web service methods. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, ModeloDocumento = ModeloDocumento.CTe, Certificado = new ConfiguracaoCertificado { /* ... */ } }; using (var servicos = new ServicosCTe(config)) { var resultado = servicos.CteAutorizacao(cteList); } ``` -------------------------------- ### Install Microsoft Core Fonts on Ubuntu 18.x Source: https://github.com/hercules-net/zeusfiscal/blob/master/README.md Installs the Microsoft Core Fonts package on Ubuntu 18.x, which includes fonts like Times New Roman required for Danfe reports. ```bash sudo apt-get install ttf-mscorefonts-installer ``` -------------------------------- ### Initialize ServicosMDFe with Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-mdfe-servicos.md Instantiate the ServicosMDFe class with service configuration and an optional pre-loaded certificate. Ensure the ConfiguracaoServico is set for MDFe. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, ModeloDocumento = ModeloDocumento.MDFe, Certificado = new ConfiguracaoCertificado { /* ... */ } }; using (var servicos = new ServicosMDFe(config)) { var resultado = servicos.MdfeAutorizacao(mdfeList); } ``` -------------------------------- ### Initialize ServicosNFe with Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-nfe-servicos.md Instantiate the main NFe service class with your service configuration. Ensure the configuration includes environment, UF, and certificate details. The certificate can be pre-loaded or loaded from configuration. ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, Certificado = new ConfiguracaoCertificado { /* ... */ } }; using (var servicos = new ServicosNFe(config)) { var resultado = servicos.NfeAutorizacao(nfeList); } ``` -------------------------------- ### Configure Hardware Token Certificate (A3) Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Configure a certificate from a hardware token (smartcard/USB key). Provide the `Serial` number of the token and its `Senha` (PIN). `StoreLocation` specifies where the system looks for the token. ```csharp var config = new ConfiguracaoServico { Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A3, Serial = "1234567890ABCDEF", Senha = "pin123", // PIN for hardware token StoreLocation = StoreLocation.CurrentUser } }; ``` -------------------------------- ### Per-Document Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Use different configurations for different SEFAZ states by creating separate service instances with specific configurations. ```csharp var configSP = new ConfiguracaoServico { cUF = Estado.SP, ... }; var configMG = new ConfiguracaoServico { cUF = Estado.MG, ... }; using (var servicosSP = new ServicosNFe(configSP)) using (var servicosMG = new ServicosNFe(configMG)) { // Process documents with appropriate service instance } ``` -------------------------------- ### Perform Distribution Query Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md Query for distributed NFe documents using NfeDistribuicaoDFe. Specify CNPJ and starting NSU to retrieve documents. ```csharp var servicos = new ServicosNFe(config); var dist = new distDFeInt { infDist = new infDist { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, CNPJ = "12345678000190", distNSU = new distNSU { nSU = "0" } // Start from beginning } }; var resultado = servicos.NfeDistribuicaoDFe(dist); Console.WriteLine($"Total NSU: {resultado.nSUUlt}"); // For next call, use nSUUlt as starting point string nextNSU = resultado.nSUUlt; ``` -------------------------------- ### Create NFe Document Instance Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/types.md Instantiate an NFe object and populate its core information block. Ensure all required fields within `ide`, `emit`, `dest`, `det`, and `total` are correctly set. ```csharp var nfe = new nfe { infNfe = new infNfe { ide = new ide { cUF = Estado.SP, /* ... */ }, emit = new emit { CNPJ = "12345678000190", /* ... */ }, dest = new dest { CNPJ = "98765432000111", /* ... */ }, det = new List { /* Products */ }, total = new total { /* Totals */ } } }; ``` -------------------------------- ### Get Certificate Days Remaining Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/types.md Calculates the number of days remaining until a certificate expires. Useful for proactive certificate renewal notifications. ```csharp // Days remaining int days = cert.VerificaDiasValidade(); ``` -------------------------------- ### Switch Between Production and Homologation Environments Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md Configure the service to operate in either homologation (testing) or production environments. Set 'DefineVersaoServicosAutomaticamente' to true to auto-update service URLs. ```csharp // Homologation (testing) config.tpAmb = TipoAmbiente.Homologacao; // Production config.tpAmb = TipoAmbiente.Producao; // Auto-update service URLs config.DefineVersaoServicosAutomaticamente = true; ``` -------------------------------- ### Get Remaining Days Until Certificate Expiration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-dfe-utils.md Returns the number of days remaining until a certificate expires. Returns a negative number if the certificate has already expired. ```csharp public static int VerificaDiasValidade(this X509Certificate2 x509Certificate2) { // Implementation details omitted for brevity return 0; // Placeholder } ``` ```csharp int daysLeft = cert.VerificaDiasValidade(); if (daysLeft < 30) Console.WriteLine("Certificate expiring soon!"); ``` -------------------------------- ### Enable XML Logging Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/errors.md Set `SalvarXmlServicos` to true and specify the directory for saving XML logs. ```csharp var config = new ConfiguracaoServico { SalvarXmlServicos = true, DiretorioSalvarXml = @"C:\Logs\NFe" }; ``` -------------------------------- ### API Reference Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/COMPLETION.txt Details on every exported function, including signatures, parameter tables, return types, exceptions, code examples, and source file references. ```APIDOC ## API Reference - Every exported function documented with: - Full signature with exact parameter types - Parameter table with defaults - Return type explanation - Throws/exceptions with conditions - Working code example - Source file reference ``` -------------------------------- ### Configure Service Environment and State from Environment Variables Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md Reads NFE_AMBIENTE and NFE_UF environment variables to set the service's operating environment (Production/Homologation) and state (UF). Defaults to SP if NFE_UF is not set. ```csharp var ambiente = Environment.GetEnvironmentVariable("NFE_AMBIENTE"); var uf = Environment.GetEnvironmentVariable("NFE_UF"); var config = new ConfiguracaoServico { tpAmb = ambiente == "PROD" ? TipoAmbiente.Producao : TipoAmbiente.Homologacao, cUF = (Estado)Enum.Parse(typeof(Estado), uf ?? "SP") }; ``` -------------------------------- ### Configure Byte Array Certificate Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/quick-start.md Configure the service to use a certificate provided as a byte array. Load the certificate from a file (e.g., .pfx) and provide its byte content along with the password. ```csharp byte[] certBytes = File.ReadAllBytes("cert.pfx"); var config = new ConfiguracaoServico { Certificado = new ConfiguracaoCertificado { TipoCertificado = TipoCertificado.A1ByteArray, ArrayBytesArquivo = certBytes, Senha = "senha123" } }; ``` -------------------------------- ### Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/COMPLETION.txt Details configuration options for services and certificates. ```APIDOC ## Configuration ### Description Details configuration options for services and certificates. ### Configuration Options - **ConfiguracaoServico** - 35+ properties - **ConfiguracaoCertificado** - 10+ properties with examples ``` -------------------------------- ### Create MDFe Document Instance Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-mdfe-servicos.md Instantiates a root MDFe document object with essential identification, issuer, modal, document, and total information. Ensure all required fields for the specific modal (e.g., rodo) are populated. ```csharp var mdfe = new mdfe { infMdfe = new infMdfe { ide = new ide { cUF = Estado.SP, dEmi = DateTime.Now, tpEmis = TipoEmissao.Normal, tpMDFe = TipoMdfe.Rodoviario }, emit = new emit { CNPJ = "12345678000190", xNome = "Transportadora ABC", IE = "123.456.789.012", UF = Estado.SP, tpIsc = TipoIscMdfe.Microempresa }, infModal = new infModal { versaoModal = "3.00", rodo = new rodo { RNTRC = "123456789", xObs = "Observações sobre o frete", infPrazo = new infPrazo { dPrev = DateTime.Now.AddDays(2) }, infLacRodo = new List() } }, infDoc = new infDoc { infNFe = new List { new infNFe { chNFe = "35200101234567000012340000000011234567890123" } } }, total = new total { vCarga = 5000.00m, cUnid = TipoUnidMdfe.M3, qCarga = 10.00m } } }; ``` -------------------------------- ### Retrieve MDFe Authorization Result Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-mdfe-servicos.md Call MdfeRetAutorizacao with a receipt number obtained from MdfeAutorizacao to get the asynchronous authorization status for a batch of MDFes. A short delay might be necessary before calling this method. ```csharp var autResult = servicos.MdfeAutorizacao(mdfeList); if (autResult.cStat == "103") { System.Threading.Thread.Sleep(2000); var retResult = servicos.MdfeRetAutorizacao(autResult.cRecibo); } ``` -------------------------------- ### ServicosCTe Constructor Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-cte-servicos.md Initializes the ServicosCTe service with service configuration and an optional X.509 certificate. The configuration object specifies details like the state (UF), environment type (production/homologation), document model (CTe), and certificate information. ```APIDOC ## ServicosCTe Constructor ### Description Initializes the ServicosCTe service with service configuration and an optional X.509 certificate. The configuration object specifies details like the state (UF), environment type (production/homologation), document model (CTe), and certificate information. ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Constructor Signature ```csharp public ServicosCTe(ConfiguracaoServico cFgServico, X509Certificate2 certificado = null) ``` ### Parameters - **cFgServico** (ConfiguracaoServico) - Required - Service configuration (reuse from NFe) - **certificado** (X509Certificate2) - Optional - Pre-loaded certificate; if null, loaded from configuration **Note**: ConfiguracaoServico is shared across NFe, CTe, and MDFe. The library automatically routes to CTe endpoints based on context. **Throws**: `Exception` if certificate configuration is invalid ### Example ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, ModeloDocumento = ModeloDocumento.CTe, Certificado = new ConfiguracaoCertificado { /* ... */ } }; using (var servicos = new ServicosCTe(config)) { var resultado = servicos.CteAutorizacao(cteList); } ``` ``` -------------------------------- ### NFe XML Structure Example Source: https://github.com/hercules-net/zeusfiscal/blob/master/NFe.Danfe.Html/Readme.txt This XML snippet represents a typical NFe (Nota Fiscal Eletrônica) structure, including header, issuer, recipient, and item details. It is used as input for generating the DANFE. ```xml 4368509077VENDA DE MERCADORIAS E SERVICOS551365222019-06-11T17:00:55-03:00124313409110210101.1.78.010835909000113KRAFCHINSKI, MORAES E LINARES LTDAKRAFCHINSKI, MORAES E LINARES LTDARUA GUIA LOPES1280RONDONIA4313409NOVO HAMBURGORS934155121058BRASIL51307730100860452247332806205000155BIKETOP COMERCIO E SERVICOS DE BICICLETAS EIRELIALTINO SERBETO DE BARROS173LOJA 01PITUBA2927408SALVADORBA418304921058BRASIL719880151741155731233005110SEM GTINCAMISA CANNONDALE PRETA/RAJADA CINZA LETRA AMARELA-ZIPER CURTO-MASC TAM G611300006102UN1.000029.990000000029.99SEM GTINUN1.000029.99000000001000329.997.00002.10999500.000.00000.000129.990.65000.190129.993.00000.90005115SEM GTINCAMISA ORBEA PRETA/AZUL/BRANCA-ZIPER CURTO- MASC - TAM G611300006102UN1.000029.990000000029.99SEM GTINUN1.000029.99000000001000329.997.00002.10999500.000.00000.00 ``` -------------------------------- ### Query CTe Authorization Status by Access Key Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-cte-servicos.md Queries the authorization status of a CTe using its 44-digit access key. The example shows how to check for a '100' status code and retrieve the reception timestamp if authorized. ```csharp string chave = "35200101234567000012340000000011234567890123"; var consulta = servicos.CteConsultaProtocolo(chave); if (consulta.cStat == "100") Console.WriteLine("Authorized on: " + consulta.protCte.dhRecbto); ``` -------------------------------- ### ServicosMDFe Constructor Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/api-mdfe-servicos.md Initializes the ServicosMDFe service with service configuration and an optional pre-loaded certificate. ```APIDOC ## ServicosMDFe Constructor ### Description Initializes the ServicosMDFe service with service configuration and an optional pre-loaded certificate. ### Parameters #### Path Parameters - **cFgServico** (ConfiguracaoServico) - Required - Service configuration (shared with NFe/CTe) - **certificado** (X509Certificate2) - Optional - Pre-loaded certificate; if null, loaded from configuration ### Throws - `Exception` if certificate configuration invalid ### Example ```csharp var config = new ConfiguracaoServico { cUF = Estado.SP, tpAmb = TipoAmbiente.Producao, ModeloDocumento = ModeloDocumento.MDFe, Certificado = new ConfiguracaoCertificado { /* ... */ } }; using (var servicos = new ServicosMDFe(config)) { var resultado = servicos.MdfeAutorizacao(mdfeList); } ``` ``` -------------------------------- ### Global Singleton Configuration Source: https://github.com/hercules-net/zeusfiscal/blob/master/_autodocs/configuration.md For single-application configuration, use the singleton instance to set and access configuration values globally. ```csharp ConfiguracaoServico.Instancia.cUF = Estado.SP; ConfiguracaoServico.Instancia.tpAmb = TipoAmbiente.Producao; // Access from anywhere var config = ConfiguracaoServico.Instancia; ```