=== TiendaFactu – Invoices for Verifactu ===
Contributors: valerisstudio
Tags: verifactu, invoices, woocommerce, aeat, spain
Requires at least: 6.4
Tested up to: 7.0
Requires PHP: 8.0
Stable tag: 0.5.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Legally numbered invoices and AEAT (Verifactu) submission for Spanish WooCommerce stores. Get ready for the anti-fraud law before 2027.

== Description ==

Verifactu becomes mandatory in Spain on January 1st, 2027 for companies and July 1st, 2027 for freelancers (RD-ley 15/2025). TiendaFactu prepares your WooCommerce store:

* **Automatic invoices** with legally correct series and sequential numbering when each order is completed.
* **Validated NIF/CIF field** at checkout (classic and block-based).
* **Corrective invoices** (facturas rectificativas) issued automatically on refunds.
* **Real AEAT submission and protected test mode**: separate API keys for test and production prevent the mode selector from reusing a live credential by accident.
* **Readiness assistant**: a checklist that tells you exactly what is missing, including SII and TicketBAI (Basque Country) exemption detection.
* **Audit trail** for every invoice: creation, submission, AEAT response.
* **Real-time AEAT confirmations** via webhooks, with an hourly fallback check.
* Compatible with HPOS and block-based checkout.

**Exemptions:** if you report VAT through SII or are based in the Basque Country (TicketBAI), Verifactu does not apply to you. The readiness assistant detects both cases.

The plugin interface is fully available in Spanish.

TiendaFactu is an independent plugin by Valeris Studio. It is not affiliated with, endorsed by or sponsored by the AEAT (Spanish Tax Agency), the VERI*FACTU program, Verifacti or WooCommerce/Automattic.

== External services ==

This plugin connects to the Verifacti API (https://api.verifacti.com), a third-party technical provider for Verifactu submissions, to submit invoice records to the AEAT (Spanish Tax Agency) and retrieve their acceptance status. The AEAT does not certify or authorize commercial invoicing applications; each producer publishes its own responsible declaration. You need your own Verifacti account and the correct API key for each environment. Without a configured key, TiendaFactu does not consume fiscal numbering or issue a new invoice. Optionally, our paid service TiendaFactu Conecta (https://tiendafactu.es) can manage the provider account for you.

Data sent to Verifacti, only when an invoice or corrective invoice is submitted or its status is checked: invoice series, number and issue date, tax breakdown and totals, an order description, and the customer's name and NIF when provided (required by the AEAT for full invoices). No data is sent while the plugin is idle or for orders without invoices.

Verifacti is operated by Bilbabit S.L.: [Terms and conditions](https://www.verifacti.com/terminos), [Privacy policy](https://www.verifacti.com/privacidad), [Legal notice](https://www.verifacti.com/aviso-legal).

Optionally, Verifacti can send webhook notifications back to your site (AEAT confirmations); this is inbound only and configured by you in the Verifacti dashboard.

If you purchase the optional TiendaFactu Conecta service from within this plugin's settings page, the plugin sends an activation request to our own server at https://tiendafactu.es/conecta (operated by Valeris Studio, the plugin's author) to verify your purchase and connect your store. Data sent: your Freemius license and installation identifiers, your store's site URL, and your account email — no invoice or customer data. A random per-installation token protects later status checks. This request is only made after a Conecta purchase and afterwards while confirming the connection; it is never sent otherwise. See https://tiendafactu.es/terminos.html and https://tiendafactu.es/privacidad.html.

== Frequently Asked Questions ==

= When does Verifactu become mandatory? =

January 1st, 2027 for companies (corporate income tax payers) and July 1st, 2027 for freelancers (RD-ley 15/2025).

= Do I need a digital certificate? =

No. Submission is handled through a third-party technical provider, with no certificates installed on your hosting.

= Does this plugin work outside Spain? =

Verifactu is a Spanish tax regulation, so the plugin is only useful for stores invoicing under Spanish common-territory tax rules.

== Screenshots ==

1. Invoice list with real-time AEAT status, CSV codes and manual resend for rejected invoices.
2. "Are you ready for Verifactu?" assistant: legal deadlines and a 7-step readiness checklist.
3. Settings: sandbox/production mode, invoice series and webhook URL for instant AEAT confirmations.
4. Customer-facing invoice with the official VERI*FACTU QR code, printable as PDF.

== Changelog ==

= 0.5.1 =
* Safety: test and production now use separate API keys; production requires explicit confirmation and each invoice keeps its original environment.
* Test invoices are visibly marked as having no fiscal validity; incomplete configuration no longer consumes a fiscal number.
* Invoice numbering and database insertion are now one atomic transaction, preventing technical gaps after failed inserts.
* Printable invoice lines now include shipping, fees and any balancing adjustment so their amounts match the stored totals.
* TiendaFactu Conecta status checks now use a random per-installation credential instead of public identifiers alone.
* Responsible declaration expanded to the complete ordered content required by article 15 of Orden HAC/1177/2024.

= 0.5.0 =
* TiendaFactu Conecta can now be activated with one click from the settings page: purchase and store connection happen automatically, no API key to copy and paste.

= 0.4.5 =
* Settings page: added an optional info card and link about the TiendaFactu Conecta managed service (shown only when no API key is configured).

= 0.4.4 =
* The printable invoice stylesheet is now registered with wp_register_style()/wp_enqueue_style() and printed via wp_print_styles(), replacing the previous inline style block.

= 0.4.3 =
* Renamed to "TiendaFactu – Invoices for Verifactu" (the plugin directory does not allow "WooCommerce" in display names).

= 0.4.2 =
* Corrective invoices now carry the real tax breakdown of the refund (previously they could be submitted with a 0% VAT line).
* Concurrency hardening: a unique key per order/type/refund plus atomic claiming prevent duplicate invoices and duplicate API submissions.
* Database insert failures abort invoice creation instead of leaving a phantom invoice note.
* Responses without a UUID are retried instead of leaving the invoice stuck as sent.
* AEAT state transitions are monotonic: a late or replayed event can no longer downgrade an accepted invoice.
* Webhook secret can be sent via the X-TiendaFactu-Secret header (recommended) instead of the URL.
* Hourly rescue of invoices stuck mid-send or never queued.

= 0.4.1 =
* Production mode (real AEAT submission) is now available to everyone — no license required.
* Renamed the plugin to clarify it is an independent integration for Verifactu and WooCommerce.
* Documented the external Verifacti service in the readme.

= 0.4.0 =
* Freemius SDK integration (accounts, licensing and updates for optional paid services).
* Live AEAT submission flow verified end to end against the Verifacti sandbox.
* Fixed AEAT status mapping and status polling (per-invoice lookup by series/number/date).

= 0.3.0 =
* Readiness assistant: deadlines, SII/TicketBAI exemption detection and configuration checklist.
* Audit trail per invoice (SIF traceability) with history view in admin.
* Manual resend of failed invoices and status filters in the invoice list.
* Responsible declaration (Orden HAC/1177/2024) embedded per version.
* Idempotency guard: a refund can never generate duplicate corrective invoices.

= 0.2.0 =
* Verifacti webhooks: AEAT confirmations arrive instantly (hourly polling stays as fallback).

= 0.1.0 =
* Initial release: legally numbered invoices, NIF checkout field, corrective invoices and sandbox submission.
