=== KSeF E-Invoicing for WooCommerce ===
Contributors: catcodestudio
Tags: ksef, e-invoice, faktura, woocommerce, poland
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Structured FA(3) e-invoices for Poland's KSeF, sent from WooCommerce orders straight to the KSeF API 2.0 with your KSeF token. No SaaS subscription.

== Description ==

Since 2026 Polish VAT payers issue invoices to businesses through the National e-Invoice System (Krajowy System e-Faktur, KSeF). KSeF E-Invoicing turns a WooCommerce order into a structured invoice in the official FA(3) format and sends it directly to KSeF — no accounting SaaS in the middle and no monthly fee.

**Free, without a time limit**

* FA(3) invoice (schema 1-0E) built from the order: seller, buyer with NIP, lines, shipping, fees, VAT per rate, payment.
* Automatic sending when the order becomes "Completed" or "Processing", through the KSeF API 2.0 (online session, AES-256 encryption, KSeF token authentication).
* KSeF number and the official UPO (confirmation of receipt) saved to the order; XML and UPO download.
* NIP field on the classic and the block checkout with checksum validation; NIP also editable in the order admin; works with NIP fields of other plugins.
* Queue with automatic retries, duplicate detection (a lost answer never creates a second invoice), readable KSeF rejection reasons, "Regenerate and send" after a fix.
* TEST, DEMO and PRODUCTION environments, separate invoice counters per environment.
* Invoice numbering you control: FV/{YYYY}/{MM}/{N}, monthly / yearly / continuous.
* VAT from WooCommerce taxes, from a fixed rate included in prices, or VAT-exempt sellers (zw with legal basis).

**Pro**

* Correction invoices (KOR) created from WooCommerce refunds — by items or by amount — referencing the corrected invoice's KSeF number.
* Buyers from other EU countries (VAT UE, 0% WDT) and outside the EU (export).
* Consumer (B2C) invoices in KSeF, when you choose to send them.
* Invoices in EUR, USD and other currencies with the NBP average rate and VAT in PLN.
* For customers: the KSeF number and the verification QR code (KOD I) in an e-mail, on the order page and on a printable invoice.
* Bulk "Issue KSeF invoice" for past orders.
* CSV register for your accountant.
* E-mail alerts on rejected invoices and delivery problems.

A 7-day Pro trial starts only when you click "Try Pro free for 7 days".

**Getting a KSeF token**

Log in to the KSeF taxpayer application (Aplikacja Podatnika KSeF 2.0) of the chosen environment, open Tokens, generate a token with the "Invoice write" and "Invoice read" permissions and paste it into WooCommerce → KSeF → Settings.

== Installation ==

1. Upload the plugin and activate it (WooCommerce must be active).
2. WooCommerce → KSeF → Settings: switch invoicing on, choose the environment, fill in the seller NIP, name and address, paste the KSeF token and click "Check the connection to KSeF".
3. Start on the TEST environment with fictitious data, then switch to PRODUCTION.

== Frequently Asked Questions ==

= Do consumer orders go to KSeF? =

KSeF is mandatory for invoices to businesses. Invoices for consumers may be issued outside KSeF, so the free version sends only orders with a buyer NIP. Pro can send consumer invoices too.

= What happens when KSeF is down? =

Invoices stay in the queue and are retried automatically. Nothing is lost and no invoice is sent twice.

= I also issue invoices in another program on the same NIP =

Give the shop its own number format (for example SKLEP/{YYYY}/{MM}/{N}). KSeF refuses a second invoice with the same number; the plugin recognises its own earlier file by its SHA-256 (from the UPO) and never takes over the KSeF number of a document issued elsewhere — such an invoice is marked as rejected with an explanation.

= Where is the KSeF token stored? =

Encrypted in the database with keys derived from your site's secret salts. You can also define it in wp-config.php as CCKSEF_TOKEN.

= What happens to my data when I delete the plugin? =

The KSeF token and cached access tokens are deleted. The invoice register and counters stay, so a reinstall continues the numbering. Define CCKSEF_DELETE_DATA as true in wp-config.php before deleting to remove everything.

== External services ==

This plugin connects to:

* **KSeF API 2.0 of the Polish Ministry of Finance** (api-test.ksef.mf.gov.pl, api-demo.ksef.mf.gov.pl, api.ksef.mf.gov.pl) to authenticate with your KSeF token, send invoices and download their status and UPO. The invoice data (seller, buyer, items, amounts) is sent encrypted when an invoice is issued. Terms and privacy: https://ksef.podatki.gov.pl/
* **KSeF verification pages** (qr-test/qr-demo/qr.ksef.mf.gov.pl) — only as the target of the QR code link; nothing is sent from the shop.
* **NBP exchange rates API** (api.nbp.pl), Pro, only for invoices in a foreign currency: the currency code and a date range are requested. https://api.nbp.pl/
* **CatCode licence server** (catcode.com.ua), only when you activate a licence or start a trial: the licence key or e-mail, the site address and the plugin name are sent. https://catcode.com.ua/

== Changelog ==

= 1.0.1 =
* The Pro version activates next to an active free copy from WordPress.org without PHP warnings or loading its code from the free copy's folder: the free copy steps aside, the settings and the invoice register stay.
* Deleting Pro while the free copy is installed keeps the shared settings, KSeF token and register and removes only the licence.

= 1.0.0 =
* First release.
