robertogallea/php-fatturapa

There is no license information available for the latest version (0.2.0) of this package.

Php package for Fattura Elettronica PA

0.2.0 2020-04-06 10:22 UTC

This package is auto-updated.

Last update: 2024-04-27 18:19:59 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);