KSeF 2.0 Integration
How FCHub Fakturownia submits invoices to Poland's national e-invoicing system (Krajowy System e-Faktur) and tracks submission status.
KSeF (Krajowy System e-Faktur) is Poland's national electronic invoicing system operated by the Ministry of Finance. FCHub Fakturownia integrates with KSeF through Fakturownia's built-in KSeF support, allowing invoices to be submitted directly from your FluentCart store.
What Is KSeF?
KSeF is Poland's centralized platform for issuing, receiving, and storing structured electronic invoices. It's part of a broader push across the EU to standardize e-invoicing and improve tax compliance.
Key points about KSeF:
- Structured format -- invoices are submitted in a standardized XML schema defined by the Ministry of Finance
- Unique KSeF ID -- every submitted invoice receives a unique identification number from the system
- Verification -- both the seller and buyer can verify invoices through the KSeF platform
- Legal compliance -- KSeF invoices are considered the official tax document
KSeF Timeline
KSeF has been available for voluntary use and is being phased in as mandatory for Polish businesses. Check the current requirements at the Ministry of Finance KSeF portal for the latest timeline and obligations.
How It Works
FCHub Fakturownia does not communicate with KSeF directly. Instead, it leverages Fakturownia's own KSeF integration. When you enable KSeF auto-send in the plugin settings, the flow is:
Invoice Created with KSeF Flag
When an order is paid and the invoice is created, the plugin sends the gov_save_and_send: true parameter to Fakturownia's API. This tells Fakturownia to create the invoice and immediately submit it to KSeF.
Fakturownia Submits to KSeF
Fakturownia handles the XML conversion and submission to KSeF. This happens asynchronously on Fakturownia's servers -- the initial API response returns before KSeF confirms receipt.
Status Polling via Cron
Since KSeF processing is asynchronous, the plugin schedules a WordPress cron event (fchub_fakturownia_check_ksef_status) to check back after 60 seconds. The cron job fetches the invoice from Fakturownia's API and reads the gov_status field.
Status Updates
The cron job updates the order metadata with the latest KSeF status, KSeF ID, and verification link. If the status is still processing, it schedules another check in 2 minutes.
Completion
Once KSeF returns a final status (ok or send_error), the polling stops and a log entry is added to the order.
KSeF Status Values
The plugin tracks the following KSeF statuses, as reported by Fakturownia:
| Status | Meaning | What Happens |
|---|---|---|
ok | Invoice accepted by KSeF | KSeF ID and verification link stored. Success log added. Polling stops. |
processing | Submitted, waiting for KSeF confirmation | Another status check is scheduled in 2 minutes. |
send_error | KSeF rejected the invoice | Error messages from KSeF are logged on the order. Polling stops. |
server_error | KSeF service error (transient) | Retried automatically like processing. Displayed as "Server Error" in admin. |
not_applicable | KSeF submission not applicable | Displayed as "N/A" in admin. |
not_connected | Fakturownia account not connected to KSeF | Displayed as "Not Connected" in admin. |
The Cron Job
The plugin uses a single-event WordPress cron (wp_schedule_single_event) for KSeF status polling. Here's the technical detail:
Event Name
fchub_fakturownia_check_ksef_statusParameters
The cron event receives two arguments:
$orderId-- the FluentCart order ID$fakturowniaInvoiceId-- the Fakturownia invoice ID to check
Timing
- First check: 60 seconds after invoice creation
- Subsequent checks: every 120 seconds (2 minutes) while the status is
processing - Stops when: the status changes to a terminal value (
ok,send_error). Bothprocessingandserver_errortrigger retries. - Retry limit: 30 attempts (~1 hour). After that, a warning is logged and polling stops.
What It Does
Each cron execution:
- Fetches the invoice from Fakturownia's API
- Updates
_fakturownia_ksef_statuson the order - Stores
_fakturownia_ksef_idif available (the official KSeF number) - Stores
_fakturownia_ksef_linkif available (the verification URL) - If status is
ok-- logs a success message with the KSeF number - If status is
send_error-- logs the error messages from KSeF - If status is
processing-- schedules another check in 2 minutes
Sandbox / Demo Environments
Fakturownia sandbox environments return KSeF statuses with a demo_ prefix (e.g. demo_ok, demo_processing). The plugin strips this prefix automatically, so status tracking works identically in sandbox and production.
WordPress Cron Dependency
KSeF status polling depends on WordPress cron (wp-cron.php). If your site has low traffic or cron is disabled, status updates may be delayed. For reliable cron execution, consider setting up a system-level cron job that hits wp-cron.php regularly:
*/2 * * * * curl -s https://yoursite.com/wp-cron.php > /dev/null 2>&1Correction Invoices and KSeF
When a refund triggers a correction invoice, the correction is also submitted to KSeF if auto-send is enabled.
Corrections use the same single-step gov_save_and_send flag as regular invoices. KSeF data from the create response (gov_status, gov_id, gov_link) is stored immediately under the _fakturownia_correction_ksef_* meta keys. A separate cron poll is also scheduled to catch async KSeF processing.
Correction positions include the required kind: 'correction' and correction_before_attributes fields per the Fakturownia API spec.
Order Metadata
The following KSeF-related metadata is stored on FluentCart orders:
| Meta Key | Description | Example Value |
|---|---|---|
_fakturownia_ksef_status | Current KSeF status | ok, processing, send_error |
_fakturownia_ksef_id | KSeF invoice number | 1234567890-20250115-ABC123DEF456 |
_fakturownia_ksef_link | KSeF verification URL | https://ksef.mf.gov.pl/... |
_fakturownia_correction_ksef_status | Correction invoice KSeF status | ok, processing |
_fakturownia_correction_ksef_id | Correction KSeF number | 1234567890-20250115-XYZ789 |
_fakturownia_correction_ksef_link | Correction KSeF verification URL | https://ksef.mf.gov.pl/... |
Requirements for KSeF
To use KSeF auto-send through FCHub Fakturownia, you need:
Fakturownia KSeF Connection
Your Fakturownia account must be connected to KSeF. This is done within Fakturownia's settings, not in the plugin. Log in to Fakturownia and follow their KSeF setup guide.
KSeF Authorization
You need proper authorization in KSeF for your company. This typically involves an electronic signature or trusted profile (profil zaufany) to authorize Fakturownia to submit invoices on your behalf.
Valid Invoice Data
KSeF has strict validation rules. Invoices must have valid buyer data, proper VAT rates, and correctly formatted fields. The plugin handles most of this automatically, but edge cases (like missing addresses) may cause rejections.
Plugin KSeF Setting Enabled
In the plugin settings, set KSeF Auto Send to Yes. This activates the KSeF flag during invoice creation and enables status polling.
Deactivation Cleanup
When the plugin is deactivated, the KSeF status check cron job is automatically cleared:
register_deactivation_hook(__FILE__, function () {
wp_clear_scheduled_hook('fchub_fakturownia_check_ksef_status');
});This ensures no orphaned cron events remain after deactivation. Any pending KSeF status checks will not execute.
Re-activation
If you deactivate and re-activate the plugin, any invoices that were in processing status will not be automatically re-polled. You can check their KSeF status manually in Fakturownia.
Invoice Generation
How FCHub Fakturownia creates invoices from FluentCart orders, maps buyer data, handles B2B and B2C invoices, calculates VAT rates, and processes correction invoices on refund.
NIP at Checkout
How the "I want a company invoice" toggle and NIP field work at FluentCart checkout, including Polish NIP validation and data storage.