=== Factova – VeriFactu: AEAT invoices for WooCommerce ===
Contributors: alvaroalon96
Tags: verifactu, facturas, aeat, woocommerce invoices, facturacion
Requires at least: 6.7
Tested up to: 7.1
Requires PHP: 8.2
Stable tag: 0.2.10
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

VeriFactu for WooCommerce: invoices every order, adds the tax QR code and sends each billing record to the Spanish AEAT. Free, with no invoice limit.

== Description ==

**Factova** brings **VeriFactu** to your WooCommerce shop. It issues the invoice of every order when it is paid (or when it is completed, if you prefer), adds the tax QR code and sends the billing record to the AEAT (Agencia Tributaria, the Spanish Tax Agency, "Hacienda"), as the VERI*FACTU system requires.

It is free and complete: there is no limit on the number of invoices or orders, and it does on its own everything VeriFactu requires. Your shop talks directly to the AEAT with your own electronic certificate: there is no intermediary service and no fee per invoice.

= What VeriFactu means for your shop =

VeriFactu is the mode of the Spanish billing systems regulation (Royal Decree 1007/2023) in which the invoicing software sends every billing record to the AEAT when the invoice is issued. For a WooCommerce shop this means:

* every invoice creates a **billing record** with a fingerprint chained to the previous one;
* the record is **sent to the AEAT** automatically;
* the invoice carries the **tax QR code** and the "VERI*FACTU" legend, so your customer can check it on the AEAT website;
* mistakes are corrected with corrective invoices or corrections, never by editing or deleting an invoice.

Factova does all of this inside WooCommerce, from the order to the PDF your customer receives.

= What Factova does =

* **Invoices from orders**: complete invoice (F1) when the customer gives a tax ID or the law requires it; **simplified invoice** (F2) up to 400 € (3,000 € for retail sales); invoice that replaces simplified invoices (F3).
* **Corrective invoices**: R1 and R5 created automatically from WooCommerce refunds; R2, R3, R4 and corrections by substitution, one by one.
* **Manual invoices** without an order.
* **Chained billing record** (SHA-256 fingerprint), stored so that it cannot be edited or deleted. Corrections and cancellations create new records and never change the previous ones.
* **Automatic submission to the AEAT** through the VeriFactu web service with your electronic certificate (your own, a representative's or a company seal), following the waiting times of the AEAT and retrying after an outage.
* **PDF with QR code** (verifiable on the AEAT website), two templates with your logo and your colour, attached to the WooCommerce emails, in My Account and on the order confirmation ("Order invoice" block).
* **Block and classic checkout**: tax ID field (Spanish NIF/NIE/CIF or EU VAT number) with validation, required above the simplified invoice limit.
* **Optional VIES check** of EU VAT numbers and, if you enable it, removal of the Spanish VAT from intra-Community supplies before payment.
* **Equivalence surcharge** (recargo de equivalencia), exports and exempt operations, with their tax mapping.
* **Setup wizard** with express consent before any connection with the AEAT, and a connection test.
* **Email alerts** (rejections, certificate about to expire, paused submissions), **daily chain verification** and detection of **copies of the site** (staging) and of **restored backups**.
* **Exports**: billing records in XML, invoices and tax lines in CSV, and PDFs in ZIP.
* **Read-only WP-CLI**: `wp factova status|verify|invoices|doctor`.
* Compatible with **HPOS** (high-performance order storage) and with the classic order storage.
* **In the language of your WordPress**: the screens follow the language of each user, and the invoice PDF the language of the site.

= Who it is for =

Factova is for one taxpayer (a company or a self-employed person) with its tax domicile in the Spanish common territory, that sells with VAT (IVA) in a WooCommerce shop and wants to comply with VeriFactu without leaving WordPress. It works only in the VERI*FACTU mode.

= How it works =

1. Install Factova and open *WooCommerce > Invoices*.
2. The wizard asks for your tax data, your electronic certificate and your VAT configuration, and asks for your consent before connecting to the AEAT.
3. Start in the AEAT test environment and check your first invoices with your adviser.
4. Switch to production. From then on, every order gets its invoice when it is paid (or when it is completed, if you chose that), its billing record is sent to the AEAT and the customer receives the PDF with the QR code.
5. Refunds get their corrective invoice automatically; for a cancelled order, Factova proposes the corrective invoice in Pending. The Overview screen tells you if anything needs your attention.

= Who it is not for =

Factova is **not** for:

* taxpayers under the **SII** (Suministro Inmediato de Información), who are outside VeriFactu;
* businesses with their tax domicile in the **Basque Country or Navarre** (TicketBAI and regional systems);
* sales with **IGIC or IPSI** (Canary Islands, Ceuta and Melilla): they will arrive in version 1.1.

The setup wizard asks, and does not let you continue in those cases.

= Responsibility and warranty =

Factova is distributed **without any warranty**, under the GPL. **The correct issuing of your invoices and your tax configuration (VAT rates, exemptions, regimes, equivalence surcharge) are your responsibility: review them with your tax adviser.** The plugin proposes a mapping for the usual rates, but it cannot know whether a given operation is exempt or taxed.

Factova does not replace your adviser nor your obligation to keep your invoices. Keep it updated and do not edit its database tables.

= Responsible declaration =

Every version includes its **responsible declaration** of the billing system (art. 13 of Royal Decree 1007/2023 and art. 15 of Order HAC/1177/2024), in *WooCommerce > Invoices > About* and as a PDF inside the plugin. Public copy: https://factova.es/factova/declaraciones/

Factova is not approved or certified by the AEAT: VeriFactu has no approval process; the producer declares compliance.

= No advertising, no tracking =

Factova sends no data to the plugin author. It shows no advertising on the Dashboard, in orders or in notices. Everything that needs your attention is listed in its Overview; outside its own screens it only shows a notice on the WooCommerce order screens when issuing is stopped, and you can hide it. The PDFs and the emails to your customers carry no advertising.

= Factova Pro =

Factova is complete and compliant without the Pro version. Factova Pro is a paid extension, installed separately, with features for shops with more volume, several companies and accounting firms:

* **Several companies and shops:** several tax IDs in the same shop, series by channel or by rules, and a network panel in multisite.
* **Peace of mind:** an "all-square" check with the AEAT (Factova Pro asks the AEAT which invoices it has on record and confirms that they match the ones in your shop, and warns you if something does not match), alerts through Slack and webhook, and a copy of the alerts to your accounting firm.
* **Accounting firms and bookkeeping:** VAT invoice ledger (XLSX), export to A3, Contasol and Holded, VAT and OSS reports, scheduled sending to the accounting firm and read-only access for it.
* **Volume:** invoicing of earlier periods and corrective invoices in batches, correction by lines, F3 from My Account, customer tax ID kept in WooCommerce Subscriptions renewals and invoice attached to WooCommerce Point of Sale receipts (Factova already invoices those orders).
* **Design:** PDF template editor, WPML and Polylang.

Plans from 99 €/year, with a 14-day trial without a card. More information at https://factova.es/pro/

== External services ==

Factova connects to two external services, both run by public administrations: the **AEAT** (Spanish Tax Agency), because the VERI*FACTU system requires that every billing record is sent to it, and, only if the administrator enables it, **VIES** of the European Commission. Factova connects to the AEAT only after the administrator gives express consent in the setup wizard (the connection test of the wizard comes after that consent), and to VIES only if the administrator enables it in the settings. Until then, nothing leaves the site.

Factova does **not** connect to the plugin author, to factova.es, to any account, sales or payment service, or to any other server. There is no tracking, no telemetry and no remote content. The links to factova.es and wordpress.org inside the plugin are plain links that the administrator may open; Factova never requests them.

= 1. AEAT (Agencia Estatal de Administración Tributaria): VERI*FACTU web service =

The Spanish Tax Agency runs the VERI*FACTU web service, where invoicing software sends the billing records of the invoices it issues (Royal Decree 1007/2023 and Order HAC/1177/2024). This is the legal purpose of the plugin and it cannot work without it.

* **What it is used for:** to send to the AEAT the billing record of every invoice, corrective invoice, correction (subsanación) and cancellation (anulación) the shop issues, and to receive its answer (accepted, accepted with errors or rejected).
* **Data sent:** tax ID (NIF) and name of the issuer; series, number and date of the invoice; invoice type; tax ID (NIF), EU VAT number or foreign identification, and name of the customer (complete invoices only); description of the operation; tax bases, rates and amounts, equivalence surcharge and exemptions; totals; references to the corrected or replaced invoices; the fingerprint (huella) of the record and the one of the previous record; the date and time the record was generated; and the identification of the software (name, version and installation number). The connection is authenticated with mutual TLS using the electronic certificate (.p12/.pfx) uploaded by the merchant: its public part is presented to the AEAT server; the private key never leaves the site.
* **When:** automatically after issuing every invoice, corrective invoice, correction or cancellation, following the waiting time set by the AEAT, and in the automatic retries after an outage. In the setup wizard, after the consent, the connection test opens a connection with the certificate and reads the service description (`?wsdl`), without sending any invoice data. Nothing is sent before that consent, nor from a site detected as a copy of the shop.
* **Endpoints:** production `https://www1.agenciatributaria.gob.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP` (`https://www10.agenciatributaria.gob.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP` with an electronic seal certificate); test environment `https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP` (`https://prewww10.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP` with a seal). The addresses are fixed in the code and cannot be changed by a filter.
* **QR code (not a connection of the plugin):** the PDF of each invoice carries the tax QR code that the regulation requires. It contains an address of the AEAT checking service with the tax ID of the issuer, the number, the date and the total of the invoice: production `https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQR`, test `https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR`. The plugin only prints it and **never calls it**; the customer who scans the code opens it.
* **About the service:** https://sede.agenciatributaria.gob.es/Sede/iva/sistemas-informaticos-facturacion-verifactu.html
* **Terms of use (legal notice) of the AEAT e-office:** https://sede.agenciatributaria.gob.es/Sede/condiciones-uso-sede-electronica/aviso-legal.html (general conditions: https://sede.agenciatributaria.gob.es/Sede/condiciones-uso-sede-electronica.html)
* **Privacy policy (data protection) of the AEAT:** https://sede.agenciatributaria.gob.es/Sede/condiciones-uso-sede-electronica/datos-personales.html

= 2. VIES (VAT Information Exchange System) of the European Commission =

VIES is the service of the European Commission that tells whether a VAT number of another EU country is registered for intra-Community operations. It is **optional and disabled by default**.

* **What it is used for:** to check the EU VAT number that a customer from another EU country types at checkout, so that the invoice and, if the merchant enables it, the removal of the Spanish VAT from an intra-Community supply rely on a valid number.
* **Data sent:** the country code and the VAT number the customer typed. Only if the merchant also enables "request identifier", the merchant's own VAT number (ES + NIF), so that VIES returns a consultation number that proves the check. No name, address, email, order or amount is sent.
* **When:** only if the merchant enabled the VIES check in *WooCommerce > Invoices > Settings*, when a customer with a VAT number of another EU country places an order (block and classic checkout) and, if the merchant also enabled the removal of the Spanish VAT for intra-Community supplies, when that customer updates the checkout before paying. A definitive answer (valid or not valid) is kept for 24 hours, so the same number is not checked twice in that time. VIES being down never blocks the checkout.
* **Endpoint:** `https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number` (the same in test and in production).
* **About the service:** https://ec.europa.eu/taxation_customs/vies/
* **Legal notice of the European Commission:** https://commission.europa.eu/legal-notice_en
* **Privacy policy of the European Commission:** https://commission.europa.eu/privacy-policy-websites-managed-european-commission_en

== Installation ==

1. Install and activate WooCommerce 10.0 or later.
2. Install Factova from *Plugins > Add Plugin* and activate it.
3. Open *WooCommerce > Invoices* and follow the wizard: requirements, scope, issuer data, electronic certificate (.p12 or .pfx), environment (test or production), tax configuration, consent and connection test.
4. Start in the **AEAT test environment**. When you have reviewed everything with your adviser, switch to production (once in production you cannot go back to test).

Until you finish the wizard, Factova does not connect to any external service and issues no invoices: orders stay pending and can be invoiced later.

== Frequently Asked Questions ==

= What is VeriFactu (VERI*FACTU)? =

It is the mode of the Spanish billing systems regulation (Royal Decree 1007/2023, often called the "ley antifraude", the anti-fraud law) in which the software sends every billing record to the AEAT when the invoice is issued. It is also written "veri factu" or "sistema verifactu".

= Is VeriFactu mandatory? =

The regulation applies to companies and self-employed people in the Spanish common territory who issue invoices with software, with exceptions such as the taxpayers under the SII. Their software must meet the requirements of the regulation in one of two modes: VERI*FACTU, which sends every record to the AEAT, or NO VERI*FACTU, which keeps signed records and an event log. Whether and from when it applies to you is something to confirm with your tax adviser.

= When does it apply? Has it been postponed? =

The dates are set by Royal Decree 1007/2023 and have already been changed more than once. We do not write them here because they can change again: check the website of the AEAT or our page with the current status, which we update when the Official State Gazette (BOE) publishes changes: https://factova.es/plazos-verifactu/

= Is Factova free? =

Yes. Factova is free software under the GPL and has no limit on invoices, orders or customers. It does not need any external account or paid service: it sends the records directly to the AEAT with your certificate.

= Does Factova support the NO VERI*FACTU mode? =

No. Factova works only in the VERI*FACTU mode: every record is sent to the AEAT when the invoice is issued.

= Does it work in the Canary Islands, Ceuta and Melilla, the Basque Country or Navarre? =

Not yet if you sell from the Canary Islands, Ceuta or Melilla with IGIC or IPSI: that will arrive in version 1.1. If your shop is in the peninsula or the Balearic Islands and ships goods to the Canary Islands, Ceuta or Melilla, Factova invoices those orders as exports, without VAT; the tax configuration step explains how to set the rates. Businesses with their tax domicile in the Basque Country or Navarre use TicketBAI and other regional systems, which Factova does not cover. The setup wizard asks about this before you start.

= Is it the same as electronic invoicing (factura electrónica)? =

No. VeriFactu is about the records that billing software sends to the AEAT. Mandatory electronic invoicing between businesses is a different obligation, with its own rules and dates. Factova issues PDF invoices with the VeriFactu QR code; it does not create structured e-invoices (such as Facturae) nor send them to e-invoicing platforms.

= Does the AEAT offer a free invoicing application? =

Yes, the AEAT offers a free application to issue invoices by hand, one by one. It is not connected to your WooCommerce orders. Factova creates the invoice from each order, with the customer and tax data of the order.

= Can I use it if I am self-employed (autónomo)? =

Yes. Factova works for one taxpayer, a company or a self-employed person, with its tax domicile in the Spanish common territory and with VAT.

= Does it work with the WooCommerce block checkout? =

Yes. The tax ID field is added with the additional fields API of the block checkout, and it also works in the classic checkout.

= Does it issue simplified invoices? =

Yes. If the customer gives no tax ID and the amount is within the limit (400 €, or 3,000 € for retail sales), a simplified invoice (F2) is issued. Above it, the checkout asks for the tax ID. If the customer later asks for a complete invoice, you can issue an invoice that replaces the simplified one (F3).

= Does it invoice subscription renewals and point of sale orders? =

Yes. Renewals of WooCommerce Subscriptions and orders from WooCommerce Point of Sale are WooCommerce orders, and Factova invoices them like any other order. As with any order, a renewal without the customer's tax ID gets a simplified invoice, or waits in Pending if it is above the simplified invoice limit.

= What is FACTOVA_SECRET? Do I need it? =

No, you do not need it, and the wizard does not ask for it. Factova encrypts your certificate and signs its internal records with a key that, by default, comes from the security keys of WordPress (the salts of wp-config.php). If someone changes those keys (some security plugins and hosting migrations do it), Factova pauses issuing, you confirm it in *Invoices > Tools* with your WordPress password and you upload your certificate again: no invoice is lost.

FACTOVA_SECRET is an optional, advanced line for wp-config.php, for developers, agencies and shops that move between servers, so that the key does not depend on the WordPress security keys. *Invoices > Tools* explains it in a folded block and gives you the line. If you add it before the first invoice, Factova adopts it on its own. If your shop already has invoices, Factova pauses issuing until you confirm the new key in *Invoices > Tools*. Normally your certificate is kept; only if the check with the previous key fails, or the previous key is gone, Tools tells you to upload it again. If the security keys of wp-config.php are missing or are the sample ones, Factova cannot protect anything and does not issue until FACTOVA_SECRET exists.

= Do I need an electronic certificate? =

Yes, to send the records to the AEAT: your own, your representative's (for example, your accounting firm) or an electronic seal. It is stored encrypted and is never shown or exported.

= How do I get the .p12 or .pfx file of my certificate? =

If the certificate is installed in your browser, export it with its private key as a .p12 or .pfx file: on Windows, from Internet Options > Content > Certificates > Export; on Mac, from Keychain Access. When you export it you choose a password, which is the one Factova asks for. If your accounting firm files your taxes, ask it for the file.

= How do I switch from test to production? =

In Invoices > Overview, press "Go to production…", review the checklist and type PRODUCTION to confirm. Then give the consent for production and repeat the connection test. You cannot go back to test.

= Can I try it without sending real invoices to the AEAT? =

Yes: the AEAT test environment has no tax validity. Test invoices carry a watermark and are never sent to your customers.

= What happens if the AEAT service is down? =

The invoice is issued anyway, because issuing happens in your shop and the submission comes afterwards: in production, the customer receives it with the order email and in My Account. Factova keeps the record, follows the waiting time of the AEAT and sends it again automatically when the service is back. With the email alerts on (the default), you receive an alert when the AEAT cannot be reached, and another one if records are still waiting after 24 hours.

= What happens if I change an invoice or an order? =

Invoices and records cannot be changed. A mistake is corrected with a correction of the record, a corrective invoice or, if the invoice should never have been issued, a cancellation. Factova warns you if the order changes after it was invoiced.

= What happens if an invoiced order is cancelled? =

The invoice is never deleted nor cancelled at the AEAT. The order moves to *Invoices > Pending* as "cancelled with invoice" and Factova proposes a corrective invoice (R1, or R5 if it was simplified) for the outstanding amount, which you issue with one click. Refunds already made are deducted. The same happens if an invoiced order goes back to failed or pending payment. If you prefer to invoice only completed orders (useful with many cancellations or with cash on delivery), choose it in the wizard or in Settings.

= Can I keep another invoice plugin? =

Turn off its invoices: two systems invoicing the same orders produce duplicate numbering and invoices outside VERI*FACTU. Its packing slips can stay. Factova warns you if it detects another invoicing system, but it never blocks or deactivates anything.

= What happens if I clone the shop to a staging site? =

Factova detects the copy and stops issuing and sending in it, so a copy never duplicates invoice numbers nor sends to the AEAT.

= What happens if I deactivate or uninstall the plugin? =

Deactivating it deletes nothing, but while it is deactivated orders get no invoice. Uninstalling it **does not delete the invoices nor the billing records**: the law requires you to keep them. It does delete the stored certificate, the temporary state and the capabilities. You can export everything from *Invoices > Tools*. Deleting the tables when the legal retention period ends is up to you.

= Is Factova approved by the AEAT? =

VeriFactu has no approval process. The producer of the software signs a responsible declaration for every version, which you can read in *Invoices > About* and at https://factova.es/factova/declaraciones/

= In which language is Factova shown? =

In the language of your WordPress: the screens in the language of each user's profile; the customer emails, the PDF and My Account in the language of the site. WordPress downloads the translations automatically from translate.wordpress.org.

= Why does Factova use cURL directly? =

Sending the records to the AEAT needs a connection with a client certificate (mutual TLS). Factova sends the request through the WordPress HTTP API (`wp_remote_request`) and only adds, with the `http_api_curl` filter, the cURL options for the certificate of the issuer, which is decrypted in memory. The WordPress HTTP API has no option for a client certificate; if the server does not support certificates in memory, a private temporary file (permissions 0600) is used, overwritten and deleted at the end.

= Where is the source code of the JavaScript? =

In the plugin itself: `assets/src/` contains the source code of all the scripts and styles in `build/`. To build it: `npm install` and `npm run build` (with `@wordpress/scripts`, see `package.json` and `webpack.config.js`).

= What should I do before and after restoring a backup? =

A restored backup takes the database back to an earlier moment, but the AEAT already has the invoices that were sent afterwards. If Factova used those numbers again, the AEAT would answer "duplicate record".

* **Before restoring:** if you can, put the shop in maintenance mode and write down the last number of each series (in Invoices or in the AEAT e-office).
* **After restoring:** do not issue invoices. Go to *Invoices > Tools*, section "The database looks restored from an older backup". Factova proposes the last number of each series from what the AEAT answered. Check it in the AEAT e-office, confirm it with your WordPress password, and Factova continues each series after that number, with a new chain. Orders that arrived in the meantime wait in Pending.
* **If you did not notice:** Factova detects it through the mark it keeps outside the database or, if the hosting also restored the files, through the first "duplicate" answer of the AEAT. From then on it pauses issuing for that issuer in that environment and takes you to Tools.
* **Installation number:** the recovery gives a new installation number to the whole shop. If the restore only affected the test environment but you already invoice in production, your production invoices also continue in a new chain (numbers and series do not change); Tools warns you before you confirm.

== Screenshots ==

1. The VeriFactu invoice your customer receives: PDF with your logo, the tax QR code and the "VERI*FACTU" legend (here a test invoice, with its watermark).
2. Block checkout: the customer asks for a complete invoice and types the tax ID, which is checked before the order is placed.
3. Order confirmation with the "Order invoice" block: the link to the PDF once the invoice is issued or, as here with a bank transfer not yet received, a note that the invoice will arrive by email.
4. Overview: everything that needs your attention in a single list, with a button for each item, and the switch to production.
5. Invoices: list with the type, the customer, the order and the AEAT status; corrective invoices link to the invoice they correct.
6. Invoice detail: its AEAT status in one sentence, the tax breakdown and the answer of the AEAT.
7. Pending: every waiting order says what to do, with the corrective invoice of a cancelled order already proposed.
8. WooCommerce order with its invoice, the corrective invoice of a refund and their AEAT status.
9. Setup wizard: tax configuration of the VAT rates and when the invoice is made.
10. Setup wizard: express consent before anything is sent to the AEAT, and the connection test.

== Changelog ==

= 0.2.10 =
* The setup wizard no longer asks for FACTOVA_SECRET: it is an optional, advanced setting explained in Invoices > Tools.
* Adding FACTOVA_SECRET before the first invoice no longer pauses issuing; with invoices, the confirmation in Tools normally keeps the certificate.
* The confirmation of a key change no longer deletes a certificate that any available key can still read, and the orders and refunds that were waiting are invoiced on their own.
* Notices only on the WooCommerce order screens and only when issuing is stopped; the rest is in the Overview of Factova.
* Every request that changes data checks its nonce before reading anything else.
* The External services section describes every connection in detail.

= 0.2.9 =
* First public release: VeriFactu invoices for orders, issued automatically when they are paid; corrective invoices for refunds and cancellations; manual invoices; automatic submission to the AEAT; PDF with QR code; setup wizard with express consent; email alerts; exports and read-only WP-CLI.

== Upgrade Notice ==

= 0.2.10 =
FACTOVA_SECRET becomes optional; a key change no longer deletes a readable certificate.

= 0.2.9 =
First public release.
