TEIF Format and Technical Specifications for E-Invoicing in Tunisia

Noqta Team
By Noqta Team ·

Loading the Text to Speech Audio Player...

Electronic invoicing in Tunisia is built on a standardized data format called TEIF — Tunisian Electronic Invoice Format. Understanding this format is essential for any developer or technical lead responsible for integrating the El Fatoora platform into an information system. This guide covers the XML structure, mandatory fields, digital signature, QR code, and the two available integration modes.

This tutorial is the fifth episode of our Electronic Invoicing in Tunisia series. It assumes you are already registered on the El Fatoora platform. If not, consult Episode 4: Step-by-Step Registration Guide first.


What is TEIF?

TEIF (Tunisian Electronic Invoice Format) is Tunisia's national standard for the electronic exchange of invoices between businesses and between businesses and government entities (B2B and B2G). It is defined by Tunisie TradeNet (TTN) in coordination with the Direction Générale des Impôts (DGI — General Tax Authority) and the Agence Nationale de Certification Électronique (ANCE — National Electronic Certification Agency).

TEIF is based on XML (eXtensible Markup Language) and is governed by an XSD (XML Schema Definition) schema that defines the mandatory structure and validation rules for every document.

Current versions:

  • Version 1.8.7: stable production version since January 2026
  • Version 1.9.x: currently being finalized, not yet deployed to production

TEIF is aligned with international e-invoicing standards, notably UBL 2.1 (Universal Business Language) and CII (Cross Industry Invoice), while incorporating Tunisian tax specificities (Tunisian VAT/TVA, stamp duties, taxation on goods subject to special regimes).


XML/XSD Schema Structure

A TEIF document is an XML file structured into several hierarchical sections. Here is the top-level structure:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:tn:gov:dgi:teif:1.8"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="urn:tn:gov:dgi:teif:1.8 TEIF_v1.8.7.xsd">
 
  <!-- Section 1: Invoice header -->
  <Header>
    <InvoiceID>FAC-2026-001234</InvoiceID>
    <IssueDate>2026-02-22</IssueDate>
    <IssueTime>14:30:00</IssueTime>
    <InvoiceTypeCode>380</InvoiceTypeCode>
    <DocumentCurrencyCode>TND</DocumentCurrencyCode>
    <TaxCurrencyCode>TND</TaxCurrencyCode>
  </Header>
 
  <!-- Section 2: Parties (supplier and customer) -->
  <Parties>
    <Supplier>...</Supplier>
    <Customer>...</Customer>
  </Parties>
 
  <!-- Section 3: Invoice lines -->
  <InvoiceLines>
    <InvoiceLine>...</InvoiceLine>
  </InvoiceLines>
 
  <!-- Section 4: Tax totals -->
  <TaxTotal>...</TaxTotal>
 
  <!-- Section 5: Monetary totals -->
  <LegalMonetaryTotal>...</LegalMonetaryTotal>
 
  <!-- Section 6: Digital signature (added after generation) -->
  <Signature>...</Signature>
 
  <!-- Section 7: Visible electronic seal (QR Code) -->
  <VisibleElectronicSeal>...</VisibleElectronicSeal>
 
</Invoice>

Mandatory Fields and Validation Rules

The TEIF schema distinguishes three field levels: mandatory (M — Mandatory), conditional (C — Conditional), and optional (O — Optional).

Header Section — Mandatory Fields

FieldTypeDescriptionExample
InvoiceIDString (max 50)Unique invoice numberFAC-2026-001234
IssueDateDate (YYYY-MM-DD)Issue date2026-02-22
IssueTimeTime (HH:MM:SS)Issue time14:30:00
InvoiceTypeCodeCode (3 digits)Document type380 (invoice), 381 (credit note)
DocumentCurrencyCodeISO 4217Invoice currencyTND
DueDateDatePayment due date2026-03-22

Document Type Codes

CodeDocument Type
380Standard commercial invoice
381Credit note (avoir)
383Debit note
386Prepayment / advance invoice
389Self-billing

Supplier Section — Mandatory Fields

<Supplier>
  <PartyIdentification>
    <ID schemeID="TN_MF">12345678A000000</ID> <!-- Tax registration number (matricule fiscal) -->
  </PartyIdentification>
  <PartyName>
    <Name>Société Exemple SARL</Name>
  </PartyName>
  <PostalAddress>
    <StreetName>Avenue Habib Bourguiba</StreetName>
    <CityName>Tunis</CityName>
    <PostalZone>1000</PostalZone>
    <CountrySubentity>Tunis</CountrySubentity>
    <Country>
      <IdentificationCode>TN</IdentificationCode>
    </Country>
  </PostalAddress>
  <TaxScheme>
    <ID>TVA</ID>
    <TaxTypeCode>VAT</TaxTypeCode>
  </TaxScheme>
</Supplier>

Key rules:

  • schemeID="TN_MF" is mandatory for the Tunisian tax registration number (matricule fiscal)
  • The address must exactly match the address registered with the DGI
  • The country code must be TN for Tunisian companies

InvoiceLine Section — Line Structure

<InvoiceLine>
  <ID>1</ID> <!-- Sequential line number -->
  <InvoicedQuantity unitCode="C62">10</InvoicedQuantity>
  <LineExtensionAmount currencyID="TND">500.000</LineExtensionAmount>
  <Item>
    <Name>Prestation de développement web</Name>
    <SellersItemIdentification>
      <ID>PROD-001</ID>
    </SellersItemIdentification>
    <ClassifiedTaxCategory>
      <ID>S</ID> <!-- S=Standard, Z=Zero, E=Exempt -->
      <Percent>19</Percent>
      <TaxScheme>
        <ID>TVA</ID>
      </TaxScheme>
    </ClassifiedTaxCategory>
  </Item>
  <Price>
    <PriceAmount currencyID="TND">50.000</PriceAmount>
    <BaseQuantity unitCode="C62">1</BaseQuantity>
  </Price>
</InvoiceLine>

Applicable Tunisian VAT (TVA) Rates

CodeRateApplication
S (Standard)19%General rate
S (Reduced 1)13%Financial services, insurance
S (Reduced 2)7%Basic foodstuffs, medicines
Z (Zero)0%Exports, exempt products
E (Exempt)Specific sectors exempted by law

Digital Signature Integration

The digital signature is the mechanism that guarantees the authenticity and integrity of a TEIF invoice. It is based on the W3C XMLDSig (XML Digital Signature) standard, using the RSA-SHA256 algorithm.

How the Signature is Embedded in the XML

The signature is added in the <Signature> section of the XML document after the invoice content has been generated:

<Signature Id="TEIF-SIG-001">
  <SignedInfo>
    <CanonicalizationMethod
      Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
    <SignatureMethod
      Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
    <Reference URI="">
      <Transforms>
        <Transform
          Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
      </Transforms>
      <DigestMethod
        Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
      <DigestValue>
        <!-- SHA256 hash of the canonicalized document -->
        7H3fKpL2mN9oQr1sT4uVwX6yZ8aB0cD2eF4gH6iJ8kL=
      </DigestValue>
    </Reference>
  </SignedInfo>
  <SignatureValue>
    <!-- RSA signature value encoded in Base64 -->
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
  </SignatureValue>
  <KeyInfo>
    <X509Data>
      <X509Certificate>
        <!-- TUNTRUST certificate in Base64 -->
        MIIDpDCCAoygAwIBAgIUX7k2Y...
      </X509Certificate>
    </X509Data>
  </KeyInfo>
</Signature>

4-Step Signing Process

  1. Generate the invoice XML (without the Signature section)
  2. Canonicalize the XML document using the C14N algorithm
  3. Compute the SHA-256 hash of the canonicalized document
  4. Encrypt the hash with the TUNTRUST certificate's private key → signature value

TTN's signature verification follows the reverse process: recomputing the hash and decrypting the signature using the certificate's public key.

Important: The signature invalidates any subsequent modification to the document. An invoice modified after signing must be re-signed.


QR Code Generation (Visible Electronic Seal)

The Cachet Électronique Visible (CEV) — Visible Electronic Seal — is a QR code printed on the invoice that allows any third party (customer, auditor, tax authority) to quickly verify the invoice's authenticity by scanning the code.

Content Encoded in the QR Code

The QR code contains a verification URL pointing to the El Fatoora portal, with the following parameters encoded:

ParameterDescription
iidUnique TTN invoice identifier (hash)
sidSupplier identifier (matricule fiscal)
dtIssue date and time
amtTotal amount including tax (TTC)
sigControl signature (truncated hash)

Example URL encoded in the QR code:

https://verify.elfatoora.tn/v?iid=a3f7e2b1c9d4&sid=12345678A000000&dt=20260222143000&amt=619.000&sig=f4e2a1b3

Integration in the TEIF XML

<VisibleElectronicSeal>
  <QRCode format="QR_CODE" version="2">
    <!-- QR code data encoded in Base64 -->
    aHR0cHM6Ly92ZXJpZnkuZWxmYXRvb3JhLnRuL3Y/...
  </QRCode>
  <SealDescription>Facture électronique certifiée TTN</SealDescription>
  <SealDate>2026-02-22T14:30:00</SealDate>
</VisibleElectronicSeal>

The QR code must be generated after the digital signature, since it contains a reference to the signed invoice's hash.


Integration Modes: Web Mode vs EDI Mode

Web Mode

In Web Mode, the entire invoicing process takes place through the El Fatoora portal's web interface:

  1. The user logs in at elfatoora.tn
  2. They enter invoice data in a form
  3. The portal automatically generates the TEIF XML
  4. The user signs electronically via their certificate (or Mobile-ID)
  5. The invoice is transmitted and validated in real time

Advantages: No development required, immediate go-live Limitations: No automation, manual entry only

EDI Mode (API)

In EDI Mode, your information system generates TEIF invoices and submits them automatically via TTN's REST API:

Integration flow:

Your ERP/CRM
    │
    ▼ (generates TEIF XML)
Signing middleware
    │
    ▼ (signed XML)
TTN API (HTTPS/REST)
    │
    ▼ (validation + timestamping)
El Fatoora Platform ──► DGI (automatic tax reporting)
    │
    ▼ (acknowledgement)
Your system (storage + archiving)

TTN API Endpoints (EDI Mode)

EndpointMethodDescription
/api/v1/auth/tokenPOSTObtain an OAuth2 access token
/api/v1/invoicesPOSTSubmit a new invoice
/api/v1/invoices/{id}GETRetrieve invoice status
/api/v1/invoices/{id}/ackGETDownload the acknowledgement
/api/v1/invoices/{id}/pdfGETDownload the PDF version
/api/v1/invoices/searchGETSearch invoices

Base URLs:

  • Sandbox: https://api-sandbox.elfatoora.tn
  • Production: https://api.elfatoora.tn

Invoice Lifecycle

A TEIF invoice passes through several statuses throughout its lifecycle:

CREATED → SIGNED → SUBMITTED → VALIDATING → VALID
                                    │
                                    └── INVALID (with error code)
StatusDescriptionRequired Action
CREATEDXML generated, not yet signedSign the document
SIGNEDDocument signed, not yet submittedSubmit to the API
SUBMITTEDReceived by TTN, validation in progressWait
VALIDATINGVerification in progress (< 30 seconds)Wait
VALIDInvoice accepted and archivedRetain the acknowledgement
INVALIDRejected for non-complianceCorrect and resubmit
CANCELLEDCancelled by issuance of a credit noteCheck the associated credit note

Invoice Archiving

Tunisian regulations impose a minimum archiving period of 5 years for all electronic invoices. TTN offers a managed archiving service at the following rates:

ServiceRate
XML/data storage0.190 TND per 50 KB
PDF copy of invoice0.250 TND per unit
XML copy of invoice0.250 TND per unit
Portal consultationIncluded in subscription
Archive exportOn request, variable rate

Estimated cost: An average TEIF XML file weighs between 5 and 15 KB depending on the number of lines. For a company issuing 500 invoices/month, archiving costs approximately 0.95 to 2.85 TND/month — a negligible amount.

Archiving options:

  1. TTN archiving (recommended): TTN manages retention, security, and availability
  2. Self-archiving: You retain the XML and PDF files on your own servers, subject to DGI security standards
  3. Hybrid archiving: TTN + synchronized local copy

Complete TEIF Invoice Example

Here is a simple but complete invoice in TEIF 1.8.7 format, for a service with 19% VAT:

<?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns="urn:tn:gov:dgi:teif:1.8"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="urn:tn:gov:dgi:teif:1.8 TEIF_v1.8.7.xsd">
 
  <Header>
    <InvoiceID>FAC-2026-001234</InvoiceID>
    <IssueDate>2026-02-22</IssueDate>
    <IssueTime>14:30:00</IssueTime>
    <InvoiceTypeCode>380</InvoiceTypeCode>
    <DocumentCurrencyCode>TND</DocumentCurrencyCode>
    <TaxCurrencyCode>TND</TaxCurrencyCode>
    <DueDate>2026-03-22</DueDate>
    <Note>Facture pour services de développement web — Projet NoqtaApp v2</Note>
  </Header>
 
  <Parties>
    <Supplier>
      <PartyIdentification>
        <ID schemeID="TN_MF">12345678A000000</ID>
      </PartyIdentification>
      <PartyName>
        <Name>Tech Solutions SARL</Name>
      </PartyName>
      <PostalAddress>
        <StreetName>12 Rue des Entrepreneurs</StreetName>
        <CityName>Tunis</CityName>
        <PostalZone>1002</PostalZone>
        <CountrySubentity>Tunis</CountrySubentity>
        <Country><IdentificationCode>TN</IdentificationCode></Country>
      </PostalAddress>
      <Contact>
        <Telephone>+216 71 000 000</Telephone>
        <ElectronicMail>facturation@tech-solutions.tn</ElectronicMail>
      </Contact>
    </Supplier>
 
    <Customer>
      <PartyIdentification>
        <ID schemeID="TN_MF">98765432B000111</ID>
      </PartyIdentification>
      <PartyName>
        <Name>Client Entreprise SA</Name>
      </PartyName>
      <PostalAddress>
        <StreetName>45 Avenue de la République</StreetName>
        <CityName>Sfax</CityName>
        <PostalZone>3000</PostalZone>
        <CountrySubentity>Sfax</CountrySubentity>
        <Country><IdentificationCode>TN</IdentificationCode></Country>
      </PostalAddress>
    </Customer>
  </Parties>
 
  <InvoiceLines>
    <InvoiceLine>
      <ID>1</ID>
      <InvoicedQuantity unitCode="HUR">20</InvoicedQuantity>
      <LineExtensionAmount currencyID="TND">1000.000</LineExtensionAmount>
      <Item>
        <Name>Développement front-end React</Name>
        <ClassifiedTaxCategory>
          <ID>S</ID>
          <Percent>19</Percent>
          <TaxScheme><ID>TVA</ID></TaxScheme>
        </ClassifiedTaxCategory>
      </Item>
      <Price>
        <PriceAmount currencyID="TND">50.000</PriceAmount>
        <BaseQuantity unitCode="HUR">1</BaseQuantity>
      </Price>
    </InvoiceLine>
 
    <InvoiceLine>
      <ID>2</ID>
      <InvoicedQuantity unitCode="HUR">10</InvoicedQuantity>
      <LineExtensionAmount currencyID="TND">400.000</LineExtensionAmount>
      <Item>
        <Name>Intégration API et tests</Name>
        <ClassifiedTaxCategory>
          <ID>S</ID>
          <Percent>19</Percent>
          <TaxScheme><ID>TVA</ID></TaxScheme>
        </ClassifiedTaxCategory>
      </Item>
      <Price>
        <PriceAmount currencyID="TND">40.000</PriceAmount>
        <BaseQuantity unitCode="HUR">1</BaseQuantity>
      </Price>
    </InvoiceLine>
  </InvoiceLines>
 
  <TaxTotal>
    <TaxAmount currencyID="TND">266.000</TaxAmount>
    <TaxSubtotal>
      <TaxableAmount currencyID="TND">1400.000</TaxableAmount>
      <TaxAmount currencyID="TND">266.000</TaxAmount>
      <TaxCategory>
        <ID>S</ID>
        <Percent>19</Percent>
        <TaxScheme><ID>TVA</ID></TaxScheme>
      </TaxCategory>
    </TaxSubtotal>
  </TaxTotal>
 
  <LegalMonetaryTotal>
    <LineExtensionAmount currencyID="TND">1400.000</LineExtensionAmount>
    <TaxExclusiveAmount currencyID="TND">1400.000</TaxExclusiveAmount>
    <TaxInclusiveAmount currencyID="TND">1666.000</TaxInclusiveAmount>
    <PayableAmount currencyID="TND">1666.000</PayableAmount>
  </LegalMonetaryTotal>
 
  <!-- Signature and QR Code sections are added by the signing process -->
 
</Invoice>

Key points in this example:

  • Amounts use 3 decimal places (Tunisian dinar format: 1400.000)
  • The unit code HUR corresponds to hours (per UN/ECE 20 standard)
  • Line amounts (LineExtensionAmount) are exclusive of VAT
  • TaxInclusiveAmount = TaxExclusiveAmount + TaxAmount (1400 + 266 = 1666)

Pre-Submission Checklist

Before submitting a TEIF invoice, systematically verify these points:

  • XSD validation passed (no schema errors)
  • Supplier tax registration number conforms to TN_MF format
  • Sum of LineExtensionAmount values = TaxExclusiveAmount
  • TaxInclusiveAmount = TaxExclusiveAmount + total TaxAmount
  • Issue date in ISO 8601 format (YYYY-MM-DD)
  • Digital signature valid (verified with the public key)
  • QR code generated after signing

Series Navigation

For a complete technical implementation with Node.js/TypeScript code examples, see our Episode 7: TTN API Integration for Developers.

Need a custom integration of electronic invoicing into your system? Noqta.tn supports Tunisian businesses in their digital transformation. Contact our technical team for a free audit of your existing system.


Want to read more tutorials? Check out our latest tutorial on Building a Full-Stack App with TanStack Start: The Next-Generation React Framework.

Discuss Your Project with Us

We're here to help with your web development needs. Schedule a call to discuss your project and how we can assist you.

Let's find the best solutions for your needs.

Related Articles

Getting Started with ALLaM-7B-Instruct-preview

Learn how to use the ALLaM-7B-Instruct-preview model with Python, and how to interact with it from JavaScript via a hosted API (e.g., on Hugging Face Spaces).

8 min read·