Last active
November 3, 2021 15:02
-
-
Save sinetoami/b43623cb82bb583239395da5c31dd757 to your computer and use it in GitHub Desktop.
POC de envio de RecepcaoNFSe para STM de Caxias/MA
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
import axios from "axios"; | |
const url = "http://stm.caxias.d2ti.com.br/wsnfselote/RecepcaoNFSePort?wsdl"; | |
const axiosConfig = { | |
headers: { | |
"Cache-Control": "no-cache", | |
"Accept-Encoding": "gzip,deflate", | |
"Content-Type": "text/xml;charset=UTF-8", | |
SOAPAction: "", | |
}, | |
}; | |
function escapeXml(text) { | |
return String(text).replace(/(['"<>&'])(\w+;)?/g, (match, char, escaped) => { | |
if (escaped) return match; | |
switch (char) { | |
case "'": | |
return """; | |
case '"': | |
return "'"; | |
case "<": | |
return "<"; | |
case ">": | |
return ">"; | |
case "&": | |
return "&"; | |
} | |
}); | |
} | |
try { | |
const cabecalho = ` | |
<cabecalhoNfseLote xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.ctaconsult.com/nfse"> | |
<versao>1.00</versao> | |
<ambiente>2</ambiente> | |
</cabecalhoNfseLote> | |
`; | |
const dados = ` | |
<nfseLote xmlns="http://www.ctaconsult.com/nfse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<codigoMunicipio>757</codigoMunicipio> | |
<dtEmissao>2021-03-07T00:00:00</dtEmissao> | |
<notaIntermediada>1</notaIntermediada> | |
<autenticacao> | |
<token>1xxxxxxxxx990567D3348120D993A58F</token> | |
</autenticacao> | |
<prestador> | |
<tipoPessoa>2</tipoPessoa> | |
<cnpj>99999999999999</cnpj> | |
<inscricaoMunicipal>999999</inscricaoMunicipal> | |
<razaoSocial>EMPRESA XXX LTDA</razaoSocial> | |
<endereco> | |
<logradouro>RUA ALAGOAS </logradouro> | |
<complemento>LETRA</complemento> | |
<bairro>JUCARA</bairro> | |
<cep>65919170</cep> | |
<codigoMunipio>757</codigoMunipio> | |
<descricaoMunicipio>CAXIAS</descricaoMunicipio> | |
<codigoEstado>MA</codigoEstado> | |
<descricaoEstado>MA</descricaoEstado> | |
</endereco> | |
<email>[email protected]</email> | |
<telefoneDdd>98</telefoneDdd> | |
<telefoneNumero>91991234</telefoneNumero> | |
</prestador> | |
<tomador> | |
<tomadorIdentificado>1</tomadorIdentificado> | |
<tipoPessoa>2</tipoPessoa> | |
<cnpj>12345639000183</cnpj> | |
<razaoSocial>ENGENHARIA LTDA</razaoSocial> | |
<endereco> | |
<logradouro>R SILVIA</logradouro> | |
<complemento>01</complemento> | |
<bairro>PIEDADE</bairro> | |
<cep>54400220</cep> | |
<codigoMunipio>2457</codigoMunipio> | |
<descricaoMunicipio>JABOATAO DOS GUARARAPES</descricaoMunicipio> | |
<codigoEstado>26</codigoEstado> | |
<descricaoEstado>PERNAMBUCO</descricaoEstado> | |
</endereco> | |
</tomador> | |
<atividadeExecutada> | |
<codigoServico>0901</codigoServico> | |
<descricaoServico>HOSPEDAGEM DE QUALQUER NATUREZA EM HOTEIS APART SERVICE CONDOMINIAIS FLAT APART HOTEIS HOTEIS RESIDENCIA RESIDENCE SERVICE SUITE SERVICE HOTELARIA MARITIMA MOTEIS PENSOES E CONGENERES; OCUPACAO POR TEMPORADA COM FORNECIMENTO DE SERVICO (O VALOR DA ALIMENTACAO E GORJETA QUANDO INCLUIDO NO PRECO DA DIARIA FICA SUJEITO AO IMPOSTO SOBRE SERVICOS)</descricaoServico> | |
<codigoAtividade>551080100</codigoAtividade> | |
<descricaoAtividade>HOTEIS</descricaoAtividade> | |
<localPrestacao> | |
<codigoEstado>MA</codigoEstado> | |
<descricaoEstado>MA</descricaoEstado> | |
<codigoMunipio>757</codigoMunipio> | |
<descricaoMunicipio>IMPERATRIZ</descricaoMunicipio> | |
</localPrestacao> | |
<tipoTributacao>4</tipoTributacao> | |
<tipoRecolhimento>1</tipoRecolhimento> | |
<aliquota>5</aliquota> | |
</atividadeExecutada> | |
<deducoes> | |
<tipo>1</tipo> | |
</deducoes> | |
<detalhamentoNota> | |
<descricaoNota> | |
DIARIAS -R$ 2.474,08 | |
VISA R$ 2.474,08 | |
HOSPEDE: SANTOS, DOC: 12345678902 | |
da União, 35, CEP: 65068300, São Luís, MA, BRASIL | |
| |
RPS: 2630348 | |
NOTA CM: 9777 | |
RESERVA: 23993650 | |
CHECKIN: 21/02/2021 | |
CHECKOUT: 07/03/2021 | |
| |
Trib aprox R$:332,76 Fed, 0,00 Est e 123,70 Mun | |
Fonte: IBPT/FECOMERCIO MA 02C353 | |
</descricaoNota> | |
<itensServico> | |
<item nItem="1"> | |
<tributavel>1</tributavel> | |
<descricao>SERVIÇOS PRESTADOS</descricao> | |
<quantidade>1</quantidade> | |
<valorUnitario>2474.08</valorUnitario> | |
<valorTotal>2474.08</valorTotal> | |
</item> | |
</itensServico> | |
<totais> | |
<valotTotalNota>2474.08</valotTotalNota> | |
<valorTotalServico>2474.08</valorTotalServico> | |
<valorTotalDeducao>0</valorTotalDeducao> | |
<valorTotalISS>123.704</valorTotalISS> | |
<valorReducaoBC>0</valorReducaoBC> | |
</totais> | |
</detalhamentoNota> | |
</nfseLote> | |
`; | |
const envelope = ` | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsn="http://wsnfselote.ctaconsult.com.br/"> | |
<soapenv:Header/> | |
<soapenv:Body> | |
<wsn:executar> | |
<arg0>${escapeXml(cabecalho)}</arg0> | |
<arg1>${escapeXml(dados)}</arg1> | |
</wsn:executar> | |
</soapenv:Body> | |
</soapenv:Envelope> | |
`; | |
// usando biblioteca 'axios' | |
const postCall = async () => { | |
const res = await axios.post(url, envelope, axiosConfig); | |
console.log( | |
res.data | |
.replace(/'/g, "'") | |
.replace(/"/g, '"') | |
.replace(/>/g, ">") | |
.replace(/</g, "<") | |
.replace(/&/g, "&") | |
); | |
}; | |
postCall(); | |
} catch (error) { | |
console.error(error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment