1. Go to this page and download the library: Download almztech/sdk 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/ */
almztech / sdk example snippets
use Almztech\Sdk\AlmztechClient;
use Almztech\Sdk\Erros\AlmztechProtocoloRejeitadoException;
use Almztech\Sdk\Erros\AlmztechValidationException;
use Almztech\Sdk\Filtros;
use Almztech\Sdk\Webhook;
// A api key está no Portal (portal.almztech.com.br), em Primeiros passos. Guarde-a na configuração do seu
// sistema, nunca no código.
$client = new AlmztechClient(getenv('ALMZTECH_API_KEY'));
try {
$protocolo = $client->notasFiscais->emitir([
'identificacaoEmitente' => '12345678000190',
'enviarParaProducao' => false, // homologação (HML-...): não consome a franquia
'notas' => [[
'rps' => ['numeroRPS' => '1001', 'serie' => '1', 'tipo' => '1', 'dataEmissao' => date('Y-m-d')],
'destinatario' => [
'cpfCnpj' => '11222333000181',
'razaoSocial' => 'Cliente Exemplo Ltda',
'endereco' => ['cep' => '50030170', 'codigoIBGEMunicipio' => 2611606],
],
'servicos' => [['codigo' => '0105', 'descricao' => 'Licenciamento de software', 'quantidade' => 1,
'valorUnitario' => 1500.00, 'aliquotaISS' => 2, 'retemISS' => 2]],
]],
]);
$resultado = $client->notasFiscais->aguardarConclusao($protocolo['protocolo']);
foreach ($resultado['notas'] ?? [] as $nota) {
file_put_contents("nfse-{$nota['numero']}.pdf", $client->notasFiscais->baixarPdf($nota['codigoNota']));
}
} catch (AlmztechProtocoloRejeitadoException $erro) {
echo 'Rejeitada: ', $erro->protocolo['mensagem'] ?? '', "\n";
} catch (AlmztechValidationException $erro) {
echo 'Recusada: ', $erro->mensagem, "\n";
}
// No seu endpoint de webhook (a API não assina o payload: proteja a URL):
$evento = Webhook::ler(file_get_contents('php://input')); // ['tipo' => Webhook::EMISSAO|CANCELAMENTO|REJEICAO, 'protocolo' => ...]