How do I validate Codice Fiscale + P.IVA at Magento checkout?
Categories:
Magento Developer Italy
Two Italian tax identifiers, two different validators, both must be checked at checkout, not after, or you’ll get SDI rejections downstream.
- Codice Fiscale, 16 alphanumeric chars, encodes surname / name / DOB / sex / municipality. Validated by checksum + format regex (no online API needed for the algorithm; AdE has a verification endpoint for sanity).
- Partita IVA (P.IVA), 11 digits. Validated by Luhn-like checksum + via AdE’s P.IVA lookup (free service) for active status. For EU intra-Community B2B: VIES validation of the IT-prefixed P.IVA confirms eligibility for 0% reverse-charge IVA.
Magento implementation:
- Add Codice Fiscale + P.IVA fields to
customerandquote_addressentities. - Validate format + checksum client-side (instant feedback) and server-side (authoritative).
- For B2B: call VIES on save; cache 30 days; apply reverse-charge IVA (0%) if valid.
- Block checkout submission with invalid IDs, never let bad data hit SDI.
- Pre-fill billing address with the AdE-returned company name + address.
Was this helpful?