Last active
August 29, 2017 13:48
-
-
Save acras/450fe5e873462a4bc1ae to your computer and use it in GitHub Desktop.
Este exemplo de código demonstra o envio e consulta de uma NFe no sistema Focus NFe API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Você deve definir isso globalmente para sua aplicação | |
$SERVER = "http://producao.acrasnfe.acras.com.br"; | |
$TOKEN = "token_recebido_do_suporte"; | |
$nfse = array( | |
"natureza_operacao" => 'Remessa de Produtos', | |
"forma_pagamento" => 0, | |
"data_emissao" => '2013-05-31T12:00:00-03:00', | |
"data_entrada_saida" => '2015-02-03', | |
"tipo_documento" => 1, | |
"finalidade_emissao" => 1, | |
"cnpj_emitente" => '001112220001333', | |
"nome_emitente" => 'Nome do seu cliente LTDA', | |
"nome_fantasia_emitente" => 'Fantasia do Emitente', | |
"logradouro_emitente" => 'Rua Pereira Leite', | |
"numero_emitente" => '323 - cj. B12/13', | |
"bairro_emitente" => 'Sumarezinho', | |
"municipio_emitente" => 'São Paulo', | |
"uf_emitente" => 'SP', | |
"cep_emitente" => '05442000', | |
"telefone_emitente" => '011 2318-1919', | |
"inscricao_estadual_emitente" => '145662857118', | |
"nome_destinatario" => 'NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL', | |
"cnpj_destinatario" => '10812933000137', | |
"inscricao_estadual_destinatario" => 'ISENTO', | |
"telefone_destinatario" => '6132332933', | |
"logradouro_destinatario" => 'SMAS 6580 PARKSHOPPING', | |
"numero_destinatario" => '134', | |
"bairro_destinatario" => 'Zona Industrial (Guará)', | |
"municipio_destinatario" => 'Brasilia', | |
"uf_destinatario" => 'DF', | |
"pais_destinatario" => 'Brasil', | |
"cep_destinatario" => '71219900', | |
"icms_base_calculo" => '0', | |
"icms_valor_total" => '0', | |
"icms_base_calculo_st" => '0', | |
"icms_valor_total_st" => '0', | |
"icms_modalidade_base_calculo" => '0', | |
"icms_valor" => '0', | |
"valor_frete" => '0.0000', | |
"valor_seguro" => '0', | |
"valor_total" => '2241.66', | |
"valor_produtos" => '2241.66', | |
"valor_ipi" => '0', | |
"modalidade_frete" => '0', | |
"informacoes_adicionais_contribuinte" => 'Não Incidência ICMS conforme Decisão...', | |
"nome_transportador" => 'BRASPRESS TRANSPORTES URGENTES LTDA SP', | |
"cnpj_transportador" => '48740351000165', | |
"endereco_transportador" => 'RUA CORONEL MARQUES RIBEIRO, 225', | |
"municipio_transportador" => 'SÃO PAULO', | |
"uf_transportador" => 'SP', | |
"inscricao_estadual_transportador" => '116945108113', | |
"items" => array( | |
array( | |
"numero_item" => '1', | |
"codigo_produto" => '9999999' | |
"descricao" => 'Perfume Polo Black', | |
"cfop" => '6949', | |
"unidade_comercial" => 'un', | |
"quantidade_comercial" => '5000', | |
"valor_unitario_comercial" => '0.448332', | |
"valor_unitario_tributavel" => '0.448332', | |
"unidade_tributavel" => 'un', | |
"codigo_ncm" => '49111090', | |
"quantidade_tributavel" => '5000', | |
"valor_bruto" => '2241.66', | |
"icms_situacao_tributaria" => '41', | |
"icms_origem" => '0', | |
"pis_situacao_tributaria" => '07', | |
"cofins_situacao_tributaria" => '07', | |
"ipi_situacao_tributaria" => '53', | |
"ipi_codigo_enquadramento_legal" => '999' | |
) | |
), | |
"volumes" => array( | |
array( | |
"quantidade" => '2', | |
"especie" => 'Volumes', | |
"marca" => '', | |
"numero" => '', | |
"peso_bruto" => '36', | |
"peso_liquido" => '36' | |
) | |
), | |
"duplicatas" => array( | |
array( | |
"numero" => 'Pagamento a vista', | |
"data_vencimento" => '', | |
"valor" => '2241.66' | |
) | |
), | |
); | |
print("=> Teste de envio\n"); | |
$r = new HttpRequest($SERVER."/nfe2/autorizar", HttpRequest::METH_POST); | |
$r->addQueryData(array('token' => $TOKEN)); | |
# A referência é uma string que identifica univocamente uma NFSe e | |
# será usada para consultas posteriores | |
$r->addQueryData(array('ref' => '1234')); | |
$yaml = yaml_emit($nfse); | |
$r->addRawPostData($yaml); | |
try { | |
$r->send(); | |
$status = $r->getResponseCode(); | |
$body = $r->getResponseBody(); | |
print("Status = $status\n"); | |
print("Body = $body\n"); | |
} catch (HttpException $ex) { | |
echo $ex; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("=> Teste de consulta\n"); | |
# O processo de envio de NFSe é assíncrono, e pode ser necessário | |
# aguardar até que a nota seja processada | |
sleep(10); | |
$r = new HttpRequest($SERVER."/nfe2/consultar", HttpRequest::METH_GET); | |
$r->addQueryData(array('token' => $TOKEN)); | |
$r->addQueryData(array('ref' => '1234')); | |
try { | |
$r->send(); | |
$status = $r->getResponseCode(); | |
$body = $r->getResponseBody(); | |
print("Status = $status\n"); | |
print("Body = $body\n"); | |
$result = yaml_parse($body); | |
var_dump($result); | |
} catch (HttpException $ex) { | |
echo $ex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment