Skip to content

Instantly share code, notes, and snippets.

@acras
Created September 6, 2016 02:49
Show Gist options
  • Save acras/3b5be9da9f2162982d07e2a018dfc636 to your computer and use it in GitHub Desktop.
Save acras/3b5be9da9f2162982d07e2a018dfc636 to your computer and use it in GitHub Desktop.
Consulta de NFSe emitida pela API do Focus NFe em Delphi
procedure consultaNFe;
var
url, chave, valor, nomeTabela, nomePK, prefixoRef: string;
res: TStringList;
i: integer;
status: integer;
uri_sefaz, mensagem_sefaz, mensagem_status, numeroNFse: string;
separator_position: integer;
begin
url := '?token=aaOqeu3poIWHM1VksU7EzVKPsai9RxGyM' + //alterar o token pelo seu token enviado pelo suporte
'&ref=' + 'sua_ref'; //alterar sua_ref pela identificação interna da nota em seu sistema
res := TStringList.Create;
try
res.Text := Utf8ToAnsi(HTTP.Get('http://producao.acrasnfe.acras.com.br/nfse2/curitiba/consultar'
+ url));
for i := 1 to res.Count -1 do
begin
separator_position := pos(':', res[i]);
chave := Trim(copy(res[i], 1, separator_position - 1));
valor := Trim(copy(res[i], separator_position + 1, MaxInt));
if chave = 'status' then
mensagem_status := valor;
if chave = 'mensagem' then
mensagem_sefaz := valor;
if chave = 'uri' then
uri_sefaz := valor;
if chave = 'numero' then
numeroNFse := StringReplace(valor, '"', '''', [rfReplaceAll]);
end;
if mensagem_status = 'processando_autorizacao' then
MessageDlg('A nota ainda está em processamento.', mtInformation, [mbOK], 0);
if mensagem_status = 'erro_autorizacao' then
ShowMessage('A nota não foi autorizada. Motivo: ' + res.text)
if mensagem_status = 'autorizado' then
ShowMessage('Nota autorizada'+#13#10+'URL: '+
MainData.execSQL('update cobranca set statusnfse = ' +
QuotedStr(uri_sefaz) + #13#10 + 'Número: ' + numeroNFse;
if mensagem_status = 'cancelado' then
ShowMessage('O cancelamento da nota foi autorizado');
finally
free;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment