PHP code example of intermedia / ksef-fa3

1. Go to this page and download the library: Download intermedia/ksef-fa3 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/ */

    

intermedia / ksef-fa3 example snippets



Intermedia\Ksef\Fa3\Model\FakturaType;
use Intermedia\Ksef\Fa3\Model\TNaglowek;
use Intermedia\Ksef\Fa3\Model\Podmiot1Type;
use Intermedia\Ksef\Fa3\Model\FaType;
use Intermedia\Ksef\Fa3\Model\FaWierszType;
use Intermedia\Ksef\Fa3\Serializer\XmlSerializer;
use Intermedia\Ksef\Fa3\Validator\XmlValidator;

// Tworzenie faktury
$faktura = new FakturaType();
$faktura->naglowek = new TNaglowek();
$faktura->podmiot1 = new Podmiot1Type();

$pozycja = new FaWierszType();
$fa = new FaType();
$fa->faWiersz = [$pozycja];
$faktura->fa = $fa;

// Serializacja do XML
$serializer = new XmlSerializer();
$doc = $serializer->createDocument('Faktura', $faktura);
echo $doc->saveXML();

// Walidacja względem XSD
$validator = new XmlValidator(__DIR__.'/vendor/intermedia/ksef/fa3/schema/FA3.xsd');
$result = $validator->validate($doc);

if ($result->isValid) {
    echo "Dokument jest poprawny względem XSD.";
} else {
    foreach ($result->errors as $error) {
        echo $error->message, PHP_EOL;
    }
}