PHP code example of robertogallea / php-fatturapa

1. Go to this page and download the library: Download robertogallea/php-fatturapa 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/ */

    

robertogallea / php-fatturapa example snippets


/*   
 * 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); 

/*   
 * 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);
 

composer