RideKit
Docs/Reference/ZATCA Phase 2 e-invoicing (Saudi Arabia)

ZATCA Phase 2 e-invoicing (Saudi Arabia)

Built: 2026-11-02. For the operator, and for whoever maintains the code.

In Saudi Arabia, every ride invoice must be a ZATCA Phase 2 ("Integration") simplified tax invoice:

  • a UBL 2.1 XML document;
  • stamped with the platform's own key;
  • chained to the invoice before it;
  • reported to ZATCA within 24 hours;
  • with a QR the rider can scan.

RideKit does all of this itself, with no SDK and no extra dependencies.

Onboarding (Admin → Tax → ZATCA e-invoicing)

  1. On the FATOORA portal (fatoora.zatca.gov.sa), choose Onboard new solution unit and generate an OTP. It is valid for one hour.

  2. In RideKit, choose the environment:

    • Developer sandbox for trying it out;
    • Simulation for a rehearsal with real taxpayer details;
    • Production for live invoicing.

    Then enter the OTP and the seller's registered details:

    • name, VAT number and commercial registration number;
    • the national address (street, 4-digit building number, district, city, 5-digit postal code);
    • branch name and business category.
  3. Press Onboard with ZATCA. RideKit then:

    • creates the unit's secp256k1 key and a CSR carrying the unit serial, VAT number and the invoice types it issues (simplified only);
    • obtains the compliance certificate;
    • passes ZATCA's three compliance documents (an invoice, a credit note and a debit note);
    • obtains the production certificate.

    The card shows each check's result. The key and secret are stored encrypted.

To move from Simulation to Production, onboard again with a production OTP. The chain starts again for the new unit.

What happens for every ride

  • At completion. The invoice is stamped, which takes these steps:

    • the next invoice counter (ICV) is assigned;
    • the previous invoice's hash is recorded (PIH);
    • the invoice is hashed and signed (XAdES, ECDSA secp256k1);
    • the nine-tag QR is built.

    The stamped XML is stored privately. The invoice shows as Pending on the Tax page.

  • Within a minute. The invoice is reported to ZATCA. It becomes Issued once ZATCA answers REPORTED; any warnings are kept.

    • A rejection (HTTP 400) is kept with ZATCA's messages under Rejected by ZATCA.
    • A server error or timeout is retried with backoff.
  • On the rider's receipt. The invoice QR is shown with the line "Scan to check this tax invoice".

  • Voiding an invoice (Tax page → the invoice → Void) issues a credit note on the same chain, referring to the invoice by number, with the reason. The credit note is reported the same way. A rejected credit note is stamped afresh by Report again. A rejected invoice is sent again unchanged, because it is the rider's invoice.

Things to know

  • No credentials under Providers. The old ZATCA fields (token, secret, URL) are gone. They never produced a real filing.
  • Currency. Use SAR. ZATCA expects the tax currency to be SAR.
  • VAT rate. A credit note takes the original invoice's rate. ZATCA accepts only 15% or 5% for standard-rated supplies (BR-KSA-84). Working the rate back from rounded amounts gave 14.94%, and ZATCA refused it in testing.
  • Legal check needed. Confirm with a Saudi tax adviser before going live:
    • that the seller's details are as registered;
    • that domestic passenger transport is standard-rated (15%);
    • who the seller of record is in your model (the operator, or the drivers).

For developers

Piece Where
DER / ASN.1 (CSR, certificate signature) backend/src/tax/zatca/der.ts
Key and CSR, environments and base URLs tax/zatca/csr.ts
UBL invoice / credit / debit, hash, XAdES, QR tax/zatca/invoice-xml.ts (stampInvoice, canonicalPure)
Onboarding, chain, reporting cron, credit notes, retry tax/zatca/zatca-phase2.service.ts
API GET /tax/zatca, POST /tax/zatca/onboard, POST /tax/zatca/documents/:uuid/retry
Provider tax/providers/zatca-tax.provider.ts (Phase 2 when onboarded, else Phase 1)
Data zatca_egs (one unit) and zatca_documents (migration 126); XML under zatca/<env>/ in storage
Admin components/tax/ZatcaCard.tsx
Rider invoice_qr on the receipt (RidesService receipt), shown in trip/[id].tsx
Tests tax/zatca/zatca.spec.ts

Hashing. The invoice is written already canonical:

  • no self-closing tags;
  • namespace declarations first, then attributes in sorted order;
  • escaped text.

So the hash is SHA-256 over the text with UBLExtensions, cac:Signature and the QR reference cut out. Each cut leaves its indentation line behind, as C14N's XPath filter does. Python's C14N gives the same text, apart from where the namespace declarations sit.

Tested end to end

Against ZATCA's developer sandbox (gw-fatoora.zatca.gov.sa), with ZATCA's documented test VAT number and OTP:

Step Result
CSR → compliance certificate ISSUED
Compliance invoice / credit note / debit note PASS, PASS, PASS (no warnings)
Production certificate ISSUED
Reporting a stamped invoice PASS, REPORTED

Through the platform (install switched to Saudi Arabia, SAR):

  • Chrome, Tax page: onboarding against the sandbox finished with three checks PASS, and the card showed "Reporting".
  • A ride completed in the app flow:
    • its invoice was stamped (ICV 1, Pending);
    • the cron reported it, and it became Issued (REPORTED).
  • Void from the Tax page:
    • the credit note was rejected with BR-KSA-84, the rate bug above, which was then fixed;
    • Report again stamped a corrected credit note (ICV 3), which was REPORTED.
  • iOS simulator: the rider's receipt showed the QR. Decoded from the screenshot, it carries all nine tags (seller, VAT number, time, total 10.00, VAT 1.30, hash, signature, public key, certificate signature).

Not tested: Simulation and Production onboarding, which need a real taxpayer's FATOORA OTP. Debit notes are only produced in the compliance step; the platform does not issue them otherwise.

source: docs/zatca-phase2.md (ships identically in the product zip)