P
Prime Docs
DocsArchitecture

ZATCA Compliance

A technical dive into how Prime Fatoora natively handles ZATCA-compliant e-invoicing and direct FATOORA integration without external middleware.

Prime Fatoora was built natively around the Saudi ZATCA e-invoicing framework. Unlike legacy ERPs that require expensive third-party middleware to transform and sign invoices, we handle all cryptographic hashing, XML canonicalization, and API clearance natively inside our backend.

ZATCA E-Invoicing Overview

  • Compliant invoice generation: Prime Fatoora protects issued invoices from manual tampering and includes the required QR code for simplified invoices.
  • Live ZATCA integration: Eligible workspaces can connect directly to the FATOORA Portal API to clear or report invoices in real time.

The Phase 1 Workflow

Phase 1 plans support standard and simplified electronic tax invoices and linked credit and debit notes without live FATOORA submission. Set up your seller details and VAT profile in Organization Settings, then confirm the invoice and download the final PDF. A preview PDF is not a tax invoice.

Choose the phase your business is required to use
Buying a Phase 1 plan does not exempt a business from a ZATCA Phase 2 integration deadline. If Phase 2 is required, use a Phase 2 plan and complete FATOORA setup.

The Phase 2 Workflow

1

Automated Onboarding

  • You generate a 6-digit OTP from the official Fatoora Portal.
  • We securely generate a local ECDSA secp256k1 private key and Certificate Signing Request (CSR).
  • We exchange the CSR for a Compliance CSID, perform mandatory ZATCA checks, and upgrade it to a Production CSID entirely in the background.
2

Cryptographic Hashing

  • Every invoice must mathematically link to the previous invoice to prevent historical tampering.
  • We take the SHA-256 hash of the previous XML document and embed it directly into the current UBL 2.1 XML document before signing (PIH Chaining).
3

Clearance & Reporting

  • B2B Invoices: Sent to the ZATCA Clearance API. We embed the returned cryptographic stamp onto your PDF.
  • B2C Invoices: Signed locally by our offline ECDSA keys, handed to the buyer instantly, and reported to ZATCA within 24 hours.

UBL 2.1 XML Example

Prime Fatoora constructs highly validated, EN16931-compliant UBL 2.1 XML documents directly. Before signing, the XML is canonicalized using the xml-c14n11 algorithm.

Embedded Signature Snippet (UBL 2.1)
<ext:UBLExtension>
  <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
  <ext:ExtensionContent>
    <sig:UBLDocumentSignatures>
      <sac:SignatureInformation>
        <cbcv:ID>urn:oasis:names:specification:ubl:signature:1</cbcv:ID>
        <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
        <ds:Signature Id="signature">
          <ds:SignedInfo>
            <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
            <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
            <!-- XML Hashing and Base64 Signature Value -->
          </ds:SignedInfo>
        </ds:Signature>
      </sac:SignatureInformation>
    </sig:UBLDocumentSignatures>
  </ext:ExtensionContent>
</ext:UBLExtension>

Frequently Asked Questions

Do I need to hire a developer to integrate with ZATCA?

No! The Prime Fatoora backend is a native Phase 2 engine. All you have to do is paste the 6-digit OTP from the Fatoora Portal into your dashboard, and our servers handle the complex cryptography.

What happens if the ZATCA portal goes offline?

For B2B Standard invoices, you must wait for the portal to come back online to achieve Clearance. For B2C Simplified invoices, our background queue workers will automatically retry reporting the offline-signed invoices for up to 24 hours.