├── src ├── nfeConsumidorApi.php ├── nfeProdutoApi.php ├── nfeServicoApi.php ├── media │ └── formatters │ │ ├── formatterBase.php │ │ ├── jsonFormatter.php │ │ └── formDataFormatter.php ├── helper.php ├── exceptions │ ├── invalidApiKeyException.php │ ├── unauthorizedException.php │ ├── requestException.php │ └── apiException.php ├── apiBase.php ├── prefeituraApi.php ├── fileParameter.php ├── response.php ├── servicosMunicipaisApi.php ├── request.php ├── empresaApi.php ├── proxy │ ├── curlProxy.php │ └── proxyBase.php ├── eNotasGW.php └── nfeApiBase.php ├── composer.json ├── LICENSE ├── examples ├── nf-e │ ├── cancelamento.php │ └── emissao.php ├── nfc-e │ └── emissao.php └── empresa │ ├── nf-e │ └── inserirAtualizar.php │ ├── nfc-e │ └── inserirAtualizar.php │ └── nfs-e │ └── inserirAtualizar.php └── README.md /src/nfeConsumidorApi.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/nfeProdutoApi.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /src/nfeServicoApi.php: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /src/media/formatters/formatterBase.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /src/helper.php: -------------------------------------------------------------------------------- 1 | format('Y-m-d'); 7 | } 8 | 9 | public static function formatDateTime($dateTime) { 10 | return $date->format('Y-m-d H:i:s'); 11 | } 12 | } 13 | ?> 14 | -------------------------------------------------------------------------------- /src/exceptions/invalidApiKeyException.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /src/exceptions/unauthorizedException.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /src/apiBase.php: -------------------------------------------------------------------------------- 1 | proxy = $proxy; 9 | } 10 | 11 | protected function callOperation($operation) { 12 | return $this->proxy->doRequest($operation); 13 | } 14 | } 15 | ?> -------------------------------------------------------------------------------- /src/media/formatters/jsonFormatter.php: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enotas/php-client-v2", 3 | "description": "eNotas GW API client for PHP v2", 4 | "keywords": ["eNotas", "NF-e", "NFC-e"], 5 | "homepage": "https://github.com/eNotasGW/php-client-v2", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "eNotas Gateway", 11 | "email": "suporte@enotasgw.com.br" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.3.0" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "eNotasGW\\Api\\": "src/" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/exceptions/requestException.php: -------------------------------------------------------------------------------- 1 | requestedUrl = $requestedUrl; 21 | $this->responseBody = $responseBody; 22 | 23 | parent::__construct($faultMessage, $httpCode, null); 24 | } 25 | } 26 | ?> 27 | -------------------------------------------------------------------------------- /src/exceptions/apiException.php: -------------------------------------------------------------------------------- 1 | errors = $errors; 11 | $message = $this->formatMessage(); 12 | 13 | parent::__construct($message, $httpCode, null); 14 | } 15 | 16 | protected function formatMessage() { 17 | $message = ''; 18 | $padding = ''; 19 | 20 | foreach ($this->errors as &$error) { 21 | $message .= $padding . "{$error->codigo} - {$error->mensagem}"; 22 | $padding = PHP_EOL; 23 | } 24 | 25 | return $message; 26 | } 27 | } 28 | ?> 29 | -------------------------------------------------------------------------------- /src/prefeituraApi.php: -------------------------------------------------------------------------------- 1 | callOperation(array( 17 | 'path' => '/estados/cidades/{codigoIbge}/provedor', 18 | 'parameters' => array( 19 | 'path' => array( 20 | 'codigoIbge' => $codigoIbge 21 | ) 22 | ) 23 | )); 24 | } 25 | } 26 | ?> -------------------------------------------------------------------------------- /src/fileParameter.php: -------------------------------------------------------------------------------- 1 | rawData = $rawData; 14 | $file->contentType = $contentType; 15 | $file->name = $fileName; 16 | 17 | return $file; 18 | } 19 | 20 | private function __contruct() { 21 | } 22 | 23 | /** 24 | * File name 25 | * @var string 26 | */ 27 | public $name; 28 | 29 | /** 30 | * The file content type, for example: "image/jpeg" 31 | * @var string 32 | */ 33 | public $contentType; 34 | 35 | /** 36 | * The file Raw Data (bytes) 37 | * @var array 38 | */ 39 | public $rawData; 40 | } 41 | ?> -------------------------------------------------------------------------------- /src/response.php: -------------------------------------------------------------------------------- 1 | body === FALSE 33 | || $this->body == ''; 34 | } 35 | 36 | public function getResponseData() { 37 | if($this->isEmpty()) { 38 | return NULL; 39 | } 40 | else { 41 | return $this->decodeResponse(); 42 | } 43 | } 44 | 45 | private function decodeResponse() { 46 | $formatter = eNotasGW::getMediaFormatter($this->contentType); 47 | 48 | return $formatter->decode($this->body); 49 | } 50 | } 51 | ?> -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 eNotas Gateway 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/nf-e/cancelamento.php: -------------------------------------------------------------------------------- 1 | '' 10 | )); 11 | 12 | $idEmpresa = '484FB0C5-969E-46AD-A047-8A0DB54667B4'; 13 | $idNFe = '10'; 14 | 15 | try 16 | { 17 | eNotasGW::$NFeProdutoApi->cancelar($empresaId, $idNFe); 18 | echo 'Sucesso!
'; 19 | } 20 | catch(Exceptions\invalidApiKeyException $ex) { 21 | echo 'Erro de autenticação:

'; 22 | echo $ex->getMessage(); 23 | } 24 | catch(Exceptions\unauthorizedException $ex) { 25 | echo 'Acesso negado:

'; 26 | echo $ex->getMessage(); 27 | } 28 | catch(Exceptions\apiException $ex) { 29 | echo 'Erro de validação:

'; 30 | echo $ex->getMessage(); 31 | } 32 | catch(Exceptions\requestException $ex) { 33 | echo 'Erro na requisição web:

'; 34 | 35 | echo 'Requested url: ' . $ex->requestedUrl; 36 | echo '
'; 37 | echo 'Response Code: ' . $ex->getCode(); 38 | echo '
'; 39 | echo 'Message: ' . $ex->getMessage(); 40 | echo '
'; 41 | echo 'Response Body: ' . $ex->responseBody; 42 | } 43 | ?> 44 | -------------------------------------------------------------------------------- /src/servicosMunicipaisApi.php: -------------------------------------------------------------------------------- 1 | callOperation(array( 21 | 'path' => '/estados/{uf}/cidades/{nome}/servicos', 22 | 'parameters' => array( 23 | 'path' => array( 24 | 'uf' => $uf, 25 | 'nome' => $cidade 26 | ), 27 | 'query' => array( 28 | 'pageNumber' => $pageNumber, 29 | 'pageSize' => $pageSize, 30 | 'filter' => $termoPesquisa != NULL ? "contains(descricao, '{$termoPesquisa}')" : NULL 31 | ) 32 | ) 33 | )); 34 | } 35 | 36 | public function consultarCidades($pageNumber, $pageSize) { 37 | return $this->callOperation(array( 38 | 'path' => '/servicos/cidades', 39 | 'parameters' => array( 40 | 'query' => array( 41 | 'pageNumber' => $pageNumber, 42 | 'pageSize' => $pageSize 43 | ) 44 | ) 45 | )); 46 | } 47 | } 48 | ?> -------------------------------------------------------------------------------- /src/request.php: -------------------------------------------------------------------------------- 1 | parameters[$name] = $value; 51 | } 52 | 53 | public function getParameter($name) { 54 | return $this->parameters[$name]; 55 | } 56 | 57 | public function getRequestBody() { 58 | if(empty($this->parameters)) { 59 | return NULL; 60 | } 61 | else { 62 | return $this->encodeRequestParameters(); 63 | } 64 | } 65 | 66 | public function encodeRequestParameters() { 67 | $contentType = $this->contentType; 68 | $formatter = eNotasGW::getMediaFormatter($contentType); 69 | 70 | if($formatter !== FALSE) { 71 | $result = $formatter->encode($this->parameters, $contentType); 72 | $this->contentType = $contentType; 73 | 74 | return $result; 75 | } 76 | 77 | return $this->parameters; 78 | } 79 | } 80 | ?> -------------------------------------------------------------------------------- /src/media/formatters/formDataFormatter.php: -------------------------------------------------------------------------------- 1 | $value) { 14 | $name = $this->removeNotAllowedChars($name); 15 | $body[] = "--" . $boundary; 16 | 17 | if(is_a($value, 'eNotasGW\Api\fileParameter')) { 18 | $this->appendFileParameter($name, $value, $body); 19 | } 20 | else { 21 | $this->appendParameter($name, $value, $body); 22 | } 23 | } 24 | } 25 | 26 | $body[] = "--" . $boundary . "--\r\n"; 27 | 28 | return implode("\r\n", $body); 29 | } 30 | 31 | private function appendParameter($name, $value, &$body) { 32 | $body[] = implode("\r\n", array( 33 | "Content-Disposition: form-data; name=\"{$name}\"", 34 | '', 35 | filter_var($value, FILTER_SANITIZE_STRING), 36 | )); 37 | } 38 | 39 | private function appendFileParameter($name, $file, &$body) { 40 | $fileName = $file->name; 41 | 42 | $body[] = implode("\r\n", array( 43 | "Content-Disposition: form-data; name=\"{$name}\"; filename=\"{$fileName}\"", 44 | 'Content-Type: ' . (isset($file->contentType) ? $file->contentType : 'application/octet-stream'), 45 | '', 46 | $file->rawData, 47 | )); 48 | } 49 | 50 | private function removeNotAllowedChars($name) { 51 | return str_replace(self::$_notAllowedChars, "_", $name); 52 | } 53 | 54 | public function decode($encodedData) { 55 | throw new Exception('This method is not supported'); 56 | } 57 | } 58 | ?> 59 | -------------------------------------------------------------------------------- /src/empresaApi.php: -------------------------------------------------------------------------------- 1 | callOperation(array( 16 | 'method' => 'POST', 17 | 'path' => '/empresas', 18 | 'parameters' => array( 19 | 'body' => $dados 20 | ) 21 | )); 22 | } 23 | 24 | /** 25 | * Atualiza a logo da empresa 26 | * 27 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 28 | * @param fileParameter $file imagem a ser utilizada como logo. 29 | */ 30 | public function atualizarLogo($idEmpresa, $file) { 31 | $this->callOperation(array( 32 | 'method' => 'POST', 33 | 'decodeResponse' => FALSE, 34 | 'path' => '/empresas/{empresaId}/logo', 35 | 'parameters' => array( 36 | 'path' => array( 37 | 'empresaId' => $idEmpresa 38 | ), 39 | 'form' => array( 40 | 'logotipo' => $file 41 | ) 42 | ) 43 | )); 44 | } 45 | 46 | /** 47 | * Atualiza o certificado digital da empresa 48 | * 49 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 50 | * @param fileParameter $file arquivo do certificado. 51 | * @param string $pass senha do certificado. 52 | */ 53 | public function atualizarCertificado($idEmpresa, $file, $pass) { 54 | $this->callOperation(array( 55 | 'method' => 'POST', 56 | 'decodeResponse' => FALSE, 57 | 'path' => '/empresas/{empresaId}/certificadoDigital', 58 | 'parameters' => array( 59 | 'path' => array( 60 | 'empresaId' => $idEmpresa 61 | ), 62 | 'form' => array( 63 | 'arquivo' => $file, 64 | 'senha' => $pass 65 | ) 66 | ) 67 | )); 68 | } 69 | } 70 | ?> -------------------------------------------------------------------------------- /src/proxy/curlProxy.php: -------------------------------------------------------------------------------- 1 | method); 11 | $options = array( 12 | CURLOPT_URL => $request->url, 13 | CURLOPT_RETURNTRANSFER => TRUE, 14 | CURLOPT_TIMEOUT => $request->timeout, 15 | CURLOPT_SSL_VERIFYHOST => 2, 16 | CURLOPT_SSL_VERIFYPEER => TRUE, 17 | CURLOPT_CAINFO => $this->executionCtx->trustedCAListPath 18 | ); 19 | 20 | switch($method) { 21 | case 'POST': 22 | $options[CURLOPT_POST] = 1; 23 | $this->setRequestBody($request, $options); 24 | break; 25 | case 'PUT': 26 | $this->setRequestBody($request, $options); 27 | case 'DELETE': 28 | $options[CURLOPT_CUSTOMREQUEST] = $method; 29 | break; 30 | default: 31 | break; 32 | } 33 | 34 | //workaround to remove Expectation -> "Expect: 100-continue" that can be a problem in some networks 35 | $request->headers[] = 'Expect:'; 36 | $request->headers[] = 'Content-Type: ' . $request->contentType; 37 | $options[CURLOPT_HTTPHEADER] = $request->headers; 38 | 39 | $ch = curl_init(); 40 | curl_setopt_array($ch, $options); 41 | //curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888'); 42 | 43 | $response = new \eNotasGW\Api\response(); 44 | $response->body = curl_exec($ch); 45 | $response->contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); 46 | $response->code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 47 | 48 | if($response->code != 200 && $response->isEmpty()) { 49 | $response->faultMessage = curl_error($ch); 50 | } 51 | 52 | return $response; 53 | } 54 | 55 | private function setRequestBody($request, &$options) { 56 | $body = $request->getRequestBody(); 57 | $options[CURLOPT_POSTFIELDS] = $body; 58 | 59 | if(is_string($body)) { 60 | $request->headers[] = 'Content-Length: ' . strlen($body); 61 | } 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /examples/nfc-e/emissao.php: -------------------------------------------------------------------------------- 1 | '' 10 | )); 11 | 12 | $idEmpresa = '484FB0C5-969E-46AD-A047-8A0DB54667B4'; 13 | 14 | try 15 | { 16 | $result = eNotasGW::$NFeConsumidorApi->emitir($idEmpresa, array( 17 | // identificador único da requisição de emissão de nota fiscal 18 | // (normalmente será preenchido com o id único do registro no sistema de origem) 19 | 'id' => '8', 20 | 'ambienteEmissao' => 'Homologacao', //'Producao' ou 'Homologacao' 21 | 'pedido' => array( 22 | 'presencaConsumidor' => 'OperacaoPresencial', 23 | 'pagamento' => array( 24 | 'tipo' => 'PagamentoAVista', 25 | 'formas' => array( 26 | array( 27 | 'tipo' => 'Dinheiro', 28 | 'valor' => 0.01 29 | ) 30 | ) 31 | ) 32 | ), 33 | 'itens' => array( 34 | array( 35 | 'cfop' => '5101', 36 | 'codigo' => '1', 37 | 'descricao' => 'Produto XYZ', 38 | 'ncm' => '49019900', 39 | 'quantidade' => 1, 40 | 'unidadeMedida' => 'UN', 41 | 'valorUnitario' => 1.39, 42 | 'impostos' => array( 43 | 'percentualAproximadoTributos' => array( 44 | 'simplificado' => array( 45 | 'percentual' => 31.45 46 | ), 47 | 'fonte' => 'IBPT' 48 | ), 49 | 'icms' => array( 50 | 'situacaoTributaria' => '102', 51 | 'origem' => 0 //0 - Nacional 52 | ) 53 | ) 54 | ) 55 | ), 56 | 'informacoesAdicionais' => 'Documento emitido por ME ou EPP optante pelo Simples Nacional. Não gera direito a crédito fiscal de IPI.' 57 | )); 58 | 59 | echo 'Sucesso!
'; 60 | echo json_encode($result); 61 | } 62 | catch(Exceptions\invalidApiKeyException $ex) { 63 | echo 'Erro de autenticação:

'; 64 | echo $ex->getMessage(); 65 | } 66 | catch(Exceptions\unauthorizedException $ex) { 67 | echo 'Acesso negado:

'; 68 | echo $ex->getMessage(); 69 | } 70 | catch(Exceptions\apiException $ex) { 71 | echo 'Erro de validação:

'; 72 | echo $ex->getMessage(); 73 | } 74 | catch(Exceptions\requestException $ex) { 75 | echo 'Erro na requisição web:

'; 76 | 77 | echo 'Requested url: ' . $ex->requestedUrl; 78 | echo '
'; 79 | echo 'Response Code: ' . $ex->getCode(); 80 | echo '
'; 81 | echo 'Message: ' . $ex->getMessage(); 82 | echo '
'; 83 | echo 'Response Body: ' . $ex->responseBody; 84 | } 85 | ?> 86 | -------------------------------------------------------------------------------- /examples/nf-e/emissao.php: -------------------------------------------------------------------------------- 1 | '' 10 | )); 11 | 12 | $idEmpresa = '484FB0C5-969E-46AD-A047-8A0DB54667B4'; 13 | 14 | try 15 | { 16 | eNotasGW::$NFeProdutoApi->emitir($empresaId, array( 17 | 'ambienteEmissao' => 'Homologacao', 18 | 'id' => '10', 19 | 'consumidorFinal' => true, 20 | 'indicadorPresencaConsumidor' => 'OperacaoPelaInternet', 21 | 'cliente' => array( 22 | 'nome' => 'Jonathan Souza', 23 | 'email' => 'jonathan.souza@mail.com', 24 | 'cpfCnpj' => '84629821708', 25 | 'endereco' => array( 26 | 'uf' => 'MG', 27 | 'cidade' => 'Belo Horizonte', 28 | 'logradouro' => 'Rua 01', 29 | 'numero' => '112', 30 | 'complemento' => 'AP 402', 31 | 'bairro' => 'Savassi', 32 | 'cep' => '32323111' 33 | ) 34 | ), 35 | 'itens' => array( 36 | array( 37 | 'cfop' => '5101', 38 | 'codigo' => '1', 39 | 'descricao' => 'Produto XYZ', 40 | 'ncm' => '49019900', 41 | 'quantidade' => 1, 42 | 'unidadeMedida' => 'UN', 43 | 'valorUnitario' => 1.39, 44 | 'impostos' => array( 45 | 'percentualAproximadoTributos' => array( 46 | 'simplificado' => array( 47 | 'percentual' => 31.45 48 | ), 49 | 'fonte' => 'IBPT' 50 | ), 51 | 'icms' => array( 52 | 'situacaoTributaria' => '102', 53 | 'origem' => 0 54 | ), 55 | 'pis' => array( 56 | 'situacaoTributaria' => '08' 57 | ), 58 | 'cofins' => array( 59 | 'situacaoTributaria' => '08' 60 | ) 61 | ) 62 | ) 63 | ), 64 | 'informacoesAdicionais' => 'Documento emitido por ME ou EPP optante pelo Simples Nacional. Não gera direito a crédito fiscal de IPI.' 65 | )); 66 | 67 | echo 'Sucesso!
'; 68 | } 69 | catch(Exceptions\invalidApiKeyException $ex) { 70 | echo 'Erro de autenticação:

'; 71 | echo $ex->getMessage(); 72 | } 73 | catch(Exceptions\unauthorizedException $ex) { 74 | echo 'Acesso negado:

'; 75 | echo $ex->getMessage(); 76 | } 77 | catch(Exceptions\apiException $ex) { 78 | echo 'Erro de validação:

'; 79 | echo $ex->getMessage(); 80 | } 81 | catch(Exceptions\requestException $ex) { 82 | echo 'Erro na requisição web:

'; 83 | 84 | echo 'Requested url: ' . $ex->requestedUrl; 85 | echo '
'; 86 | echo 'Response Code: ' . $ex->getCode(); 87 | echo '
'; 88 | echo 'Message: ' . $ex->getMessage(); 89 | echo '
'; 90 | echo 'Response Body: ' . $ex->responseBody; 91 | } 92 | ?> 93 | -------------------------------------------------------------------------------- /examples/empresa/nf-e/inserirAtualizar.php: -------------------------------------------------------------------------------- 1 | '' 11 | )); 12 | 13 | try 14 | { 15 | $dadosEmpresa = array( 16 | //informar apenas se quiser atualizar uma empresa existente 17 | //'id' => 'CB09776E-E954-4D75-BBA6-E7A99FF20100', 18 | 'cnpj' => '56308661000199', 19 | 'inscricaoEstadual' => '12345', 20 | 'inscricaoMunicipal' => null, //opcional 21 | 'razaoSocial' => 'Empresa de Teste Ltda', 22 | 'nomeFantasia' => 'Empresa de Teste', 23 | 'optanteSimplesNacional' => true, 24 | 'email' => null, 25 | 'telefoneComercial' => '3132323131', 26 | 'endereco' => array( 27 | 'uf' => 'MG', 28 | 'cidade' => 'Belo Horizonte', 29 | 'logradouro' => 'Rua 01', 30 | 'numero' => '112', 31 | 'complemento' => 'SL 102', 32 | 'bairro' => 'Savassi', 33 | 'cep' => '32323111' 34 | ), 35 | 'emissaoNFeProduto' => array( 36 | 'ambienteProducao' => array( 37 | 'sequencialNFe' => 1, 38 | 'serieNFe' => '2' 39 | ), 40 | 'ambienteHomologacao' => array( 41 | 'sequencialNFe' => 1, 42 | 'serieNFe' => '2' 43 | ) 44 | ) 45 | ); 46 | 47 | $result = eNotasGW::$EmpresaApi->inserirAtualizar($dadosEmpresa); 48 | $empresaId = $result->empresaId; 49 | 50 | echo 'empresa inserida com sucesso!'; 51 | echo '
ID: ' . $empresaId; 52 | echo '
'; 53 | echo '
'; 54 | 55 | echo 'inserindo certificado digital...

'; 56 | 57 | $arquivoPfxOuP12 = fileParameter::fromPath('{certificate file path}', 58 | 'application/x-pkcs12', '{file name}'); 59 | $senhaDoArquivo = '{senha do arquivo .pfx ou .p12}'; 60 | 61 | eNotasGW::$EmpresaApi->atualizarCertificado($empresaId, $arquivoPfxOuP12, $senhaDoArquivo); 62 | echo '
Certificado incluído com sucesso!'; 63 | } 64 | catch(Exceptions\invalidApiKeyException $ex) { 65 | echo 'Erro de autenticação:

'; 66 | echo $ex->getMessage(); 67 | } 68 | catch(Exceptions\unauthorizedException $ex) { 69 | echo 'Acesso negado:

'; 70 | echo $ex->getMessage(); 71 | } 72 | catch(Exceptions\apiException $ex) { 73 | echo 'Erro de validação:

'; 74 | echo $ex->getMessage(); 75 | } 76 | catch(Exceptions\requestException $ex) { 77 | echo 'Erro na requisição web:

'; 78 | 79 | echo 'Requested url: ' . $ex->requestedUrl; 80 | echo '
'; 81 | echo 'Response Code: ' . $ex->getCode(); 82 | echo '
'; 83 | echo 'Message: ' . $ex->getMessage(); 84 | echo '
'; 85 | echo 'Response Body: ' . $ex->responseBody; 86 | } 87 | ?> 88 | -------------------------------------------------------------------------------- /examples/empresa/nfc-e/inserirAtualizar.php: -------------------------------------------------------------------------------- 1 | '' 11 | )); 12 | 13 | try 14 | { 15 | $dadosEmpresa = array( 16 | //informar apenas se quiser atualizar uma empresa existente 17 | //'id' => 'CB09776E-E954-4D75-BBA6-E7A99FF20100', 18 | 'cnpj' => '56308661000199', 19 | 'inscricaoEstadual' => '12345', 20 | 'inscricaoMunicipal' => null, //opcional 21 | 'razaoSocial' => 'Empresa de Teste Ltda', 22 | 'nomeFantasia' => 'Empresa de Teste', 23 | 'optanteSimplesNacional' => true, 24 | 'email' => null, 25 | 'telefoneComercial' => '3132323131', 26 | 'endereco' => array( 27 | 'uf' => 'RJ', 28 | 'cidade' => 'Rio de Janeiro', 29 | 'logradouro' => 'Rua 01', 30 | 'numero' => '112', 31 | 'complemento' => 'SL 102', 32 | 'bairro' => 'Savassi', 33 | 'cep' => '32323111' 34 | ), 35 | 'emissaoNFeConsumidor' => array( 36 | 'ambienteProducao' => array( 37 | 'sequencialNFe' => 1, 38 | 'serieNFe' => '2', 39 | 'csc' => array( 40 | 'id' => '000001', //id do Código de Segurança do Contribuiente (CSC) necessário para emsisão de NFC-e 41 | 'codigo' => '800FA97D5C3F4219A89DCE3FCE813A6F' //Código de Segurança do Contribuiente (CSC) necessário para emsisão de NFC-e 42 | ) 43 | ), 44 | 'ambienteHomologacao' => array( 45 | 'sequencialNFe' => 1, 46 | 'serieNFe' => '2' 47 | ) 48 | ) 49 | ); 50 | 51 | $result = eNotasGW::$EmpresaApi->inserirAtualizar($dadosEmpresa); 52 | $empresaId = $result->empresaId; 53 | 54 | echo 'empresa inserida com sucesso!'; 55 | echo '
ID: ' . $empresaId; 56 | echo '
'; 57 | echo '
'; 58 | 59 | echo 'inserindo certificado digital...

'; 60 | 61 | $arquivoPfxOuP12 = fileParameter::fromPath('{certificate file path}', 62 | 'application/x-pkcs12', '{file name}'); 63 | $senhaDoArquivo = '{senha do arquivo .pfx ou .p12}'; 64 | 65 | eNotasGW::$EmpresaApi->atualizarCertificado($empresaId, $arquivoPfxOuP12, $senhaDoArquivo); 66 | echo '
Certificado incluído com sucesso!'; 67 | } 68 | catch(Exceptions\invalidApiKeyException $ex) { 69 | echo 'Erro de autenticação:

'; 70 | echo $ex->getMessage(); 71 | } 72 | catch(Exceptions\unauthorizedException $ex) { 73 | echo 'Acesso negado:

'; 74 | echo $ex->getMessage(); 75 | } 76 | catch(Exceptions\apiException $ex) { 77 | echo 'Erro de validação:

'; 78 | echo $ex->getMessage(); 79 | } 80 | catch(Exceptions\requestException $ex) { 81 | echo 'Erro na requisição web:

'; 82 | 83 | echo 'Requested url: ' . $ex->requestedUrl; 84 | echo '
'; 85 | echo 'Response Code: ' . $ex->getCode(); 86 | echo '
'; 87 | echo 'Message: ' . $ex->getMessage(); 88 | echo '
'; 89 | echo 'Response Body: ' . $ex->responseBody; 90 | } 91 | ?> 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # eNotas GW PHP client v2 2 | 3 | 4 | ### Instalação 5 | 6 | ```bash 7 | composer require enotas/php-client-v2 8 | ``` 9 | 10 | ### Configuração 11 | 12 | ```php 13 | eNotasGW::configure(array( 14 | 'apiKey' => '' 15 | )); 16 | ``` 17 | 18 | ### Emitindo uma nota fiscal de serviço (NFS-e) 19 | Para emitir NFS-e utilize a versão a API v1 (link abaixo) 20 | 21 | https://github.com/eNotasGW/php-client 22 | 23 | ### Emitindo uma nota fiscal de produto (NF-e) 24 | ```php 25 | $idEmpresa = '484FB0C5-969E-46AD-A047-8A0DB54667B4'; 26 | 27 | eNotasGW::$NFeProdutoApi->emitir($idEmpresa, array( 28 | // identificador único da requisição de emissão de nota fiscal 29 | // (normalmente será preenchido com o id único do registro no sistema de origem) 30 | 'id' => '5', 31 | 'ambienteEmissao' => 'Homologacao', //'Producao' ou 'Homologacao' 32 | 'consumidorFinal' => true, 33 | 'indicadorPresencaConsumidor' => 'OperacaoPelaInternet', 34 | 35 | 'cliente' => array( 36 | 'nome' => 'Nome Cliente', 37 | 'email' => 'cliente@mail.com', 38 | 'cpfCnpj' => '23857396237', 39 | 'endereco' => array( 40 | 'uf' => 'MG', 41 | 'cidade' => 'Belo Horizonte', 42 | 'logradouro' => 'Rua 01', 43 | 'numero' => '112', 44 | 'complemento' => 'AP 402', 45 | 'bairro' => 'Savassi', 46 | 'cep' => '32323111' 47 | ) 48 | ), 49 | 'itens' => array( 50 | array( 51 | 'cfop' => '5101', 52 | 'codigo' => '1', 53 | 'descricao' => 'Produto XYZ', 54 | 'ncm' => '49019900', 55 | 'quantidade' => 1, 56 | 'unidadeMedida' => 'UN', 57 | 'valorUnitario' => 1.39, 58 | 'impostos' => array( 59 | 'percentualAproximadoTributos' => array( 60 | 'simplificado' => array( 61 | 'percentual' => 31.45 62 | ), 63 | 'fonte' => 'IBPT' 64 | ), 65 | 'icms' => array( 66 | 'situacaoTributaria' => '102', 67 | 'origem' => 0 //0 - Nacional 68 | ), 69 | 'pis' => array( 70 | 'situacaoTributaria' => '08' 71 | ), 72 | 'cofins' => array( 73 | 'situacaoTributaria' => '08' 74 | ) 75 | ) 76 | ) 77 | ), 78 | 'informacoesAdicionais' => 'Documento emitido por ME ou EPP optante pelo Simples Nacional. Não gera direito a crédito fiscal de IPI.' 79 | )); 80 | ``` 81 | 82 | ### Emitindo uma nota fiscal de consumidor (NFC-e) 83 | ```php 84 | $idEmpresa = '484FB0C5-969E-46AD-A047-8A0DB54667B4'; 85 | 86 | $result = eNotasGW::$NFeConsumidorApi->emitir($idEmpresa, array( 87 | // identificador único da requisição de emissão de nota fiscal 88 | // (normalmente será preenchido com o id único do registro no sistema de origem) 89 | 'id' => '5', 90 | 'ambienteEmissao' => 'Homologacao', //'Producao' ou 'Homologacao' 91 | 'pedido' => array( 92 | 'presencaConsumidor' => 'OperacaoPresencial', 93 | 'pagamento' => array( 94 | 'tipo' => 'PagamentoAVista', 95 | 'formas' => array( 96 | array( 97 | 'tipo' => 'Dinheiro', 98 | 'valor' => 0.01 99 | ) 100 | ) 101 | ) 102 | ), 103 | 104 | 'itens' => array( 105 | array( 106 | 'cfop' => '5101', 107 | 'codigo' => '1', 108 | 'descricao' => 'Produto XYZ', 109 | 'ncm' => '49019900', 110 | 'quantidade' => 1, 111 | 'unidadeMedida' => 'UN', 112 | 'valorUnitario' => 1.39, 113 | 'impostos' => array( 114 | 'percentualAproximadoTributos' => array( 115 | 'simplificado' => array( 116 | 'percentual' => 31.45 117 | ), 118 | 'fonte' => 'IBPT' 119 | ), 120 | 'icms' => array( 121 | 'situacaoTributaria' => '102', 122 | 'origem' => 0 //0 - Nacional 123 | ) 124 | ) 125 | ) 126 | ), 127 | 'informacoesAdicionais' => 'Documento emitido por ME ou EPP optante pelo Simples Nacional. Não gera direito a crédito fiscal de IPI.' 128 | )); 129 | ``` 130 | -------------------------------------------------------------------------------- /src/eNotasGW.php: -------------------------------------------------------------------------------- 1 | new formatters\jsonFormatter(), 56 | 'multipart/form-data' => new formatters\formDataFormatter() 57 | ); 58 | 59 | if(!isset($config->apiKey)) { 60 | throw new Exception('A api key deve ser definida no método configure.'); 61 | } 62 | 63 | self::$_apiKey = $config->apiKey; 64 | 65 | if(isset($config->baseUrl)) { 66 | self::$_baseUrl = $config->baseUrl; 67 | } 68 | 69 | if(isset($config->version)) { 70 | self::$_version = $config->version; 71 | } 72 | 73 | if(isset($config->defaultContentType)) { 74 | self::$_defaultContentType = $config->defaultContentType; 75 | } 76 | 77 | if(isset($config->_trustedCAListPath)) { 78 | self::$_trustedCAListPath = $config->_trustedCAListPath; 79 | } 80 | else { 81 | self::$_trustedCAListPath = dirname(__FILE__) . '/files/ca-bundle.crt'; 82 | } 83 | 84 | self::$_versionedBaseUrl = self::$_baseUrl . '/v' . self::$_version; 85 | 86 | self::init(); 87 | } 88 | 89 | public static function getMediaFormatter($contentType) { 90 | $contentType = explode(';', $contentType); 91 | 92 | return self::$_formmaters[$contentType[0]]; 93 | } 94 | 95 | private static function init() { 96 | self::$_proxy = self::createProxy(); 97 | self::$EmpresaApi = new api\empresaApi(self::$_proxy); 98 | self::$NFeServicoApi = new api\nfeServicoApi(self::$_proxy); 99 | self::$NFeProdutoApi = new api\nfeProdutoApi(self::$_proxy); 100 | self::$NFeConsumidorApi = new api\nfeConsumidorApi(self::$_proxy); 101 | self::$PrefeituraApi = new api\prefeituraApi(self::$_proxy); 102 | self::$ServicosMunicipaisApi = new api\servicosMunicipaisApi(self::$_proxy); 103 | } 104 | 105 | private static function createProxy() { 106 | return new proxy\curlProxy(array( 107 | 'baseUrl' => self::$_versionedBaseUrl, 108 | 'apiKey' => self::$_apiKey, 109 | 'defaultContentType' => self::$_defaultContentType, 110 | 'trustedCAListPath' => self::$_trustedCAListPath 111 | )); 112 | } 113 | } 114 | ?> 115 | -------------------------------------------------------------------------------- /src/proxy/proxyBase.php: -------------------------------------------------------------------------------- 1 | executionCtx = (object)$executionCtx; 12 | } 13 | 14 | /** 15 | * Perform a request to the specified operation 16 | * @param array the operation info. 17 | * 18 | * For example: 19 | * 20 | * array( 21 | * 'path' => '/empresa/{empresaId}/certificadoDigital', 22 | * 'contentType' => 'multipart/form-data', 23 | * 'parameters' = array( 24 | * path => array( 25 | * 'empresaId' => '{24234-42342423-42442-43423}' 26 | * ), 27 | * form = array( 28 | * 'certificado' => $certificateRawData, 29 | * 'senha' => $certificatePassword 30 | * ) 31 | * ); 32 | * 33 | * @return $response 34 | */ 35 | public function doRequest($operation) { 36 | $operation = (object)$operation; 37 | $executionCtx = $this->executionCtx; 38 | $decodeResponse = (isset($operation->decodeResponse) ? $operation->decodeResponse : TRUE); 39 | 40 | $request = new \eNotasGW\Api\request(); 41 | $request->url = $this->buildUrl($operation); 42 | 43 | if(!empty($operation->method)) { 44 | $request->method = $operation->method; 45 | } 46 | 47 | $request->headers = $this->getDefaultHeaders($operation); 48 | $request->contentType = (isset($operation->contentType) ? $operation->contentType : $executionCtx->defaultContentType); 49 | 50 | $this->appendParameters($request, $operation->parameters); 51 | $response = $this->sendRequest($request); 52 | 53 | if($response->code != 200) { 54 | if($response->isEmpty() || $response->code == 404) { 55 | throw new Exceptions\requestException($response->code, $response->faultMessage, 56 | $request->url, $response->body); 57 | } 58 | else { 59 | $errors = $response->getResponseData(); 60 | 61 | switch($response->code) 62 | { 63 | case 401: 64 | throw new Exceptions\invalidApiKeyException($response->code, $errors); 65 | case 403: 66 | throw new Exceptions\unauthorizedException($response->code, $errors); 67 | default: 68 | throw new Exceptions\apiException($response->code, $errors); 69 | } 70 | } 71 | } 72 | 73 | if($decodeResponse) { 74 | return $response->getResponseData(); 75 | } 76 | 77 | return $response->body; 78 | } 79 | 80 | abstract protected function sendRequest($request); 81 | 82 | private function getDefaultHeaders($operation) { 83 | $executionCtx = $this->executionCtx; 84 | 85 | $headers = array( 86 | 'Accept: ' . $executionCtx->defaultContentType, 87 | 'Authorization: Basic ' . $executionCtx->apiKey 88 | ); 89 | 90 | return $headers; 91 | } 92 | 93 | private function appendParameters($request, $params) { 94 | if(!empty($params['body'])) { 95 | $request->parameters = $params['body']; 96 | } 97 | else if(!empty($params['form'])) { 98 | $request->parameters = $params['form']; 99 | //force request to be a form-data 100 | $request->contentType = 'multipart/form-data'; 101 | } 102 | } 103 | 104 | private function buildUrl($operation) { 105 | $path = $operation->path; 106 | $params = $operation->parameters; 107 | 108 | if($params !== FALSE) { 109 | if(!empty($params['path'])) { 110 | $pathParams = $params['path']; 111 | 112 | foreach($pathParams as $name => $value) { 113 | $path = str_replace('{' . $name . '}', rawurlencode($value), $path); 114 | } 115 | } 116 | 117 | if(!empty($params['query'])) { 118 | $path .= '?' . http_build_query($params['query']); 119 | } 120 | } 121 | 122 | return $this->executionCtx->baseUrl . $path; 123 | } 124 | } 125 | ?> 126 | -------------------------------------------------------------------------------- /examples/empresa/nfs-e/inserirAtualizar.php: -------------------------------------------------------------------------------- 1 | '' 24 | )); 25 | 26 | try 27 | { 28 | $codigoIbgeCidade = 3106200; 29 | $caracteristicasPrefeitura = eNotasGW::$PrefeituraApi->consultar($codigoIbgeCidade); 30 | 31 | $dadosEmpresa = array( 32 | //'id' => 'CB09776E-E954-4D75-BBA6-E7A99FF20100', //informar apenas se quiser atualizar uma empresa existente 33 | 'cnpj' => '56308661000199', //sem formatação 34 | 'inscricaoMunicipal' => '12345', 35 | 'inscricaoEstadual' => null, 36 | 'razaoSocial' => 'Empresa de Teste Ltda', 37 | 'nomeFantasia' => 'Empresa de Teste', 38 | 'optanteSimplesNacional' => true, 39 | 'email' => null, 40 | 'telefoneComercial' => '3132323131', 41 | 'endereco' => array( 42 | 'uf' => 'MG', 43 | 'cidade' => 'Belo Horizonte', 44 | 'logradouro' => 'Rua 01', 45 | 'numero' => '112', 46 | 'complemento' => 'SL 102', 47 | 'bairro' => 'Savassi', 48 | 'cep' => '32323111' 49 | ), 50 | 'emissaNFeServico' => array( 51 | 'regimeEspecialTributacao' => '0', //A lista de valores possíveis deve ser obtida pela api de caraterísticas da prefeitura 52 | 'codigoServicoMunicipal' => '181309901', //código do serviço municipal padrão para emissão de NFS-e 53 | 'descricaoServico' => 'SERVICO DE SERIGRAFIA / SILK-SCREEN', //Descrição do serviço municipal padrão para emissão de NFS-e (utilizado apenas na impressão da NFS-e) 54 | 55 | 'ambienteProducao' => array( 56 | 'sequencialNFe' => 1, 57 | 'serieNFe' => '2', 58 | 'sequencialLoteNFe' => 1 59 | ), 60 | 'ambienteHomologacao' => array( 61 | 'sequencialNFe' => 1, 62 | 'serieNFe' => '2', 63 | 'sequencialLoteNFe' => 1 64 | ) 65 | ) 66 | ); 67 | 68 | if($caracteristicasPrefeitura->usaCNAE) { 69 | $dadosEmpresa->cnae = '1813099'; 70 | } 71 | 72 | if($caracteristicasPrefeitura->usaItemListaServico) { 73 | $dadosEmpresa->itemListaServicoLC116 = '13.05'; 74 | } 75 | 76 | $configProd = $dadosEmpresa['emissaNFeServico']['ambienteProducao']; 77 | $configHomologa = $dadosEmpresa['emissaNFeServico']['ambienteHomologacao']; 78 | 79 | if($caracteristicasPrefeitura->tipoAutenticacao == tipoAutenticacao::UsuarioESenha) { 80 | $configProd['usuarioAcessoProvedor'] = '[usuario]'; 81 | $configProd['senhaAcessoProvedor'] = '[senha]'; 82 | 83 | //opcional, preencher apenas se for emitir em ambiente de homologação 84 | $configHomologa['usuarioAcessoProvedor'] = '[usuario]'; 85 | $configHomologa['senhaAcessoProvedor'] = '[senha]'; 86 | } 87 | else if($caracteristicasPrefeitura->tipoAutenticacao == tipoAutenticacao::Token) { 88 | $configProd['tokenAcessoProvedor'] = '[token]'; 89 | 90 | //opcional, preencher apenas se for emitir em ambiente de homologação 91 | $configProd['tokenAcessoProvedor'] = '[token]'; 92 | } 93 | 94 | $result = eNotasGW::$EmpresaApi->inserirAtualizar($dadosEmpresa); 95 | $empresaId = $result->empresaId; 96 | 97 | echo 'empresa inserida com sucesso!'; 98 | echo '
ID: ' . $empresaId; 99 | echo '
'; 100 | echo '
'; 101 | 102 | //Necessita de certificado digital para autenticação ou assinatura da nota? 103 | if($caracteristicasPrefeitura->assinaturaDigital == tipoAssinaturaDigital::Obrigatorio 104 | || $caracteristicasPrefeitura->tipoAutenticacao == tipoAutenticacao::Certificado) { 105 | 106 | echo 'inserindo certificado digital...

'; 107 | 108 | $arquivoPfxOuP12 = fileParameter::fromPath('{certificate file path}', 109 | 'application/x-pkcs12', '{file name}'); 110 | $senhaDoArquivo = '{senha do arquivo .pfx ou .p12}'; 111 | 112 | eNotasGW::$EmpresaApi->atualizarCertificado($empresaId, $arquivoPfxOuP12, $senhaDoArquivo); 113 | echo '
Certificado incluído com sucesso!'; 114 | } 115 | } 116 | catch(Exceptions\invalidApiKeyException $ex) { 117 | echo 'Erro de autenticação:

'; 118 | echo $ex->getMessage(); 119 | } 120 | catch(Exceptions\unauthorizedException $ex) { 121 | echo 'Acesso negado:

'; 122 | echo $ex->getMessage(); 123 | } 124 | catch(Exceptions\apiException $ex) { 125 | echo 'Erro de validação:

'; 126 | echo $ex->getMessage(); 127 | } 128 | catch(Exceptions\requestException $ex) { 129 | echo 'Erro na requisição web:

'; 130 | 131 | echo 'Requested url: ' . $ex->requestedUrl; 132 | echo '
'; 133 | echo 'Response Code: ' . $ex->getCode(); 134 | echo '
'; 135 | echo 'Message: ' . $ex->getMessage(); 136 | echo '
'; 137 | echo 'Response Body: ' . $ex->responseBody; 138 | } 139 | ?> 140 | -------------------------------------------------------------------------------- /src/nfeApiBase.php: -------------------------------------------------------------------------------- 1 | tipoNF = $tipoNF; 10 | } 11 | 12 | /** 13 | * Emite uma Nota Fiscal 14 | * 15 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 16 | * @param mixed $dadosNFe dados da NFe a ser emitida 17 | */ 18 | public function emitir($idEmpresa, $dadosNFe) { 19 | $result = $this->callOperation(array( 20 | 'method' => 'POST', 21 | 'path' => '/empresas/{empresaId}/{tipoNF}', 22 | 'parameters' => array( 23 | 'path' => array( 24 | 'empresaId' => $idEmpresa, 25 | 'tipoNF' => $this->tipoNF 26 | ), 27 | 'body' => $dadosNFe 28 | ) 29 | )); 30 | 31 | return $result; 32 | } 33 | 34 | /** 35 | * Cancela uma determinada Nota Fiscal 36 | * @param string $nfeId Identificador Único da Nota Fiscal 37 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 38 | */ 39 | public function cancelar($idEmpresa, $id) { 40 | $result = $this->callOperation(array( 41 | 'method' => 'DELETE', 42 | 'path' => '/empresas/{empresaId}/{tipoNF}/{id}', 43 | 'parameters' => array( 44 | 'path' => array( 45 | 'empresaId' => $idEmpresa, 46 | 'tipoNF' => $this->tipoNF, 47 | 'id' => $id 48 | ) 49 | ) 50 | )); 51 | 52 | return $result; 53 | } 54 | 55 | /** 56 | * Consulta uma Nota Fiscal pelo Identificador Único 57 | * 58 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 59 | * @param string $nfeId Identificador Único da Nota Fiscal 60 | * @return mixed $dadosNFe retorna os dados da nota como um array 61 | */ 62 | public function consultar($idEmpresa, $nfeId) { 63 | return $this->callOperation(array( 64 | 'path' => '/empresas/{empresaId}/{tipoNF}/{id}', 65 | 'parameters' => array( 66 | 'path' => array( 67 | 'empresaId' => $idEmpresa, 68 | 'tipoNF' => $this->tipoNF, 69 | 'id' => $nfeId 70 | ) 71 | ) 72 | )); 73 | } 74 | 75 | /** 76 | * Consulta notas fiscais emitidas em um determinado período 77 | * 78 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 79 | * @param int $pageNumber numero da página no qual a pesquisa será feita 80 | * @param int $pageSize quantidade de registros por página 81 | * @param string $dataInicial data inicial para pesquisa 82 | * @param string $dataFinal data final para pesquisa 83 | * @return searchResult $listaNFe retorna uma lista contendo os registros encontrados na pesquisa 84 | */ 85 | public function consultarPorPeriodo($idEmpresa, $pageNumber, $pageSize, $dataInicial, $dataFinal) { 86 | $dataInicial = eNotasGWHelper::formatDateTime($dataInicial); 87 | $dataFinal = eNotasGWHelper::formatDateTime($dataFinal); 88 | 89 | return $this->callOperation(array( 90 | 'path' => '/empresas/{empresaId}/{tipoNF}', 91 | 'parameters' => array( 92 | 'path' => array( 93 | 'empresaId' => $idEmpresa, 94 | 'tipoNF' => $this->tipoNF 95 | ), 96 | 'query' => array( 97 | 'pageNumber' => $pageNumber, 98 | 'pageSize' => $pageSize, 99 | 'filter' => "dataCriacao ge '{$dataInicial}' and dataCriacao le '{$dataFinal}'" 100 | ) 101 | ) 102 | )); 103 | } 104 | 105 | /** 106 | * Download do xml de uma Nota Fiscal identificada pelo seu Identificador Único 107 | * 108 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 109 | * @param string $id Identificador Único da Nota Fiscal 110 | * @return string xml da nota fiscal 111 | */ 112 | public function downloadXml($idEmpresa, $id) { 113 | return $this->callOperation(array( 114 | 'path' => '/empresas/{empresaId}/{tipoNF}/{id}/xml', 115 | 'decodeResponse' => FALSE, 116 | 'parameters' => array( 117 | 'path' => array( 118 | 'empresaId' => $idEmpresa, 119 | 'tipoNF' => $this->tipoNF, 120 | 'id' => $id 121 | ) 122 | ) 123 | )); 124 | } 125 | 126 | /** 127 | * Download do pdf de uma Nota Fiscal identificada pelo seu id único 128 | * 129 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 130 | * @param string $id Identificador Único da Nota Fiscal 131 | * @return os bytes do arquivo pdf 132 | */ 133 | public function downloadPdf($idEmpresa, $id) { 134 | return $this->callOperation(array( 135 | 'path' => '/empresas/{empresaId}/{tipoNF}/{id}/pdf', 136 | 'decodeResponse' => FALSE, 137 | 'parameters' => array( 138 | 'path' => array( 139 | 'empresaId' => $idEmpresa, 140 | 'tipoNF' => $this->tipoNF, 141 | 'id' => $id 142 | ) 143 | ) 144 | )); 145 | } 146 | 147 | /** 148 | * Inutiliza uma faixa de numeraço da NF-e / NFC-e 149 | * 150 | * @param string $idEmpresa id da empresa para a qual a inutilização será realizada 151 | * @param mixed $dadosInutilizacao dados da inutilizacao a ser realizada 152 | * 153 | */ 154 | public function inutilizarNumeracao($idEmpresa, $dadosInutilizacao) { 155 | $result = $this->callOperation(array( 156 | 'method' => 'POST', 157 | 'path' => '/empresas/{empresaId}/{tipoNF}/inutilizar', 158 | 'parameters' => array( 159 | 'path' => array( 160 | 'empresaId' => $idEmpresa, 161 | 'tipoNF' => $this->tipoNF 162 | ), 163 | 'body' => $dadosInutilizacao 164 | ) 165 | )); 166 | 167 | return $result; 168 | } 169 | 170 | /** 171 | * Consulta uma Inutilização pelo Identificador Único 172 | * 173 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 174 | * @param string $idInutilizacao Identificador Único da inutilização 175 | * @return mixed $dadosInutilizacao retorna os dados da inutilização como um array 176 | */ 177 | public function consultarInutilizacao($idEmpresa, $idInutilizacao) { 178 | return $this->callOperation(array( 179 | 'path' => '/empresas/{empresaId}/{tipoNF}/inutilizar/{id}', 180 | 'parameters' => array( 181 | 'path' => array( 182 | 'empresaId' => $idEmpresa, 183 | 'tipoNF' => $this->tipoNF, 184 | 'id' => $idInutilizacao 185 | ) 186 | ) 187 | )); 188 | } 189 | 190 | /** 191 | * Download do xml de uma Inutilização identificada pelo seu Identificador Único 192 | * 193 | * @param string $idEmpresa id da empresa para a qual a nota será emitida 194 | * @param string $id Identificador Único da Inutilização 195 | * @return string xml da inutilização 196 | */ 197 | public function downloadXmlInutilizacao($idEmpresa, $idInutilizacao) { 198 | return $this->callOperation(array( 199 | 'path' => '/empresas/{empresaId}/{tipoNF}/inutilizar/{id}/xml', 200 | 'parameters' => array( 201 | 'path' => array( 202 | 'empresaId' => $idEmpresa, 203 | 'tipoNF' => $this->tipoNF, 204 | 'id' => $idInutilizacao 205 | ) 206 | ) 207 | )); 208 | } 209 | } 210 | ?> 211 | --------------------------------------------------------------------------------