Skip to content
For Business Owners

SEFAZ Integration in Practice: A1 Certificate, Test Environment, Contingency, Events, and DANFE

By Ana da Forcoder6 min read

Integrating a system with SEFAZ is not just about calling a webservice. It involves handling digital certificates, two environments that can't be mixed, contingency plans when the authorization service goes down, events with deadlines, and printed auxiliary documents that must strictly follow the manual. Every detail done wrong turns into a rejection or, worse, a valid document issued by mistake.

This article is for those looking for a company to integrate with SEFAZ and want to understand what happens under the hood. Everything described here is in the code of LogFrota and ValuERP, Forcoder's systems for issuing CT-e, MDF-e, NF-e, and NFC-e.

A1 Digital Certificate: the Key to Everything

All communication with SEFAZ is signed and authenticated using the company's certificate. We work with A1, the .pfx file protected by password, which is valid for one year.

Loading and Validating

When the certificate is received, the system opens the file, checks the password, reads the validity, and rejects any expired certificate with a clear message. Older certificates generated with algorithms no longer supported by newer OpenSSL versions get a second read attempt instead of just an incomprehensible technical error for the user.

Who Represents the Company

SEFAZ recognizes CNPJ, not "system accounts." In LogFrota, the parent branch represents the company: its certificate, regime, numbering, and environment are inherited by all subsidiaries. ValuERP checks whether the certificate belongs to the same base CNPJ as the store before issuing.

Approval and Production: One Switch

SEFAZ has two environments. In approval, the document has no fiscal value; in production, any error is a valid document that must be canceled within the deadline. So the environment is a serious system decision:

  • every new database starts in approval;
  • the public demo remains locked in simulated mode, which never transmits;
  • switching to production is done by the company’s administrator, with confirmation;
  • CT-e, MDF-e, NF-e, and other services follow the same switch.

In approval, the layout itself replaces the recipient's name with a "no fiscal value" warning. DANFE and DACTE generated in this environment have a watermark so no one confuses a test with a real invoice.

Contingency: When SEFAZ Goes Down

SEFAZ does go down. When that happens at a carrier, a loaded truck can’t depart without documentation. Legislation provides contingency paths, and the tpEmis chosen goes into the access key: you can’t issue normally and "convert" later.

Contingency modes implemented in our systems
DocumentMain PathAlternative or Next Step
CT-eSVC (SVC-RS or SVC-SP), instant authorizationOffline contingency (tpEmis 2), as per NT 2026.004, which replaced EPEC for CT-e
NF-eSVC, instant authorizationEPEC, event sent to the National Environment
MDF-eContingency (tpEmis 2), vehicle continues the tripLater transmission of the same XML once authorization service returns
NFC-eOffline contingency (tpEmis 9)Subsequent transmission of the document

The policy we follow is the same for all:

  1. Draft or rejected only. Documents already transmitted do not change their mode.
  2. Authorization service available, normal issuance. The system checks the service status and won’t allow contingency without reason.
  3. SVC available, SVC goes first. It authorizes in real time and leaves no pending issues.
  4. Checks before numbering. All validations run before numbering is assigned, so an internal rejection doesn’t waste a number.
  5. Operator’s decision. Contingency is selected with confirmation on screen, never automatically engaged.
  6. Automatic subsequent transmission. A routine sends the same XML once the authorization service comes back and handles late authorizations.

Separately, there's retention: when the failure is just a communication problem, the document is retained and automatically resent. Distinguishing “SEFAZ is down” from “what we sent is wrong” prevents stuck, repeated failed attempts.

Events: What Happens After Authorization

An authorized document stays active. The most common events handled by our systems are:

  • Cancellation, within the legal timeframe, keeping the event XML stored;
  • CT-e Correction Letter (event 110110), with a ready list of the common transport fields, rules for what can’t be corrected, and a PDF of the letter;
  • Closure of MDF-e, including querying still-open manifests for the same CNPJ at SEFAZ;
  • Numbering voidance for number ranges;
  • Document distribution, importing NF-e issued to the company and their cancellation events.

DANFE, DACTE, and DAMDFE

Printed auxiliary documents follow each layout’s manual. Our systems generate NF-e DANFE in A4 with stub, carrier, installments, and item-wise taxes; NFC-e DANFCE in an 80 mm receipt with QR Code; DACTE, including in batches; and DAMDFE, which the driver can open in the app even offline.

The document status is visible on paper: canceled, denied, no fiscal value in approval, or issued in contingency, with the required phrase from the manual instead of protocol. For CT-e issued in offline contingency, DACTE prints the specific strip for that mode.

Translated Rejections

SEFAZ returns a code (the cStat) and a technical message. Our systems keep a catalog of the most common rejections, explained in plain Portuguese, and show the screen where to fix them. Registration-related rejections point to the record; ones depending on SEFAZ or the accountant are flagged as external. This way, operators know if they can solve it or need someone else.

SEFAZ Integration Well-Done: The Checklist

  • A1 certificate validated on send, with warnings before expiration
  • Homologation environment as default, and switch to production is confirmed
  • Status check of the service before proposing contingency
  • SVC and offline contingency implemented for all operational documents
  • Numbering protected from internal rejection
  • Cancellation, correction, closure, and voidance events
  • DANFE, DACTE, and DAMDFE displaying document status
  • Translated rejections and log of every call

Hire Those Already Live in Production

Forcoder integrates systems with SEFAZ and the National Environment from XML signature through auxiliary document printing. If you need a complete fiscal issuing system or want to enable issuing within your current system, check out how we do it in a TMS like LogFrota as well.

Contact Forcoder or reach out on WhatsApp.

Frequently Asked Questions

What is the difference between SVC and EPEC?

SVC is a virtual SEFAZ that authorizes the complete document on the spot, with no pending actions. EPEC records a summarized event and requires the document to be sent later. For CT-e, EPEC was replaced by offline contingency in NT 2026.004; for NF-e, it is still valid.

Do you work with A3 certificates?

Our systems use A1, which can be used by the server without physical devices. For automated cloud issuing, A1 is the practical option.

How can I tell if SEFAZ is down or if the error is mine?

The system checks the status of both the authorization and SVC services. Communication failures are retained and automatically retried; SEFAZ error codes indicate issues with the data sent, and explanations appear on screen.

Does the integration work for any state?

Yes. The communication library points to the authorization service for each state and the corresponding SVC; the mapping of which SVC covers each state follows SEFAZ publications.

Keep reading

Products by Forcoder and our clients

Software Forcoder built and maintains, for itself and for its clients.

Client case

Nexus Finanças

Banking as a Service (BaaS) platform for Nexus Finanças: a digital account for each partner, with Pix, transfers, bill payments, charges with automatic split and cards, admin and partner dashboards, plus the company's corporate website.

Client case

Torela Real Estate

Real estate portal and system for Torela, in Gramado, Canela and the Rio Grande do Sul coast, integrated with Loft: listings reach the website without double entry, with search by region, city and neighborhood, property pages with photo galleries, favorites, comparison, vacation...

Client case

Permute-se

An asset-matching social network: properties and vehicles with compatibility-based matches, private proposals, a nationwide feed, wanted listings and subscription plans, on the web and in apps published on the App Store and Google Play.

Have a project in mind? Let's make it happen.

Custom websites, systems and integrations, focused on results. Tell us what you need and the Forcoder team will get in touch.