1. Go to this page and download the library: Download phpcfdi/sat-estado-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/ */
phpcfdi / sat-estado-cfdi example snippets
use PhpCfdi\SatEstadoCfdi\Consumer;
use PhpCfdi\SatEstadoCfdi\Contracts\ConsumerClientInterface;
/** @var ConsumerClientInterface $client */
$consumer = new Consumer($client);
$cfdiStatus = $consumer->execute('...expression');
if ($cfdiStatus->cancellable->isNotCancellable()) {
echo 'CFDI no es cancelable';
}
use PhpCfdi\SatEstadoCfdi\Clients\Soap\SoapConsumerClient;
use PhpCfdi\SatEstadoCfdi\Consumer;
function createConsumerUsingSoap(): Consumer
{
$client = new SoapConsumerClient();
return new Consumer($client);
}
use PhpCfdi\SatEstadoCfdi\Clients\Http\HttpConsumerClient;
use PhpCfdi\SatEstadoCfdi\Clients\Http\HttpConsumerFactory;
use PhpCfdi\SatEstadoCfdi\Consumer;
function createConsumerUsingGuzzle(): Consumer
{
// Implements PSR-18 \Psr\Http\Client\ClientInterface
$guzzleClient = new \GuzzleHttp\Client();
// Implements PSR-17 \Psr\Http\Message\RequestFactoryInterface and PSR-17 \Psr\Http\Message\StreamFactoryInterface
$guzzleFactory = new \GuzzleHttp\Psr7\HttpFactory();
$factory = new HttpConsumerFactory($guzzleClient, $guzzleFactory, $guzzleFactory);
$client = new HttpConsumerClient($factory);
return new Consumer($client);
}
use PhpCfdi\SatEstadoCfdi\Consumer;
use PhpCfdi\SatEstadoCfdi\Clients\Http\HttpConsumerClient;
use PhpCfdi\SatEstadoCfdi\Clients\Http\HttpConsumerFactory;
function createConsumerUsingSymfonyNyholm(): Consumer
{
$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$messageFactory = new \Nyholm\Psr7\Factory\Psr17Factory();
$factory = new HttpConsumerFactory($httpClient, $messageFactory, $messageFactory);
$client = new HttpConsumerClient($factory);
return new Consumer($client);
}
use PhpCfdi\SatEstadoCfdi\Consumer;
use PhpCfdi\SatEstadoCfdi\Clients\Http\HttpConsumerClient;
use PhpCfdi\SatEstadoCfdi\Clients\Http\HttpConsumerFactory;
function createConsumerUsingLaravel(): Consumer
{
$httpClient = app(\Psr\Http\Client\ClientInterface::class);
$requestFactory = app(Psr\Http\Message\RequestFactoryInterface::class);
$streamFactory = app(Psr\Http\Message\StreamFactoryInterface::class);
$factory = new HttpConsumerFactory($httpClient, $requestFactory, $streamFactory);
$client = new HttpConsumerClient($factory);
return new Consumer($client);
}
use PhpCfdi\CfdiExpresiones\DiscoverExtractor;
use PhpCfdi\SatEstadoCfdi\Consumer;
// lectura del contenido del CFDI
$document = new DOMDocument();
$document->load('archivo-cfdi.xml');
// creación de la expresión
$expressionExtractor = new DiscoverExtractor();
$expression = $expressionExtractor->extract($document);
// realizar la consulta con la expresión obtenida
/** @var Consumer $consumer */
$cfdiStatus = $consumer->execute($expression);
// usar el estado
if ($cfdiStatus->document->isActive()) {
echo 'El CFDI se encuentra vigente';
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.