ZATCA E-Invoicing Phase 2: What Integration Actually Involves
A technical and operational guide to Fatoora Phase 2 — clearance versus reporting, cryptographic stamps, onboarding, the XML requirements, and the integration mistakes that cause rejected invoices.
Phase 1 of Saudi e-invoicing was a formatting change. You stopped writing invoices by hand or in a word processor, and started producing them from a system. Painful for some, but conceptually simple.
Phase 2 is a different kind of project. Your billing system now has to hold a private key, cryptographically stamp every document, speak a specific XML dialect, and — for a large share of your invoices — obtain the tax authority's approval before the customer ever sees the document. That last point is the one that catches teams off guard: for standard invoices, ZATCA is not receiving a copy of your invoice. It is standing in the middle of your billing process.
The distinction that determines your architecture
Everything in Phase 2 follows from one split, and getting it wrong at design time is expensive to correct later.
Standard tax invoices — typically business-to-business and business-to-government — go through clearance. You submit the invoice to ZATCA, ZATCA validates and applies its own stamp, and only the cleared document is legally valid to issue to your buyer. This is synchronous and it is blocking. If the clearance call fails, you do not have an invoice.
Simplified tax invoices — typically business-to-consumer, the receipt handed over at point of sale — go through reporting. You issue the invoice to the customer immediately, complete with QR code, and report it to ZATCA within the required window after issuance. This is asynchronous, which is the only workable design for a retail till.
The operational consequence is large. A clearance failure stops a B2B sale. A reporting failure does not stop the retail transaction, but it creates a compliance backlog that must be drained and monitored. These need different error handling, different queues, and different alerting. Teams that build one generic "send to ZATCA" path discover this during their first outage.
What the invoice document must carry
A compliant Phase 2 invoice is a structured XML document — based on UBL — carrying elements that a PDF simply cannot express:
- A UUID unique to the document.
- A cryptographic stamp generated using a certificate tied to your invoicing solution.
- A hash of the previous invoice, which chains your documents together. This is the anti-tampering mechanism, and it has a consequence people miss: your invoice sequence becomes an append-only chain. You cannot delete an invoice, and you cannot quietly reorder or backfill one. Corrections happen through credit and debit notes, never through editing.
- A QR code encoding defined fields in a specified structure — mandatory on simplified invoices, and it must be scannable and correct, not decorative.
- Complete party and tax detail: VAT registration numbers where applicable, correct addresses in the required structure, line-level tax categories and rates, and totals that reconcile exactly.
That last item is the quiet killer. ZATCA validates arithmetic. A rounding approach that has been fine in your ERP for a decade — rounding at the line versus at the total, or handling a mixed-rate invoice inconsistently — will produce rejections at scale once every document is machine-checked. Reconciling your rounding logic to the specification is often the single largest code change in the project.
Onboarding your solution
Before your system can transact, it must be registered with ZATCA and issued a cryptographic identity. In outline: you generate a certificate signing request from your invoicing solution, obtain a one-time password from the Fatoora portal, exchange these for a compliance certificate, pass the compliance checks, and then obtain the production credentials your system uses thereafter.
Three things to plan for that are not obvious from the documentation:
- Every device or branch that issues invoices independently needs its own identity. If you run forty point-of-sale terminals, you are managing forty credentials, forty renewal dates, and forty potential failure points. Build the management tooling before you deploy the fortieth terminal, not after.
- Certificates expire. An expiry that nobody is watching means invoicing stops. Put renewal on a monitored calendar with alerting well ahead of the date, and treat it as a production dependency, not an administrative task.
- Private keys need real protection. The key that stamps your invoices is a legal instrument. It should not sit in a repository, in a config file committed to source control, or on a shared drive.
Where to put the integration
You have three realistic options, and the right one depends on how many systems in your business can create an invoice.
Direct integration in the ERP. Simplest when a single system issues everything. The ERP holds the credentials and calls ZATCA directly. Fewest moving parts, but it couples your compliance layer to your ERP upgrade cycle, and it does not scale if a second billing system appears.
A middleware layer. A dedicated service that all billing systems call, which handles credentials, formatting, submission, retries and archiving. More to build, but this is the right answer for most organisations of any size — because the number of systems that can generate an invoice always grows, and because it gives you one place to fix a specification change.
A certified third-party provider. You send invoice data, they handle the compliance mechanics. Fastest to launch and a sensible choice for smaller operations. The trade-offs are per-document cost at volume, a dependency on their uptime for your ability to bill, and questions about where your invoice data is processed and stored that you should answer before signing.
The failure modes that cause real damage
Treating clearance as optional at runtime. Some teams build a fallback that issues the invoice anyway when ZATCA is unreachable. For standard invoices this produces documents that are not legally valid, and the problem compounds silently until someone reconciles. The correct behaviour is to fail the issuance, queue it, and alert — not to invent an invoice.
Ignoring the reporting backlog. Simplified invoices report asynchronously, which means failures are invisible unless you look. Without a dashboard showing unreported invoices by age, you will find out at audit. Build the monitoring on day one; it costs a day and saves a quarter.
Underestimating the archive requirement. Invoices must be retained in their original structured form, and retention obligations under Saudi VAT rules run for years. A PDF rendering is not the invoice. Store the signed XML, and make sure your archive is genuinely durable and retrievable rather than a folder nobody has tested restoring from.
Testing only the happy path. Test credit notes, debit notes, invoices with mixed VAT rates, zero-rated and exempt lines, foreign-currency documents, invoices to customers without a VAT registration, and cancellation flows. Every one of these has caused a production incident for someone.
Forgetting the human side. Your finance team needs to know what to do when an invoice is rejected. Without a defined process, the default becomes someone quietly editing and resubmitting until it passes, which breaks the chain integrity the whole system is built on.
How to sequence the work
- Confirm your obligations and timing. Phase 2 applies in waves determined by revenue, with taxpayers notified in advance of their wave. Establish your own position from ZATCA's notification rather than from what a peer told you.
- Inventory every system that can create an invoice. Include the ones finance built in a spreadsheet, the standalone system in the branch, and the one the sales team uses for deposits. Each is in scope.
- Fix your data before you fix your integration. Missing customer VAT numbers, malformed addresses and inconsistent tax codes will fail validation regardless of how good your integration is. This is usually the longest task, and it can start immediately.
- Build against the sandbox. ZATCA provides a developer environment. Use it hard, including for the failure cases.
- Run parallel before you cut over. Issue through both paths and reconcile, for a period long enough to include a month-end close.
- Instrument everything. Submission success rate, clearance latency, reporting backlog age, certificate expiry countdown. These are production metrics, not project metrics — they matter permanently.
The way to think about it
It is tempting to treat e-invoicing as a tax project that IT has to support. In practice it is an availability project. Once clearance sits in the path of a B2B sale, your invoicing integration has the same operational status as your payment gateway: when it is down, you are not doing business. Build it, monitor it, and staff it accordingly — and the compliance outcome takes care of itself.