Function sendInvoiceToKsef

Description

Sends an invoice to the National e-Invoice System (Krajowy System e-Faktur) via external KSeF Service.

Important notes

  • Requires active connection to KSeF Service (external microservice)
  • Requires KsefService configuration with API key:
    $tc['api']['KsefService'] = [
        'serverUrl' => 'http://localhost:8080',
        'apiKey' => 'your-api-key',
    ];
  • Invoice must exist in FAKTURY table
  • KSeF Service must be initialized and connected to KSeF
  • Use ping to check if KSeF Service is running

Arguments

array(
  ['idInvoice'] = string   // Invoice ID from FAKTURY table (min. 9 characters)
  ['offline'] = bool       // default is false - ksef mode
)

Example

require_once('classUddsOx.php');

$udds = new classUddsOx;
$udds->customerCode = [your_customerCode];
$udds->login = [your_login];
$udds->password = [your_password];
$udds->serverUrl = 'http://api.dlaoperatora.pl/udds/';

$params = array();
$params['idInvoice'] = '00000004M1G221031126JF1B44ASNQ6D';
$params['offline'] = false;

$ret = $udds->sendInvoiceToKsef($params);

Returns

Success response

{
  "status": "OK",
  "message": "Faktura wysΕ‚ana do KSeF",
  "idInvoice": "00000004M1G221031126JF1B44ASNQ6D",
  "errorCode": null,
  "ksefResponse": {
    "httpCode": "200",
    "message": "Faktura wysΕ‚ana do KSeF",
    "status": "ok"
  }
}

Error response

{
  "status": "ERROR",
  "message": "BΕ‚Δ…d wysyΕ‚ki do KSeF",
  "idInvoice": "00000004M1G221031126JF1B44ASNQ6D",
  "errorCode": 1005,
  "ksefResponse": {
    "httpCode": "404",
    "message": "REST-003: KSeF nie jest zainicjowany",
    "status": "error"
  }
}

Error codes

CodeDescription
1001Missing required parameter idInvoice
1002Invoice with given ID does not exist in FAKTURY table
1003Missing KSeF Service configuration (serverUrl or apiKey)
1004Connection error to KSeF Service
1005KSeF Service response error

KSeF Service error codes (in ksefResponse.message)

CodeDescription
REST-001Unauthorized - invalid API key
REST-002Bad request - missing body
REST-003KSeF not initialized
REST-004Missing required parameter
REST-006Missing invoice ID
REST-009Database connection error
REST-010Processing error
REST-011KSEF_FAKTURY record not found
REST-014System exception