=== BuildsByLuke Facture Électronique for WooCommerce ===
Contributors: lukeaxiomflow, freemius
Tags: facture, factur-x, facturation, e-invoice, woocommerce
Requires at least: 6.2
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

French e-invoicing (réforme 2026-2027) for WooCommerce: Factur-X, UBL & CII invoices, SIREN checkout capture, credit notes, PA export, e-reporting.

== Description ==

**La réforme de la facturation électronique arrive : 1er septembre 2026 (réception) et 1er septembre 2027 (émission pour toutes les entreprises).** This plugin helps a WooCommerce store get ready — and it answers the objection you have read everywhere ("WooCommerce invoicing plugins are not compliant — use a certified SaaS"): **your Plateforme Agréée (PA) remains the legal transmission layer; this plugin is the automated pipe from your store to it.**

= What the free version does (complete — no locked features) =

* **E-invoice generation per order** in the three legal "socle" formats: **Factur-X** (PDF/A-3 with embedded CII XML, EN 16931 profile, validated against the official XSD at generation time), **UBL 2.1**, and **CII XML** — every Plateforme Agréée must accept these.
* **Automatic generation on order completion** (optional toggle, on by default): every order that reaches "Completed" gets its e-invoice with no manual click — plus one-click generation from any order or the orders list. Auto-generation waits until your seller identity (SIREN) is filled in Settings, because invoice numbering is immutable.
* **B2B checkout capture**: customer type (particulier/professionnel), **SIREN** (Luhn-validated locally, La Poste exception handled) and **TVA intracommunautaire** (FR key cross-checked against the SIREN) — on BOTH the classic checkout and the new block checkout, stored HPOS-safe. All validation runs locally on your server; nothing is sent anywhere.
* **Sequential, gap-free invoice numbering** (atomic — safe under concurrent checkouts), assigned at generation time, separate sequence for credit notes.
* **Credit notes (avoirs)** generated automatically on refunds (type 381, referencing the original invoice) — including amount-only refunds.
* **The four new mandatory invoice mentions** (Sept 2026): buyer SIREN, category of operation, "option TVA sur les débits", delivery address — plus per-rate VAT breakdown, payment terms, late-payment mentions.
* **PA export package**: one ZIP per period (all Factur-X/XML documents + CSV manifest) to upload manually to YOUR Plateforme Agréée — whichever your accountant chose.
* **B2C e-reporting extract**: daily-aggregated bases HT + VAT per rate (ticket-Z model, per the DGFiP spec — no transaction counts), with a **regime-aware transmission calendar** (réel normal / simplifié / franchise).
* **Readiness checklist** with the real deadlines — including what you must do OUTSIDE WordPress (choosing a PA).

= Important, honest scope =

* This plugin is **not a Plateforme Agréée** and does not transmit invoices to the PPF itself. Legal transmission is performed by your PA; the merchant remains responsible for issued invoices.
* **No plugin can, by itself, make your business compliant with the réforme** — this one assists by generating the required document formats and data. What remains yours: choosing and registering with a PA, and your accounting obligations.
* It does not provide tax, legal or accounting advice (ne constitue pas un conseil fiscal, juridique ou comptable). Validate your first invoice with your PA or the FNFE-MPE validator.
* v1 supports EUR stores (French domestic rules). Multi-currency and OSS distance-selling rates are flagged in the checklist, not handled.

**[Pro](https://buildsbyluke.com/plugins/facture-electronique)**: automated transmission — each generated invoice is pushed to your PA's ingest API (generic REST connector, works with any PA exposing one) with a transmission log as your audit trail. Pro is a separate, paid build; its code is not part of this plugin. Sold and licensed through Freemius (see "External services").

== External services ==

The plugin's own features run entirely on your server: invoice generation, checkout validation, numbering, exports and the e-reporting extract make **no external requests at all**.

**Freemius (freemius.com), who sell and license the Pro version**
Freemius is contacted in four situations. Every one of them is something you click. It is never contacted in the background.

1. **If you opt in on the activation screen** (or start a trial / activate a licence). Sent to api.freemius.com: your site URL, your WordPress and PHP versions, and the email address of the account you activate with. Skipping the opt-in is a first-class choice and the plugin is fully functional without it.
2. **If you open the "Upgrade" page** under the plugin's menu. Your own server (not your browser) asks api.freemius.com for current plan prices, sending your site URL. The page itself loads no third-party scripts — everything it renders is served from this plugin's own folder. The payment SDK's bundled pricing script used to inject Google Analytics and a remote checkout script into wp-admin on that page; this build removes both, along with the SDK's remaining remote references (all modifications are listed under "Source code" below).
3. **If you open the "Contact Us" page**, which is Freemius's hosted support form (wp.freemius.com). The link carries your site URL and your WordPress login URL so the form knows which site you are writing about.
4. **If you click a plan to buy**, you go to Freemius's hosted checkout (checkout.freemius.com). It receives your site URL, site name, WordPress and PHP versions, and your WordPress administrator email address (pre-filled, sent whether or not you complete the purchase). Freemius is the merchant of record. Their checkout page loads its own third-party scripts (at the time of writing: Stripe, PayPal, Google Tag Manager, and Freemius's own assets); we do not control that list. If you never click a plan, none of it loads.

Terms: https://freemius.com/terms/ — Privacy: https://freemius.com/privacy/

Installing, activating, skipping the opt-in, using every screen, deactivating (the SDK's deactivation-feedback dialog is switched off in this build, so deactivation is one click and sends nothing), WordPress's update cycle and all scheduled tasks complete without contacting Freemius at all. Free updates come from WordPress.org like any other plugin.

== Source code ==

This plugin's own PHP is unminified and readable in the plugin folder. It bundles the following third-party libraries (all GPL-compatible; licence files ship in each folder):

* **atgp/factur-x** v3.4 (MIT) — Factur-X PDF/A-3 assembly + official XSD validation. One local modification, marked "Facture Electronique:" in src/Writer.php: the library's XMP extension-schema data file ships renamed from .xmp to .xml (identical content — XMP is XML). https://github.com/atgp/factur-x
* **setasign/FPDI** v2 (MIT) — PDF import for the PDF/A-3 container. https://github.com/Setasign/FPDI
* **smalot/pdfparser** v2 (LGPL-3.0) — PDF parsing used by the Factur-X writer. https://github.com/smalot/pdfparser
* **FPDF** 1.8.x (permissive, see vendor/fpdf/license.txt) — base class required by FPDI. http://www.fpdf.org/
* **tFPDF** 1.24 (LGPL) — UTF-8 PDF rendering with embedded fonts. Two local modifications, each marked "Facture Electronique:" at the patch site: the PHP 5.4-era magic-quotes call in tFPDF.php is guarded so the class runs on PHP 8, and font/unifont/ttfonts.php carries the #[AllowDynamicProperties] attribute so PHP 8.2+ does not emit dynamic-property deprecations while font metrics are generated. http://www.fpdf.org/en/script/script92.php
* **DejaVu fonts** (Bitstream Vera licence + public-domain additions, see vendor/tfpdf/font/unifont/LICENSE-DejaVu.txt) — embedded so the PDFs are PDF/A-viable.

The one exception to "unminified" is the third-party payment SDK in `vendor/freemius/`, which ships pre-minified. Those files are the Freemius WordPress SDK, published under the GPL, and their unminified source and build tooling are public:

* Freemius WordPress SDK: https://github.com/Freemius/wordpress-sdk
* The pricing screen bundled at `vendor/freemius/assets/js/pricing/freemius-pricing.js`: https://github.com/Freemius/pricing-page

The minified files under `vendor/freemius/` are: `assets/js/pricing/freemius-pricing.js`, `assets/js/postmessage.js`, `assets/js/nojquery.ba-postmessage.js`, `assets/js/jquery.form.js`, and thirteen stylesheets under `assets/css/`.

This plugin ships four deliberate modifications to that SDK, all in `assets/js/pricing/freemius-pricing.js`, all removing remote references from wp-admin. Three are marked with a "Facture Electronique:" comment at the patch site; the loader-image swap (3.) is a one-string replacement:

1. The `appendScripts()` method is emptied. Upstream it injects `https://www.google-analytics.com/analytics.js` and `https://checkout.freemius.com/checkout.js` into wp-admin when the pricing screen renders.
2. The Google Analytics pageview tracker is stubbed out. Upstream it reports pricing-page views to Freemius's Analytics property whenever a GA object is already present in wp-admin, stamping them with the Freemius user id.
3. The remote loading spinner (`img.freemius.com/blue-loader.gif`) is replaced with an inline data-URI equivalent.
4. Testimonial photos (Gravatar/remote) are forced to the bundled placeholder image, so the pricing page renders without any remote image requests.

== Installation ==

1. Install and activate (WooCommerce required).
2. Fill **Facture Électronique → Settings**: SIREN, TVA, legal mentions, VAT regime.
3. Invoices now generate automatically when orders are completed (toggle in Settings) — or open any order and click **Generate e-invoice**. Download the Factur-X and validate it with your PA.
4. Follow the readiness checklist for the Sept 2026 / Sept 2027 deadlines.

== Frequently Asked Questions ==

= Est-ce que ce plugin me rend conforme à la réforme 2026 ? =

Aucun plugin ne peut, à lui seul, garantir la conformité. Celui-ci vous y aide : il génère vos factures aux formats légaux (Factur-X/UBL/CII), capture le SIREN de vos clients professionnels, numérote séquentiellement, et prépare vos exports e-reporting. La transmission légale reste assurée par votre Plateforme Agréée : choisissez-en une avec votre expert-comptable (échéance : 1er septembre 2026 pour la réception).

= Do I need this if I already use a PDF invoice plugin? =

PDF invoice plugins produce documents for humans. The 2026-2027 reform requires STRUCTURED e-invoices (Factur-X/UBL/CII) with the buyer's SIREN, routed through a Plateforme Agréée — plus e-reporting of B2C sales. That is what this plugin helps with.

= What happens to my invoices if I uninstall? =

Nothing — generated documents stay in their folder under wp-content/uploads/ (invoices are legal records you must retain 10 years). Only settings and internal tables are removed.

= Is the Factur-X output validated? =

The embedded CII XML is validated against the official Factur-X XSD at generation time. Validate your first document with your PA's ingest test or the FNFE-MPE validator; the plain UBL/CII XML outputs are also legally valid on every PA.

= Does the free version phone home? =

No. The plugin's own features make no external requests. The Freemius SDK (which powers the optional paid upgrade) only talks to Freemius in the four click-through situations listed under "External services" — never in the background.

== Screenshots ==

1. Documents & Compliance: the readiness checklist for the 2026-2027 deadlines, the B2C e-reporting calendar for your VAT regime, the PA export package, and every document generated so far — each one downloadable as Factur-X, CII, UBL or PDF.
2. Any order shows the customer type, SIREN and TVA captured at checkout, alongside the documents generated for it — here an invoice and the credit note (avoir) raised automatically from a partial refund.
3. B2B capture on the block checkout (the classic checkout is supported too): customer type, SIREN and TVA intracommunautaire. All validation runs locally on your own server.
4. Settings: the seller identity that appears on every e-invoice, invoice and credit-note numbering, payment terms, category of operation and VAT regime.

== Changelog ==

= 1.1.2 =
* Maintenance : migration du service de licences et de mises à jour de la version Pro vers un nouveau compte. Aucun changement fonctionnel.

= 1.1.1 =
* Packaging: the Factur-X XMP extension-schema data file now ships with an .xml extension (identical content).
* Compatibility: the plugin no longer defines the global FPDF_FONTPATH constant — the bundled PDF libraries resolve their font folders per instance, so the plugin cannot collide with other plugins that bundle FPDF.

= 1.1.0 =
* Initial release: Factur-X/UBL/CII generation (EN 16931), automatic generation on order completion, dual-checkout SIREN/TVA capture, atomic numbering, credit notes, PA export package, e-reporting extract + calendar, readiness checklist.

== Upgrade Notice ==

= 1.1.2 =
Maintenance release; no functional changes.

= 1.1.1 =
Packaging and compatibility refinements; no functional changes.

= 1.1.0 =
First release.
