PHP code example of apex-dextra / fiscal-monorepo

1. Go to this page and download the library: Download apex-dextra/fiscal-monorepo 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/ */

    

apex-dextra / fiscal-monorepo example snippets


use Fiscal\\Core\\Security\\A1FileCertificateProvider;
use Fiscal\\Core\\Transport\\CurlHttpTransport;
use Nfe\\Client\\DTO\\AuthorizeNfeRequest;
use Nfe\\Client\\DTO\\Environment;
use Nfe\\Client\\Endpoints\\NfeEndpointResolver;
use Nfe\\Client\\NfeClient;

$provider = new A1FileCertificateProvider('/caminho/certificado.pfx', 'senha');
$client = new NfeClient(
    environment: Environment::HOMOLOGATION,
    endpointResolver: new NfeEndpointResolver(),
    transport: new CurlHttpTransport(),
    certificateProvider: $provider,
    uf: 'SP',
);

$response = $client->authorize(new AuthorizeNfeRequest($signedEnviNfeXml));

use Nfce\\Client\\DTO\\Environment;
use Nfce\\Client\\QRCode\\NfceQrCodeGenerator;

$qrCode = (new NfceQrCodeGenerator())->onlineV3(
    'https://www.sefaz.exemplo.gov.br/nfce/qrcode?p=',
    $accessKey,
    Environment::HOMOLOGATION,
);



declare(strict_types=1);

use Fiscal\Core\Security\A1FileCertificateProvider;
use Fiscal\Core\Security\OpenSslXmlSigner;
use Fiscal\Core\Transport\CurlHttpTransport;
use Fiscal\Core\Validation\DomXmlSchemaValidator;
use Nfse\Client\SefinNacionalClient;
use Nfse\Client\DTO\EmitNfseRequest;
use Nfse\Client\DTO\Environment;
use Nfse\Client\Endpoints\SefinEndpointResolver;

$certificateProvider = new A1FileCertificateProvider('/caminho/certificado.pfx', 'senha');
$signer = new OpenSslXmlSigner();

$signedXml = $signer->sign($dpsXml, $certificateProvider->getCertificate());

$client = new SefinNacionalClient(
    environment: Environment::PRODUCTION_RESTRICTED,
    endpointResolver: new SefinEndpointResolver(),
    transport: new CurlHttpTransport(),
    certificateProvider: $certificateProvider,
    xmlValidator: new DomXmlSchemaValidator(),
    emitSchemaPath: '/caminho/xsd/dps.xsd',
);

$response = $client->emit(new EmitNfseRequest($signedXml));