1. Go to this page and download the library: Download intermedia/ksef-api-v2 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/ */
declare(strict_types=1);
2\AuthTokenRequest;
use Intermedia\Ksef\Apiv2\Models\Components\{TContextIdentifier, TNip, SubjectIdentifierTypeEnum};
$req = new AuthTokenRequest(
'20250625-CR-20F5EE4000-DA48AE4124-46',
TContextIdentifier::fromNip(new TNip('5265877635')),
SubjectIdentifierTypeEnum::CERTIFICATE_SUBJECT
);
// PEM Signature (private key and public certificate in separate files)
$signedXml = $req->signWithXadesToString('/path/to/private.pem', '/path/to/cert.pem');
// or PKCS#12 (private key and public certificate in one .p12 file)
$signedXml = $req->signWithXadesToString('/path/to/cert.p12', null, 'password_to_p12');