PHP code example of metolabs / satcfdi-php

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

    

metolabs / satcfdi-php example snippets


use MetoLabs\SAT\Cfdi\Client;
use MetoLabs\SAT\Cfdi\Credentials\Fiel;

$fiel = Fiel::fromFiles(
    certificate: '/secure/fiel.cer',
    privateKey: '/secure/fiel.key',
    password: $password,
);

$client = Client::usingBridge('/opt/satcfdi/bin/satcfdi-bridge');

$artifact = $client->csf()->download(
    fiel: $fiel,
    destination: '/tmp/csf.pdf',
);

$pdf = $client->csf()->contents($fiel);

$artifact = $client->compliance()->download(
    fiel: $fiel,
    destination: '/tmp/opinion.pdf',
);

$pdf = $client->compliance()->contents($fiel);

$fiel = Fiel::fromContents(
    certificate: $certificateContents,
    privateKey: $privateKeyContents,
    password: $password,
);

$pdf = $client->csf()->contents($fiel);

$response = $client->execute('portal.rfc_valid', [
    'rfc' => 'AAA010101AAA',
]);

$result = $response->result;

$client->portal()->validateRfc('AAA010101AAA');
$client->portal()->validateLegalName('AAA010101AAA', 'ACME SA DE CV');
$client->portal()->lcoDetails('AAA010101AAA');

$capabilities = $client->capabilities();

if ($client->supports('csf.download')) {
    // Supported by the installed bridge.
}

use MetoLabs\SAT\Cfdi\Exceptions\InvalidCredentialsException;
use MetoLabs\SAT\Cfdi\Exceptions\SatCfdiException;
use MetoLabs\SAT\Cfdi\Exceptions\UpstreamException;

try {
    $pdf = $client->csf()->contents($fiel);
} catch (InvalidCredentialsException $e) {
    // Invalid e.firma certificate, private key, or password.
} catch (UpstreamException $e) {
    // SAT/upstream/network error.
} catch (SatCfdiException $e) {
    // Other bridge or protocol error.
}
bash
composer