php-fatturapa is a php implementation for FatturaPA XML specification.
It allows reading from and writing to files formatted as described in the current specifications
To install php-fatturapa, require it using composer:
composer require robertogallea/php-fatturapa
php-fatturapa currently supports only the Fattura Ordinaria model
(not Fattura Semplificata)
The whole DOM of the XML document is wrapped by the class FatturaOrdinaria,
which could be used directly or build using FatturaPA class.
Follow some basic usage exmaples:
/*
* Read from XML
*/
$filename = 'IT01234567890_FPA01.xml';
$fattura = FatturaPA::readFromXML($filename);
/*
* Read from XML signed document
*/
$filename = 'IT01879020517_e4duu.xml.p7m';
$fattura = FatturaPA::readFromSignedXML($filename);
/*
* Read from XML string
*/
$xml = '<your-xml-string>';
$fattura = FatturaPA::readFromXMLString($xml);
/*
* Read from XML
*/
$filename = 'IT01234567890_FPA01.xml';
FatturaPA::writeToXML($fattura, $filename);
/*
* Write to XML string
*/
$xml = FatturaPA::writeToXMLString($fattura);
php-fatturapa provides methods for easily add and
extract attachments to and from the XML document.
By specifications they are stored inside the FatturaElettronicaBody
element, so theFatturaElettronicaBody
class provides convenient methods
for storing attachments performing the required compresson and base64 encoding:
/*
* Export attachments to folder
*/
$filename = 'IT01234567890_FPA01.xml';
$fattura = FatturaPA::readFromXML($filename);
$folder = '/your/path';
foreach ($fattura->getFatturaElettronicaBody() as $body);
$body->esportaAllegati($folder);
}
/*
* Add attachment
*/
$filename = 'IT01234567890_FPA01.xml';
$fattura = FatturaPA::readFromXML($filename);
$attachment_filename = /path/to.pdf;
$attachment = Allegati::createFromFile($attachment_filename,'Name','Description');
$fattura->getFatturaElettronicaBody()[0]->addAttachment($attachment);