robertogallea / php-fatturapa
Php package for Fattura Elettronica PA
Requires
- nelexa/zip: ^3.1
- robrichards/xmlseclibs: ^3.0.4
- sabre/xml: ^2.1
This package is auto-updated.
Last update: 2025-01-27 19:54:23 UTC
README
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
1. Installation
To install php-fatturapa, require it using composer:
composer require robertogallea/php-fatturapa
2. Usage
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:
2.1 Read From XML document file
/* * Read from XML */ $filename = 'IT01234567890_FPA01.xml'; $fattura = FatturaPA::readFromXML($filename);
2.2 Read From signed XML file
/* * Read from XML signed document */ $filename = 'IT01879020517_e4duu.xml.p7m'; $fattura = FatturaPA::readFromSignedXML($filename);
2.3 Read From XML string
/* * Read from XML string */ $xml = '<your-xml-string>'; $fattura = FatturaPA::readFromXMLString($xml);
2.4 Write to XML file
/* * Read from XML */ $filename = 'IT01234567890_FPA01.xml'; FatturaPA::writeToXML($fattura, $filename);
2.5 Write to XML string
/* * Write to XML string */ $xml = FatturaPA::writeToXMLString($fattura);
3. Attachment handling
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);