=== Valifakt E-Rechnung for WooCommerce ===
Contributors: valifakt
Tags: e-rechnung, xrechnung, zugferd, invoice, woocommerce
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 0.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Create XRechnung and ZUGFeRD e-invoices from WooCommerce orders, validated against the official KoSIT rules (EN 16931).

== Description ==

Since 1 January 2025, German businesses must be able to **receive** e-invoices from other businesses (B2B). Issuing them becomes mandatory in phases: from 2027 for businesses with more than €800,000 annual turnover, and from 2028 for all others. A PDF created by a normal invoice plugin is not an e-invoice.

This plugin turns a WooCommerce order into a real e-invoice:

* **XRechnung 3.0** in UBL or CII syntax, or **ZUGFeRD / Factur-X (EN 16931 profile)**: a PDF with the XML embedded
* **Validated with the official rules**: the KoSIT validator with the XRechnung schematron and the CEN EN 16931 rules. You see every error in plain language before you send anything.
* **Download buttons** in the order screen (XML, and PDF for ZUGFeRD)
* **Optional e-mail attachment** to the "Completed order" and "Invoice" customer e-mails
* **Leitweg-ID** field per order for public-sector customers (B2G, BT-10)
* Customer VAT ID from the order (common VAT plugins are detected, or set your own meta key)
* Reverse-charge, intra-community and export cases, and the small-business rule (§ 19 UStG)
* Optional automatic creation when an order is completed; you can limit it to business customers
* Compatible with WooCommerce High-Performance Order Storage (HPOS)

The e-invoice is created by the Valifakt service (valifakt.com). The free tier works without an API key, up to its monthly free quota. For more invoices, add a Valifakt Pro key in the settings.

= External service =

This plugin relies on the third-party service **Valifakt** (https://valifakt.com), operated by the plugin author, to create and validate e-invoices. No data is sent before you tick the consent box in WooCommerce → E-Rechnung. After that, data is sent only when an e-invoice is created or validated: when you click a button in the order screen, or automatically on order completion if you enabled that.

* **What is sent:** your seller details from the settings, and the invoice data of the order: number, dates, currency, the customer's billing name, company, address, e-mail, phone and VAT ID, the Leitweg-ID, and the order items, shipping and fees with their prices and tax rates. For "Validate again", the stored XML is sent. Your API key is sent in a header if you entered one.
* **Where:** `https://valifakt.com/api/generate`, `https://valifakt.com/api/jobs/…` (download of the result) and `https://valifakt.com/api/validate`. The servers are in Germany (EU).
* **Retention:** the service deletes uploaded data and created files automatically after 60 minutes. The created files are stored in your own WordPress installation (`wp-content/uploads/valifakt-e-rechnung/`, protected from direct web access on Apache; see the FAQ for nginx).
* Terms of service: https://valifakt.com/de/agb.html (English: https://valifakt.com/en/terms.html)
* Privacy policy: https://valifakt.com/de/datenschutz.html (English: https://valifakt.com/en/privacy.html)

The plugin does not track usage and loads no remote scripts, fonts or images.

= Not included =

The plugin creates and validates the e-invoice file. It does not send invoices to public portals (ZRE, OZG-RE, Peppol). It is not a bookkeeping or archiving system: keep invoices for the statutory period (in Germany, 8 years under § 147 AO and the GoBD).

== Installation ==

1. Install and activate WooCommerce, then this plugin.
2. Go to **WooCommerce → E-Rechnung** and enter your seller details: company name, address, VAT ID (USt-IdNr.) or tax number, the invoice e-mail address, and your IBAN.
3. Read the service note and tick **"I agree that order data … is sent to valifakt.com"**.
4. Open an order and click **Create e-invoice** in the "E-Rechnung" box.

== Frequently Asked Questions ==

= Do I need a Valifakt account or API key? =

No. Without a key, the free tier applies, up to its monthly quota of conversions per IP address of your shop server. Validation ("Validate again") does not use the quota. With a Pro or Office key you get more conversions; see https://valifakt.com/de/pricing.html.

= Which format should I choose? =

Public-sector customers (B2G) usually require **XRechnung** and a Leitweg-ID. For business customers, **ZUGFeRD** is popular because it is also a readable PDF. Both are valid e-invoices under § 14 UStG.

= Where does the Leitweg-ID go? =

Enter it in the "E-Rechnung" box of the order. It is written to the buyer reference (BT-10). Without one, the order number is used.

= My invoice is "not valid". What now? =

The box lists every problem in plain language, for example a missing seller address or e-mail. Fix it in the settings or the order, then click **Create again**. Only valid files can be downloaded or attached.

= Which invoice number is used? =

The invoice number is the optional prefix from the settings plus the WooCommerce order number. If you already use another invoice-number plugin, make sure the numbers don't clash.

= Are the files protected on nginx? =

On Apache, the plugin writes a `.htaccess` file that blocks direct access, and the file names are random. On nginx, add a rule such as `location ^~ /wp-content/uploads/valifakt-e-rechnung/ { deny all; }`.

= What happens on uninstall? =

The settings are deleted. Created e-invoice files stay in `wp-content/uploads/valifakt-e-rechnung/`, because you may have to keep them by law.

== Screenshots ==

1. Settings: seller details, payment details, format and the consent to use the valifakt.com service.
2. Order screen: e-invoice created and validated, with XML and PDF download buttons.
3. Order screen: plain-language errors when required data is missing.

== Changelog ==

= 0.1.0 =
* First release: XRechnung UBL/CII and ZUGFeRD from orders, KoSIT validation, downloads, e-mail attachment, Leitweg-ID, de_DE translation.

== Upgrade Notice ==

= 0.1.0 =
First release.
