Dev Log - Week 3: Spanish Electronic Invoicing
This week I took a slightly unexpected turn from my original roadmap. My plan was to keep working on the full refactor of all three new modules using my new architecture, but I decided to temporarily shift focus to something different - Spanish electronic invoicing.
Even though in my first Dev Log I explicitly said that I wasn't going to work on another invoicing system for WHMCS, over the past months I've received many requests from Spanish users asking if my module supported "Factura Electrónica Española". Eventually, I gave in.
Since I already developed electronic invoicing for multiple countries, including the Italian version (by far the most complex one), implementing the Spanish one turned out to be surprisingly easy. Thanks to all the groundwork I've already laid out, I was able to reuse a lot of components and logic. In less than a day, I was already generating valid Spanish e-invoices (XML files) fully compliant with the national standard.
Below is a summary of what's already working in the new plugin for Billing Extension - the module I'm rewriting from scratch.
- Configurable options for all company and issuer details used in the XML structure
- Full support for credit notes (facturas rectificativas)
- Automatic mapping of all invoice data from WHMCS snapshots
- Updated VIES validation for compatibility with Spanish e-invoicing rules
- Full logging system tracking XML generation, deletion, manual overrides, and user-specific rules
- Option to define the start date for generating electronic invoices
- Option to enable e-invoicing only for Spanish clients or globally
- Automatic client type detection (intra-EU, extra-EU, business, private, Spanish company/private)
- Fully customizable XML file naming and folder hierarchy using auto-tags (eg. year, month, type, currency, country, random strings etc.)
- View, download, delete, and regenerate XML files directly from WHMCS invoice view
- Cron support to issue XML files automatically on a daily basis
- Dedicated module page for bulk actions, downloads and invoice/e-invoice status overview
- System Requirements check: before generating any XML, the system validates that all required information is present and correctly formatted. If something is missing or invalid, the admin is redirected to a detailed page that explains what needs to be fixed
- Per-invoice validation system: when attempting to generate a specific XML, the module performs a detailed check of that invoice's data. If required fields (like client address, VAT number etc.) are missing, the generation process stops and the system displays a visible warning both in the invoice view and in the logs, making it easy for admins to fix and retry
- Custom folder and file structure system: by using "autotags", users can define their own storage hierarchy (e.g. /2025/February/Invoices/ or /2025/02/CreditNotes/) and customize XML filenames with any combination of variables, including year, month, client country, currency and many more
In short, Spanish e-invoicing integration is already up and running with a rich set of features and flexibility. I share some screenshots to illustrate how it looks in practice.
What's Next
At this point, I've reached a stage where I can easily generate XML files that seem fully compliant with the Spanish electronic invoicing format. However, there's one big question left: what should I actually do with these XML files?
Unfortunately, I haven't been able to find detailed documentation in English explaining how the Spanish e-invoicing process works in practice. I can only assume it might be similar to the Italian system, where invoices are uploaded to a government portal or submitted through a specific API, possibly with a digital signature involved. But I'm not entirely sure. Maybe users simply download the XMLs and manually upload them to a platform I'm not aware of?
So, if you're a Spanish WHMCS user or you're familiar with how electronic invoicing works in Spain, I'd really appreciate your help!
Comments (0)