Exemple #1
0
 private static function init()
 {
     self::$_proxy = self::createProxy();
     self::$NFeApi = new api\nfeApi(self::$_proxy);
     self::$EmpresaApi = new api\empresaApi(self::$_proxy);
     self::$PrefeituraApi = new api\prefeituraApi(self::$_proxy);
     self::$ServicosMunicipaisApi = new api\servicosMunicipaisApi(self::$_proxy);
 }
use eNotasGW\Api\Exceptions;
use eNotasGW\Api\fileParameter;
class tipoAutenticacao
{
    const Nenhuma = 0;
    const Certificado = 1;
    const UsuarioESenha = 2;
    const Token = 3;
}
class tipoAssinaturaDigital
{
    const NaoUtiliza = 0;
    const Opcional = 1;
    const Obrigatorio = 2;
}
eNotasGW::configure(array('apiKey' => '<api key>'));
try {
    $codigoIbgeCidade = 3106200;
    $caracteristicasPrefeitura = eNotasGW::$PrefeituraApi->consultar($codigoIbgeCidade);
    $dadosEmpresa = array('cnpj' => '56308661000199', 'inscricaoMunicipal' => '12345', 'inscricaoEstadual' => null, 'razaoSocial' => 'Empresa de Teste Ltda', 'nomeFantasia' => 'Empresa de Teste', 'optanteSimplesNacional' => true, 'email' => null, 'telefoneComercial' => '3132323131', 'endereco' => array('uf' => 'MG', 'cidade' => 'Belo Horizonte', 'logradouro' => 'Rua 01', 'numero' => '112', 'complemento' => 'SL 102', 'bairro' => 'Savassi', 'cep' => '32323111'), 'regimeEspecialTributacao' => '0', 'codigoServicoMunicipal' => '181309901', 'descricaoServico' => 'SERVICO DE SERIGRAFIA / SILK-SCREEN', 'configuracoesNFSeProducao' => array('sequencialNFe' => 1, 'serieNFe' => '2', 'sequencialLoteNFe' => 1), 'configuracoesNFSeHomologacao' => array('sequencialNFe' => 1, 'serieNFe' => '2', 'sequencialLoteNFe' => 1));
    if ($caracteristicasPrefeitura->usaCNAE) {
        $dadosEmpresa->cnae = '1813099';
    }
    if ($caracteristicasPrefeitura->usaItemListaServico) {
        $dadosEmpresa->itemListaServicoLC116 = '13.05';
    }
    if ($caracteristicasPrefeitura->tipoAutenticacao == tipoAutenticacao::UsuarioESenha) {
        $dadosEmpresa['configuracoesNFSeProducao']['usuarioAcessoProvedor'] = '[usuario]';
        $dadosEmpresa['configuracoesNFSeProducao']['senhaAcessoProvedor'] = '[senha]';
        //opcional, preencher apenas se for emitir em ambiente de homologação
        $dadosEmpresa['configuracoesNFSeHomologacao']['usuarioAcessoProvedor'] = '[usuario]';
<?php

header('Content-Type: text/html; charset=utf-8');
require '../src/eNotasGW.php';
use eNotasGW\Api\Exceptions;
use eNotasGW\Api\fileParameter;
eNotasGW::configure(array('apiKey' => '{api key}'));
$empresaId = '{empresa id}';
try {
    $file = fileParameter::fromPath('{certificate file path}.pfx', 'application/x-pkcs12', '{file name}.pfx');
    $pass = '******';
    eNotasGW::$EmpresaApi->atualizarCertificado($empresaId, $file, $pass);
    echo 'Certificado atualizado com sucesso!';
} catch (Exceptions\invalidApiKeyException $ex) {
    echo 'Erro de autenticação: </br></br>';
    echo $ex->getMessage();
} catch (Exceptions\unauthorizedException $ex) {
    echo 'Acesso negado: </br></br>';
    echo $ex->getMessage();
} catch (Exceptions\apiException $ex) {
    echo 'Erro de validação: </br></br>';
    echo $ex->getMessage();
} catch (Exceptions\requestException $ex) {
    echo 'Erro na requisição web: </br></br>';
    echo 'Requested url: ' . $ex->requestedUrl;
    echo '</br>';
    echo 'Response Code: ' . $ex->getCode();
    echo '</br>';
    echo 'Message: ' . $ex->getMessage();
    echo '</br>';
    echo 'Response Body: ' . $ex->responseBody;
Exemple #4
0
 private static function init()
 {
     self::$_proxy = self::createProxy();
     self::$NFeApi = new api\nfeApi(self::$_proxy);
 }
Exemple #5
0
{
    $xml = eNotasGW::$NFeApi->downloadXml($empresaId, $nfeId);
    file_put_contents("Notas\\Autorizadas\\NF-{$nfeNumero}.xml", $xml);
}
function downloadPdf($empresaId, $nfeId, $nfeNumero)
{
    $pdf = eNotasGW::$NFeApi->downloadPdf($empresaId, $nfeId);
    file_put_contents("Notas\\Autorizadas\\NF-{$nfeNumero}.pdf", $pdf);
}
function gerarLogNFeNegada($id, $motivoStatus)
{
    file_put_contents("Notas\\Negadas\\NF-{$id}-erros.txt", $motivoStatus);
}
$postContent = file_get_contents("php://input");
if (!empty($postContent)) {
    $formatter = eNotasGW::getMediaFormatter($_SERVER['CONTENT_TYPE']);
    $webHookData = $formatter->decode($postContent);
    switch (strtolower($webHookData->nfeStatus)) {
        case 'autorizada':
            downloadXml($webHookData->empresaId, $webHookData->nfeId, $webHookData->nfeNumero);
            downloadPdf($webHookData->empresaId, $webHookData->nfeId, $webHookData->nfeNumero);
            break;
        case 'negada':
            gerarLogNFeNegada(empty($webHookData->nfeIdExterno) ? $webHookData->nfeId : $webHookData->nfeIdExterno, $webHookData->nfeMotivoStatus);
            break;
        case 'cancelada':
            if (!empty($webHookData->nfeNumero)) {
                //download do pdf atualizado (com carimbo de cancelada)
                downloadPdf($webHookData->empresaId, $webHookData->nfeId, $webHookData->nfeNumero);
            }
            break;