1. Go to this page and download the library: Download naprawksef/sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
naprawksef / sdk example snippets
use NaprawKsef\Sdk\NaprawKsef;
use NaprawKsef\Sdk\Exceptions\RateLimitException;
use NaprawKsef\Sdk\Exceptions\ValidationException;
.2', // optional, attached to User-Agent
]);
// 1. Who am I?
$me = $client->me->retrieve();
echo $me['organization']['name'], PHP_EOL;
// 2. Validate a KSeF XML
$xml = file_get_contents('invoice.xml');
try {
$result = $client->validate->run($xml, filename: 'invoice.xml');
if (!$result['valid']) {
foreach ($result['issues'] as $issue) {
printf("[%s] %s → %s\n", $issue['severity'], $issue['code'], $issue['message']);
}
}
} catch (RateLimitException $e) {
printf("Throttled. Wait %d seconds.\n", $e->retryAfterSeconds() ?? 60);
} catch (ValidationException $e) {
printf("Bad input: %s (%s)\n", $e->getMessage(), $e->code);
}
// 3. Analyse for FA(3) correction scenarios
$analysis = $client->correction->analyze($xml);
print_r($analysis['suggestions']); // top 5 scenarios with confidence