=== OuiFacture - Facture électronique Factur-X for WooCommerce ===
Contributors: factureconforme
Tags: facture, factur-x, woocommerce, invoice, e-invoicing
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Automatic Factur-X (EN 16931) electronic invoices for every WooCommerce order, ready for the French e-invoicing mandate.

== Description ==

**OuiFacture** turns your WooCommerce store into a compliant French electronic invoicing machine. Every order automatically gets a legally compliant PDF invoice with an embedded **Factur-X** XML file (PDF/A-3, profile **EN 16931**), the format required by the French e-invoicing reform (réforme de la facturation électronique, échéances 2026-2027).

**Automatic. On every order.**

= Features =

* **Automatic generation** of a Factur-X invoice when the order reaches the status you choose (processing, the default, or completed), no clicks needed. An order that jumps straight to completed is invoiced then; each order is invoiced exactly once.
* **PDF/A-3 with embedded EN 16931 CII XML**, validated against the official Factur-X XSD schemas at generation time.
* **French legal invoice layout**: seller block (raison sociale, forme juridique, capital, RCS, SIRET, TVA), buyer block, line items HT, VAT breakdown by rate, totals HT/TVA/TTC, payment terms, and the mandatory legal mentions (catégorie d'opération, pénalités de retard, indemnité forfaitaire de 40 €, escompte, option TVA sur les débits si activée).
* **Gap-free sequential numbering** (prefix + year + counter, optional yearly reset), race-safe, numbers are immutable once issued, regeneration never changes the number.
* **B2B checkout fields**: optional SIRET and intra-community VAT number on the classic checkout, validated (Luhn / FR VAT key) and shown in the admin order screen and in the XML.
* **Customer access**: download link in My Account → Orders, on the order-received page, and optional PDF attachment to the "order completed" email.
* **Admin control**: metabox on every order with Generate / Regenerate / Download.
* **Secure storage**: invoices live in a protected uploads folder with unguessable file names and are only served through authenticated endpoints.
* **HPOS compatible** (High-Performance Order Storage).
* **No external calls, no tracking**: everything is generated locally on your server.

= Compliance notes =

* Invoices embed the CII XML at the **EN 16931** profile of Factur-X 1.x, validated against the official XSDs before the PDF is written.
* Invoice numbers are sequential and gap-free; a number is only consumed once the invoice files have been written successfully.
* On uninstall, the plugin removes its settings but **keeps generated invoices**: French law requires you to retain them for 10 years.

= Limitations of this version =

* The SIRET/VAT checkout fields are available on both the classic (shortcode) checkout and the block-based checkout (WooCommerce 8.9 or later for the block checkout fields; earlier versions still get automatic invoices, just without the two B2B fields on the block checkout).
* Refunds do not produce credit notes (avoirs); the original invoice is kept unchanged, as required (an issued invoice is immutable).
* One VAT category per order line (standard/zero). Margin schemes, VAT exemption reasons and non-EUR specifics beyond currency code pass-through are not handled.
* PDF/A-3 conversion covers embedded file relationships, XMP metadata and output intents as produced by the bundled Factur-X writer; full ISO 19005-3 conformance of exotic source PDFs is not re-verified at runtime.
* The buyer's electronic routing identifier (BT-49, French rule BR-FR-12) is only included when the buyer supplied a SIRET at checkout (the B2B fields). Orders from a private buyer with no SIRET do not carry it: there is no such identifier to supply truthfully for an individual.

== Installation ==

1. Upload the plugin to `/wp-content/plugins/` or install it through the WordPress plugin screen.
2. Activate it (WooCommerce must be active).
3. Go to **WooCommerce → OuiFacture** and fill in your seller identity (raison sociale, SIRET, n° TVA, adresse…). These appear on every invoice.
4. Choose the trigger status (default: processing). Done, invoices now generate automatically.

== Frequently Asked Questions ==

= Is this the format required by the French reform? =

The plugin produces Factur-X PDF/A-3 invoices with an embedded EN 16931 CII XML, the mixed format retained by the French reform. OuiFacture is not a Plateforme Agréée (PA), the term now used for what used to be called a PDP: businesses exchange invoices through those state-registered platforms. The separate OuiFacture Premium add-on connects to your own platform account to transmit documents automatically (a Sellsy connector, a Chorus Pro connector for public-sector clients, and a tracked manual workflow for any other platform) and prepares e-reporting aggregates for your platform to file with the tax administration.

= Where are my invoices stored? =

In `wp-content/uploads/ouifacture/`, protected by an `.htaccess` deny rule and random file names. Downloads always go through authenticated endpoints. Note: the `.htaccess` rule only applies to Apache/LiteSpeed servers. On nginx, add a `location` deny rule for that folder to your server configuration (file names remain unguessable either way).

= Can I regenerate an invoice? =

Yes, from the order screen. The invoice number and date never change on regeneration (a French invoice number is immutable); only the document content is rebuilt.

== Screenshots ==

1. Settings: seller identity, legal mentions, numbering and generation trigger.
2. Order screen: OuiFacture metabox with the generated invoice and download button.
3. A generated Factur-X invoice (French legal layout, PDF/A-3 with embedded EN 16931 XML).
4. My Account → Orders: customer invoice download link.
5. Classic checkout: optional SIRET and intra-community VAT (B2B) fields.

== Changelog ==

= 1.0.6 =
* The SIRET and intra-community VAT fields now also appear on the block-based checkout (WooCommerce 8.9 or later), registered through WooCommerce's own additional-checkout-fields API, with the same server-side validation (Luhn key for the SIRET, French VAT key) and the same order meta, admin display and Factur-X XML pickup as the classic checkout. Older WooCommerce versions keep the classic fields, unchanged.

= 1.0.5 =
* Punctuation and wording cleanup: 20 strings (including the plugin's own display name and three strings on the customer-facing PDF invoice) no longer use an em or en dash. No functional change.
* Readme updated to describe the platform story truthfully: OuiFacture is not a Plateforme Agréée (PA, formerly called PDP); transmission and e-reporting filing run through the merchant's own platform account, via the separate OuiFacture Premium add-on.

= 1.0.4 =
* Fixed: invoices now pass the French BR-FR-05 rule. The three existing legal-mention notes (late payment penalty, recovery indemnity, discount) now carry the required SubjectCode (PMD, PMT, AAB); two further mandatory notes were added, operation category (REG, new setting, default "delivery of goods") and, only when the option is used, VAT on debits (TXD, new optional setting).
* Fixed: the seller's and buyer's SIRET now also appears as an electronic routing identifier (BT-34/BT-49, French rules BR-FR-13/BR-FR-12), in addition to the existing legal-organization identifier.
* Fixed: the seller's and buyer's legal-organization identifier (BT-30/BT-46) now correctly carries the 9-digit SIREN under scheme code 0002. It previously carried the full 14-digit SIRET under that scheme, which is the SIREN scheme; the SIRET is now correctly emitted separately (scheme 0009).
* Verified against both the core EN 16931 Schematron and the French BR-FR-* rules together (confactura.fr validator), not the XSD alone.

= 1.0.3 =
* Plugin URI added to the header, pointing to https://ouifacture.fr/.
* Invoices no longer plug a totals rounding gap into the RoundingAmount field (BT-114), which can fail the EN 16931 total-identity rules (BR-CO-15, BR-CO-16). Any gap between the sum of the lines plus VAT and the order total now rides its own visible, zero-rated line ("Ajustement d'arrondi").
* New optional IBAN setting (Seller identity section). When set, invoices paid by bank transfer now carry the payee account identifier (BT-84) the EN 16931 rules require for that payment means. Leave it empty and nothing changes.

= 1.0.2 =
* Translations are now served through translate.wordpress.org: the bundled .po/.mo files are no longer packaged and the obsolete `load_plugin_textdomain()` call has been removed (not needed since WordPress 4.6).
* Housekeeping following the plugin review; no change to invoice generation, numbering or output.

= 1.0.1 =
* Plugin display name now ends in "for WooCommerce" (WordPress.org trademark guidelines).
* The default generation trigger is now **processing** (was completed): invoices are issued as soon as payment is received. Orders that skip straight to completed are still invoiced there, exactly once per order.
* French translation updated.

= 1.0.0 =
* Initial release: automatic Factur-X (EN 16931) generation, gap-free numbering, B2B checkout fields, customer downloads, email attachment, HPOS support, French translation.

== Upgrade Notice ==

= 1.0.6 =
The SIRET and VAT checkout fields now also work on the block-based checkout (WooCommerce 8.9 or later). No settings change.

= 1.0.5 =
Punctuation and wording cleanup only (dash-free strings, readme accuracy on platforms). No functional change.

= 1.0.4 =
Fixes French compliance rules (BR-FR-05, BR-FR-12/13): legal-mention notes, SIREN vs SIRET, electronic routing identifiers. New "Operation category" setting, default "delivery of goods": check WooCommerce → OuiFacture if you sell services or a mix.

= 1.0.3 =
Rounding fix for invoice totals and an optional IBAN setting for bank transfer payments. No settings are changed unless you fill in the new IBAN field.

= 1.0.2 =
Translations now come from translate.wordpress.org. No functional change.

= 1.0.1 =
New default: invoices generate at "processing". Existing saved settings are not changed.

= 1.0.0 =
Initial release.
