=== FatturaPA SdI for WooCommerce ===
Contributors: catcode
Tags: fattura elettronica, fatturapa, sdi, italy, invoice
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
WC requires at least: 8.0
WC tested up to: 11.1
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Italian electronic invoices (FatturaPA, format FPR12) built straight from WooCommerce orders — no paid invoicing service in between.

== Description ==

FatturaPA SdI turns WooCommerce orders into electronic invoices in the official Italian format for private-sector recipients (FatturaPA 1.2.3, "fattura ordinaria" FPR12, Specifiche tecniche 1.9.1 of the Agenzia delle Entrate) and helps you get them to the Sistema di Interscambio (SdI).

Every file is checked against the official XSD schema before it gets a number, and against the SdI controls that can be verified offline (Natura vs VAT rate, amounts and rounding, buyer identifier, recipient code, PEC, the generic Natura codes refused since 2021).

**Free version**

* An invoice (TD01) for companies with a Partita IVA and for customers who tick "I need an invoice" — or for every order, as you choose.
* Codice fiscale, Partita IVA, codice destinatario (SDI) and PEC at checkout — classic and block checkout — with check-digit validation of the codice fiscale (omocodia included) and of the Partita IVA.
* CodiceDestinatario / PECDestinatario filled in by the rules of the SdI (7-character code, 0000000 + PEC, 0000000 for the buyer's reserved area).
* VAT from the WooCommerce taxes of each order, several rates on one invoice, lines without VAT with the Natura code of your choice (N1–N7, only the codes still accepted) and its legal reference.
* Forfettario (RF19) and minimi (RF02) sellers: every line without VAT with Natura N2.2 and the legal reference.
* Stamp duty: "BolloVirtuale" when the lines without VAT (N2.1, N2.2, N3.5, N3.6, N4) exceed 77,47 EUR.
* Company or natural-person seller, REA data, all RegimeFiscale codes, payment data (ModalitaPagamento, IBAN), your own number series with a yearly counter.
* File names as the SdI requires (IT + codice fiscale of the transmitter + progressive); every resend gets a new name.
* An invoice register, the XML under its SdI name, a box on every order, "Rebuild" with the same number after a rejection.
* SdI receipts (RC delivered, NS rejected with the error list, MC not delivered) recorded from their XML files — e.g. downloaded from "Fatture e corrispettivi".

**Pro (7-day free trial, then a licence)**

* Sending to the SdI by PEC from your own certified mailbox (SMTP) — the channel open to every business, no accreditation — with the receipts read automatically from the mailbox (IMAP) and the SdI address remembered from its answers.
* Or an intermediary webhook: the XML is POSTed to an address you choose; receipts come back to a REST endpoint with a token.
* Credit notes (TD04) from WooCommerce refunds, by item or by amount, linked to the invoice (DatiFattureCollegate).
* Customers outside Italy: code XXXXXXX, foreign VAT number or customer reference, CAP 00000, Natura codes for goods to EU businesses, exports and services.
* The stamp duty (2 EUR) added at checkout for customers of flat-rate sellers.
* A courtesy copy of the invoice for the customer in My Account.
* Bulk "Create FatturaPA" for past orders, ZIP of the XML files + CSV register for your accountant, e-mail alerts (rejections, undelivered invoices, transmission problems, receipts that do not arrive).

**Good to know**

* The SdI web service and SFTP channels need an accreditation of their own; this plugin does not use them. Sending by PEC or through your intermediary is the way for a single shop.
* The plugin creates invoices in EUR only; an order in another currency is skipped with a message.
* OSS sales (VAT of another EU country) are not issued by this version.
* The content of an invoice is the seller's responsibility: confirm the Natura codes, the legal references and when you issue invoices with your accountant.

== Installation ==

1. Install and activate the plugin (WooCommerce must be active).
2. WooCommerce → FatturaPA → Settings: fill in the seller data (Partita IVA, name, tax regime, address with CAP and province), the numbering and the VAT choices.
3. Choose how invoices reach the SdI: manual upload (free), or by PEC / intermediary (Pro). For PEC enter your PEC address, the SMTP and IMAP servers of your provider and the password, then "Test the PEC connection".
4. Switch "Create FatturaPA invoices" on.

== Frequently Asked Questions ==

= Is there a test mode? =
The SdI has no test environment for PEC senders. Define `CCFP_SDI_MOCK` in wp-config.php as `rc` (delivered), `ns` (rejected), `mc` (not delivered), `silent`, `down` or `auth`: nothing leaves the site and the answers are simulated through the real receipt parser.

= Which PEC address of the SdI is used? =
The first invoice goes to sdi01@pec.fatturapa.it, as the specification says. The SdI answers from the address you must use from then on; the plugin reads it from the receipts and uses it for the next invoices.

= The SdI rejected an invoice. What now? =
The error list of the receipt is shown in the register and in the order notes. A rejected invoice counts as not issued: correct the order and click "Rebuild and send" — same number and date, new file name.

= Where are the receipts kept? =
In the site database (not in a web folder), so no web server can hand them out by URL: they are downloaded only in the admin. Mailbox passwords and tokens are stored encrypted with your site's secret keys.

== Privacy ==

The invoice data (seller, customer, codice fiscale / Partita IVA, address, lines, amounts) is sent to the SdI through the channel you choose — the purpose of electronic invoicing. Licence checks contact catcode.com.ua with the licence key and the site address only.

== Changelog ==

= 1.0.0 =
* First release.
