Chat on WhatsApp

NIF + NIE + CIF + DNI, validación de identificadores fiscales en checkout

Spain has four different identifier formats and a Magento store touching B2B or invoicing needs to validate them correctly:

  • DNI (Documento Nacional de Identidad), 8 digits + 1 letter (e.g. 12345678Z). Spanish citizens. Letter is checksum-derived from the digits.
  • NIF (Número de Identificación Fiscal), for residents, the NIF = DNI. For foreigners, NIF can equal NIE.
  • NIE (Número de Identidad de Extranjero), letter (X/Y/Z) + 7 digits + 1 letter (e.g. X1234567L). Foreign residents.
  • CIF (Código de Identificación Fiscal), companies pre-2008. Letter + 7 digits + 1 control character (e.g. A12345674). Replaced by NIF-J / NIF-A for new SLs, but huge install base still uses CIF.
  • VAT ID (NIF-IVA), ES + NIF/CIF for EU intra-community trade. Validated via VIES.

Magento integration:

  1. Add identifier-type selector + value field to checkout + customer registration.
  2. Apply the correct checksum algorithm per type (each is different, DNI uses mod-23, CIF uses a different control char calculation).
  3. For B2B / VIES, on a valid VIES-validated ES+CIF, apply 0% IVA reverse-charge for intra-EU sales.
  4. Print the validated identifier on every Magento invoice (mandatory under AEAT rules).
Was this helpful?