eInvoices KSeF
Overview
eInvoices KSeF is a transport module for eInvoices exporter allowing you to export your HostBill invoices into KSeF API (Polish: Krajowy System eFaktur).
Module requires:
PHP 8.1+ (check HostBill System Requirements for currently supported PHP version)
active eInvoices Exporter module.
EU Invoicing method should be used (where unpaid invoices are pro-forma invoices, and paid ones are considered final/fiscal ones)
Final Invoice Delayoption in EU Invoicing method should be disabledTo ensure exported invoice consistency, consider using
Block final invoice editsoption in EU invoicing settings
Activating the module
If the plugin is included in your HostBill edition you can download it from your client portal.
If the plugin is not included in your HostBill edition you can purchase it from our marketplace and then download it from the client area.
Once you download the plugin extract it in the main HostBill directory.
Go to Settings → Modules, find and activate eInvoices KSeF.
Once the plugin is activated you will be directed to Settings→ Modules→ Plugins to configure the plugin.
Module configuration
Fill in the configuration fields:
Module display name
NIP - Your Company NIP number, used on invoices and for KSeF connection
Mode - KSeF API Mode - pick between test/demo/production. When using test mode ensure to use fake NIP number
Auth Method - Select between token and certificate authentication method this module should use to connect to KSeF API
KSeF Token - Enter your KSeF Token, required if Auth Method is configured to use it
Certificate Path - Full path to
.p12certificate file - used for authorization (uwierzytelnianie w systemie KSeF). Required if Auth Method is configured to use it. Ensure to place it outside of the webroot. If you have certificate generated in MCU portal you can convert it to.p12using this module, see Converting MCU Certificates below.Certificate Password -
.p12certificate password - used for authorization (uwierzytelnianie w systemie KSeF).Offline Certificate Path - Full path to
.p12certificate file - used for offline mode (Podpis linku do weryfikacji wystawcy). Ensure to place it outside of the webroot. If you have certificate generated in MCU portal you can convert it to.p12using this module, see Converting MCU Certificates below. Required for QR codesOffline Certificate Password -
.p12certificate password - used for offline mode (Podpis linku do weryfikacji wystawcy). Required for QR codesOffline Certificate Serial Number -
.p12certificate serial number - used for offline mode (Podpis linku do weryfikacji wystawcy). Required for QR codesQR Codes Path - Full path where QR code images will be saved, should be writeable by php process. Consider to place it outside of the webroot.
VAT field - Registration field responsible for storing customer vat/nip number.
Additional Org number field - Optional registration field responsible for storing customer additional registration number, ie regon
Company Name - Full name of your company
Company Address 1 - Your company address
Company Address 2 - Second line of address for your company
Company Email - Your company billing email
Company Phone - Phone number of your company
KRS - KRS (if present)
REGON - REGON (if present)
BDO - BDO (if present)
Bank Account Number - Your company Bank Account Number/IBAN. Optional
Bank Name - Name of your bank. Optional
Bank Swift code - Swift code for your bank. Optional
Always include bank details - When enabled bank details will be always sent to KSeF, even if invoice is not unpaid
Force 2nd Currency - When enabled your invoices a not issued in PLN, invoice will be sent to KSeF converted to PLN configured in 2nd currency option (configured in Settings -> Billing -> Document templates).
Example: if primary invoice currency in HB is USD, and 2nd currency option is enabled (and set to PLN), invoice will be sent to KSeF as if it was issued only in PLNUse 2nd Language - When enabled and invoice lines are translated to 2nd language, invoice lines will be sent to KSeF in 2nd language
Use Due Date - When enabled invoice due date will be set as
FA(3): TerminPlatnosciOSS Procedure - Enable if your company is part of OSS procedure, where it can have tax rates different that the ones in Poland for B2C EU invoices
Anonymize invoice - This option works only in KSeF test mode/environment.
When enabled, invoice details like: item descriptions, notes, customer and your company details (but not NIP), will be anonymized (replaced with random characters) in FA(3). Useful for testing exporting actual invoices against test environment.
Global Tax exemption - Enable if your company uses
"zw"as tax, used withP_19CGlobal Tax exemption reason - Enter explanation (podstawa prawna) for using tax exemption
P_19CStore UPO - Enable to download and store UPO xml files upon invoice delivery
UPO files storage path - Full path where UPO xml files will be saved, should be writeable by php process. Consider to place it outside of the webroot.
Shared items PKWiU - Enter shared PKWiU for all invoice items that cannot be determined via dedicated module settings. Leave empty if it should not be set in FA(3)
Shared items GTIN - Enter shared GTIN for all invoice items that cannot be determined via module settings. Leave empty if it should not be set in FA(3)
Shared items GTU - Pick shared GTU for all invoice items that cannot be determined via module settings. Leave empty if it should not be set in FA(3)
Items unit - Items unit (
P_8A) defaults to: szt.Invoice footer text - If this field is filled it will be always added as a footer text (Stopka faktury).
Once configuration options are set, ensure to click on Test module settings & connectivity button, to verify if the module can:
connect to selected KSeF API
read certificate files
write QR codes into destination directory
Obtaining KSeF tokens/certificates from MCU
In order to connect to KSeF API you will need either a token or a certificate generated in MCU / Aplikacja Podatnika KSeF. For generating QR codes and putting them on invoices issued in HostBill you will need a certificate too.
To generate a connection token go to Tokeny → Generuj token. For exporting invoices you only need the “wystawianie faktur” scope.
To generate certificate for QR codes, proceed to Certyfikaty → Wnioskuj o certyfikat. Generate new key, ensure to store/remember passphrase.
Select “Podpis linku do weryfikacji wystawcy” as “Przeznaczenie certyfikatu”, generate certificate.
Once the certificate gets issued, proceed to Certyfikaty → Lista certyfikatów to copy Certificate Serial Number (Numer seryjny certyfikatu) - it will be required for QR code generation.
If you want to make use of certificate for API connection, repeat steps above for separate certificate, ensuring to select “Uwierzytelnienie” as certificate purpose
Converting MCU Certificates
To be able to generate QR codes and in case of using certificates for API connection, you will need to convert MCU-generated certificate (*.crt, *.key) into .p12 certificate format module “understands”. To make it easier, module adds feature for conversion under Extras → Plugins → KSeF.
To create .p12 version of certificate:
select
.crtfile downloaded from MCUselect
.keyfile downloaded from MCUenter certificate passphrase (set when generating key in MCU)
hit Generate certificate → browser should send you a
.p12file.Upload
.p12certificate file into path configured in module settings
GTIN/GTU/PKWiU classifications
In module configuration you can define shared GTIN/GTU/PKWiU classification for all items on exported invoices. If certain products should have its own individual classifications, you can set them in Extras → Plugins → KSeF → GTIN/GTU/PKWiU classification.
When generating FA(3) file module will look for target classification for each individual invoice line
If none is set for related product, category one would be applied
If product/category cannot be applied/found shared one from module settings will be used
In case that no matching and shared configuration is set -> related field in
FA(3)would not be set
KSeF QR codes on HostBill invoices
KSeF specification requires to place certain QR codes on invoice that is sent or shown. eInvoices KSeF module can generate them for you automatically.
When invoice is scheduled to export, but not yet exported (KSeF: offline24 mode) module will let you render 2 QR codes on invoices:
offline QR
certificate QR
When invoice gets successfully exported to KSeF, module will let you render online QR code.
Add following code to your HostBill Invoice template in place where you want to render QR codes:
{if $ksef}
{if $ksef.status == 'offline'}
{ksefqr type='offline' width="250" align="left"}
{ksefqr type='cert' width="250" align="left"}
{else}
{ksefqr type='online' width="250" align="left"}
Identyfikator faktury w KSeF: {$ksef.id}
{/if}
{/if}
Testing module
It is advised to first test the module capabilities in test API mode, before sending actual invoices into production system. To test:
Disable autoexport in eInvoices Exporter module
Select
testAPI mode in eInvoices KSeF moduleGenerate fake PL company credentials, ie using: https://danetestowe.pl/generator/firmowe
store them in eInvoices KSeF module configuration
consider enabling
Anonymize invoiceoption in module configuration to send anonymized invoice contents to test environment
Authenticate to test KSeF: Krajowy System e-Faktur using generated fake NIP number, to generate certificates and tokens
Convert downloaded certificates and store them in module configuration
Attempt to export single invoice from your system using eInvoice → Schedule button.
Export only invoice that you do not plan to export into production mode
Wait up to 5 minutes for cron to pick up invoice for delivery
Refresh invoice page to verify outcome.
Using eInvoices KSeF
eInvoices Exporter module is used to schedule invoice exports, whilst eInvoices KSeF performs actual FA(3) XML generation and delivery to KSeF API. Depending on configuration exporter module, exports can be automated (ie. as soon final invoice gets issued after payment).
You can track current state of delivery in adminarea invoice details, or in eInvoices Exporter module listing.
When
DEBUGlog level is enabled in General HostBill settings module will log each API request into separate log file, accessible from module page in Extras → Plugins → KSeFModule will export each attempted invoices (regardless if recipient is from EU/PL/World or B2C/B2B/B2G)
Module currently do not export / create Faktura Korekta - this feature is being developed
Once invoice is exported it is not possible to re-export it. If you first exported invoice in test mode and wish to re-export it in live mode, relate related invoice row from database table:
hb_einvoice_delivery
For testing purposes, module adds button KSeF button in admin UI: “Generuj aktualny XML”. This button generates FA(3) xml of current invoice state and downloads it as XML file, allowing you to validate its schema. It is possible to generate XML for invoice that was not sent to KSeF yet. Note that any changes in invoice details will be reflected in this XML (so once invoice changes and XML gets re-generated using this button, it will be new one)
To download exact XML of invoice that was sent, use “Pobierz wysłany XML”
To download UPO (Urzędowe Potwierdzenie Odbioru) for sent invoice, use Pobierz UPO XML option (available only if UPO was stored)