PHP code example of anglemx / sat-cfdi

1. Go to this page and download the library: Download anglemx/sat-cfdi 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/ */

    

anglemx / sat-cfdi example snippets


<?

use Angle\CFDI\CFDI33;
use Angle\CFDI\XmlLoader;

// ...
// ...
// ...

$xmlFile = 'invoice.xml';

$loader = new XmlLoader();

$cfdi = $loader->fileToCFDI($xmlFile);

if (!$cfdi) {
    // Parsing failed
    // All the helper classes and utilities keep a log of errors that are meant for internal debugging
    echo "Errors:" . PHP_EOL;
    echo print_r($loader->getErrors(), true) . PHP_EOL;

    // And the utilities also keep a log of validations, which are user-friendly and meant for public display
    echo "Validations:" . PHP_EOL;
    echo print_r($loader->getValidations(), true) . PHP_EOL;
}

// Parsing success!
print_r($cfdi);

// The validations log is also available upon success
echo "Validations:" . PHP_EOL;
echo print_r($loader->getValidations(), true) . PHP_EOL;

echo 'Node class: ' . get_class($node) . PHP_EOL;
echo 'Node Name: ' . $node->nodeName . PHP_EOL;
echo 'Node Prefix ' . $node->prefix . PHP_EOL;
echo 'Node Local Name: ' . $node->localName . PHP_EOL;
echo 'Node Base URI: ' . $node->baseURI . PHP_EOL;
echo 'Node Namespace URI: ' . $node->namespaceURI . PHP_EOL;
echo PHP_EOL;
bash
php vendor/bin/phpunit tests