Invora v1.4
Saudi ZATCA Phase 2 · ZATCA-PIH-MISMATCH

How to Fix ZATCA-PIH-MISMATCH (Broken ICV / PIH Chain)

Concurrent POS or ERP workers read the same last_pih and last_icv before committing, causing ZATCA Fatoora to reject out-of-order hashes.

Exact Fix

Invora REST prevents this automatically by locking the EGS device row with PostgreSQL SELECT ... FOR UPDATE inside a single transaction from the genesis PIH.

Failing Payload
// Anti-pattern: parallel workers reading last_pih without DB row locks
const pih = await db.getLastPih(egsSerial);
Fixed Payload
// Invora handles row locking automatically per egsSerialNumber:
{
  "format": "SA_ZATCA",
  "egsSerialNumber": "1-POS|2-V1|3-001",
  "zatcaInvoiceSubtype": "0200000"
}
Verify Fix via Free Preflight API
curl -sS -H "Authorization: Bearer tb_live_your_key" https://api.invora.dev/v1/zatca/csids

What is the ZATCA genesis PIH hash for ICV = 1?

Base64(SHA-256("0")), which equals NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==.