Skip to content

ERP · 6 min read

ERP and ZATCA e-invoicing: what Phase 2 integration actually requires

Phase 2 is not a PDF with a QR code. It is UBL 2.1 XML, a cryptographic stamp, onboarding to Fatoora and reporting in near real time — what that means for your ERP, and where integrations fail.

By Muhammad Junaid Khan ·

Illustrated invoice, stamp and government platform, for ZATCA e-invoicing ERP integration

Phase 1 of Saudi e-invoicing was mostly a formatting exercise: produce an electronic invoice, put a QR code on it, stop writing them by hand. Phase 2 is a different kind of requirement, and teams who treat it as more of the same discover that in the worst way. It is an integration project: your ERP has to speak to a government platform, in a specific XML dialect, with a cryptographic stamp, on the regulator's timing rather than yours.

This is a technical article for the people who have to make an existing ERP comply. It is not tax advice — thresholds and wave dates are set by ZATCA and change, so confirm your own wave and deadline with them or your tax adviser before planning around any date here.

What Phase 2 actually asks of a system

Strip away the terminology and there are five engineering requirements.

  • Invoices are generated as structured XML in the UBL 2.1 format, not as a PDF with data behind it.
  • Each invoice carries a UUID, a cryptographic stamp and a hash chained to the previous invoice, so the sequence cannot be altered after the fact.
  • A QR code encodes a defined set of fields, generated from the invoice data rather than pasted on.
  • Your system is onboarded to the Fatoora platform and holds a cryptographic identifier issued to it, which has to be renewed.
  • B2B invoices are cleared with ZATCA before they are considered valid; B2C invoices are reported within twenty-four hours.

That last distinction is the one that reshapes an ERP. Clearance is synchronous: a B2B invoice is not final until the platform says so. An invoicing flow that assumed "save, print, send" now has a network call with a regulator in the middle of it, and it has to behave properly when that call is slow, fails, or returns a rejection.

Clearance sits inside the invoicing flow. The regulator is now on the critical path.
Clearance sits inside the invoicing flow. The regulator is now on the critical path.

The four places integrations actually fail

We have been brought in to fix more of these than we have built from scratch, and the failures repeat.

The first is treating clearance as fire-and-forget. A queued job that posts the invoice and does not care about the response produces a month of invoices the company believes are valid and the regulator has never accepted. The fix is a state machine on the invoice — drafted, submitted, cleared, rejected — with rejections surfaced to a human, not buried in a log.

The second is the hash chain. Invoices must chain in sequence, which means concurrency matters. Two processes issuing invoices at once, or a retry that re-stamps an invoice already stamped, breaks the chain quietly and is discovered during an audit rather than at the time.

The third is master data. The XML requires specific, correctly formatted fields: VAT registration numbers, a national address in the prescribed format, item codes, tax categories. Most ERPs hold those somewhere, loosely validated, entered by whoever created the customer three years ago. The compliance project becomes a data-cleaning project, and that is where the schedule goes.

The fourth is credential management. The cryptographic identifier your system is issued expires. If nobody owns its renewal, invoicing stops on a date nobody has in a calendar.

Build it into the ERP, or bolt on a middleware?

Both are defensible. A certified middleware provider takes the protocol work, the certificate handling and the format updates off your team, and charges per invoice or per year. That is the right answer when your invoice volume is modest and your ERP is a product you do not control.

Building it inside the ERP makes sense when the ERP is yours, when volume makes per-invoice pricing uncomfortable, or when credit notes, prepayments and multi-entity billing make the mapping to UBL genuinely non-trivial — because in a middleware setup you still have to produce a correct payload, and that mapping is most of the work either way.

What we would not recommend is a third option people try: exporting to a spreadsheet and uploading. It works until volume rises, and it puts a manual step between a sale and a legal document.

Middleware or in-house, the mapping from your data to correct UBL is most of the work.
Middleware or in-house, the mapping from your data to correct UBL is most of the work.

A sane sequence for an existing ERP

  • Audit the master data first — VAT numbers, addresses, tax categories, item codes. Fix it before writing any integration code; it is the long pole.
  • Map every document type you issue to its UBL representation: standard invoice, simplified invoice, credit note, debit note, prepayment. Missing one is how a go-live slips.
  • Build against the sandbox, including the failure paths. Rejections, timeouts and duplicates are the code you will actually depend on.
  • Onboard, then run in parallel for a full billing cycle with reconciliation between what you issued and what was cleared.
  • Put certificate renewal in a monitored calendar with an owner, not in someone's head.

For a mid-sized ERP with reasonably clean data, that is six to twelve weeks. With messy master data it is longer, and the extra time is all in step one.

What the sandbox will not tell you

Testing against the sandbox proves your XML is well formed and your stamp is valid. It does not prove your business can operate. Three things only show up in a parallel run.

  • Volume at month end. Most businesses issue a large share of their invoices in the last two days of the month, and a clearance call per invoice behaves very differently at two hundred an hour than at two.
  • The human path for a rejection. Somebody has to see it, understand it and fix the underlying data — and that person needs a screen, not a log file. Design it before go-live or it gets designed in a panic.
  • Credit notes and corrections. Reversing a cleared invoice is not deleting it. Teams who never tested the correction flow discover it during their first real dispute.

Who owns this after go-live

Compliance integrations are not finished when they pass. The format is versioned, the regulator publishes changes, and the certificate expires on a date. Someone has to own three standing tasks: watching for specification updates, renewing credentials before they lapse, and reconciling issued invoices against cleared ones on a schedule rather than when an auditor asks.

In most companies this ends up unowned because it sits between finance and IT. Name the owner at project close-out, put the certificate expiry in a monitored calendar, and send clearance failures to a person rather than to a mailbox nobody reads.

What it costs to get wrong

ZATCA penalties for e-invoicing violations are assessed per violation and run into the tens of thousands of riyals. The larger cost is usually operational: an invoicing system that stops clearing is an invoicing system that stops invoicing, and a company that cannot bill for a week has a cash-flow problem long before it has a compliance one.

If you are staring at an ERP that was never designed for this, a technical due-diligence review is the cheapest first step — an independent read on what the integration will actually take, from $2,800, before anyone commits to a plan.

Questions readers ask about this

What does ZATCA Phase 2 require from our ERP?

Invoices generated as UBL 2.1 XML with a UUID, a cryptographic stamp and a hash chained to the previous invoice; a QR code generated from the invoice data; onboarding to the Fatoora platform with a cryptographic identifier; B2B invoices cleared with ZATCA before they are valid, and B2C invoices reported within twenty-four hours.

How long does a ZATCA Phase 2 integration take?

Six to twelve weeks for a mid-sized ERP with clean master data. The variable is almost never the protocol work — it is auditing and correcting VAT registration numbers, national addresses, tax categories and item codes, which most systems hold loosely. Budget that as the first phase, not as a detail.

Should we use a certified middleware provider or build it into the ERP?

Middleware is the right answer when invoice volume is modest and the ERP is a product you do not control — it takes protocol and certificate handling off your team for a per-invoice or annual fee. Building it in makes sense when the ERP is yours, volume is high, or credit notes, prepayments and multi-entity billing make the UBL mapping complex. Either way you still have to produce a correct payload, and that mapping is most of the work.

What are the most common integration failures?

Four: treating clearance as fire-and-forget so rejections go unnoticed; breaking the invoice hash chain through concurrency or retries; discovering mid-project that master data does not meet the format requirements; and letting the cryptographic certificate expire with no owner for its renewal. The first and last both stop invoicing outright.

What are the penalties for non-compliance?

ZATCA assesses penalties per violation, running into the tens of thousands of riyals. Confirm the current schedule with ZATCA or your tax adviser. In practice the operational cost is larger — a system that stops clearing invoices is a system that stops billing.

Can you fix an ERP we did not build?

Yes, that is most of this work. We start with a technical due-diligence review from $2,800: an independent read on the data quality, the document types in use and what the integration will genuinely take, delivered as a written plan you keep whether or not we do the build.

Something not answered here? Ask us directly — we reply within one working day.

Muhammad Junaid Khan

SoftCity Solutions

Talk to us about your project

Keep reading

More from the blog

Let's talk about what you are building

A 30-minute call, no deck and no obligation. We will tell you honestly whether we are the right fit — and who is, if we are not.

Or call +923019278056 · We reply to every enquiry within one working day.