pytrustnfe3
Advanced tools
| import os | ||
| import suds | ||
| from lxml import etree | ||
| from pytrustnfe.client import get_authenticated_client | ||
| from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key | ||
| from pytrustnfe.xml import render_xml, sanitize_response | ||
| from .assinatura import Assinatura | ||
| def _render(certificado, method, **kwargs): | ||
| path = os.path.join(os.path.dirname(__file__), "templates") | ||
| xml_send = render_xml(path, f"{method}.xml", False, **kwargs) | ||
| signer = Assinatura(certificado.pfx, certificado.password) | ||
| xml_send = etree.fromstring(xml_send) | ||
| xml_send = signer.assina_xml(xml_send) | ||
| return xml_send | ||
| def _send(certificado, method, **kwargs): | ||
| base_url = "https://nfse.goiania.go.gov.br/ws/nfse.asmx?wsdl" | ||
| xml_send = kwargs["xml"] | ||
| cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password) | ||
| cert, key = save_cert_key(cert, key) | ||
| client = get_authenticated_client(base_url, cert, key) | ||
| try: | ||
| response = getattr(client.service, method)(xml_send) | ||
| except suds.WebFault as e: | ||
| return { | ||
| "send_xml": str(xml_send), | ||
| "received_xml": str(e.fault.faultstring), | ||
| "object": None, | ||
| } | ||
| response, obj = sanitize_response(response) | ||
| return {"send_xml": str(xml_send), "received_xml": str(response), "object": obj} | ||
| def xml_gerar_nfse(certificado, **kwargs): | ||
| """ Retorna o XML montado para ser enviado para o Webservice """ | ||
| return _render(certificado, "GerarNfse", **kwargs) | ||
| def gerar_nfse(certificado, **kwargs): | ||
| """" Gera uma NFSe de saída """ | ||
| if "xml" not in kwargs: | ||
| kwargs["xml"] = xml_gerar_nfse | ||
| return _send(certificado, "GerarNfse", **kwargs) | ||
| def consulta_nfse_por_rps(certificado, **kwargs): | ||
| """ Consulta os dados de um NFSe já emitida """ | ||
| if "xml" not in kwargs: | ||
| kwargs["xml"] = _render(certificado, "ConsultarNfseRps", **kwargs) | ||
| return _send(certificado, "ConsultarNfseRps", **kwargs) |
| from lxml import etree | ||
| from pytrustnfe.certificado import extract_cert_and_key_from_pfx | ||
| from signxml import XMLSigner, methods | ||
| from pytrustnfe.nfe.assinatura import Assinatura as _Assinatura | ||
| class Assinatura(_Assinatura): | ||
| def assina_xml(self, xml_element): | ||
| cert, key = extract_cert_and_key_from_pfx(self.arquivo, self.senha) | ||
| for element in xml_element.iter("*"): | ||
| if element.text is not None and not element.text.strip(): | ||
| element.text = None | ||
| signer = XMLSigner( | ||
| method=methods.enveloped, | ||
| signature_algorithm=u"rsa-sha1", | ||
| digest_algorithm=u"sha1", | ||
| c14n_algorithm=u"http://www.w3.org/TR/2001/REC-xml-c14n-20010315", | ||
| ) | ||
| ns = {} | ||
| ns[None] = signer.namespaces["ds"] | ||
| signer.namespaces = ns | ||
| element_signed = xml_element.find(".//{http://nfse.goiania.go.gov.br/xsd/nfse_gyn_v02.xsd}Rps") | ||
| signed_root = signer.sign( | ||
| xml_element, key=key.encode(), cert=cert.encode() | ||
| ) | ||
| signature = signed_root.find( | ||
| ".//{http://www.w3.org/2000/09/xmldsig#}Signature" | ||
| ) | ||
| if element_signed is not None and signature is not None: | ||
| parent = xml_element.getchildren()[0] | ||
| parent.append(signature) | ||
| return etree.tostring(xml_element, encoding=str) |
+3
-2
| Metadata-Version: 2.1 | ||
| Name: pytrustnfe3 | ||
| Version: 1.0.56 | ||
| Version: 1.0.57 | ||
| Summary: PyTrustNFe é uma biblioteca para envio de NF-e | ||
@@ -57,5 +57,6 @@ Home-page: https://github.com/danimaribeiro/PyTrustNFe | ||
| * **Imperial** - Petrópolis/RH | ||
| * **Goiânia** - Goiânia/GO | ||
| * [Susesu](cidades/susesu.md) - 3 cidades atendidas | ||
| * [Simpliss](cidades/simpliss.md) - 18 cidade atendidas | ||
| * [GINFES](cidaes/ginfes.md) - 79 cidades atendidas | ||
| * [GINFES](cidades/ginfes.md) - 79 cidades atendidas | ||
| * [DSF](cidades/dsf.md) - 7 cidades atendidas | ||
@@ -62,0 +63,0 @@ |
@@ -29,2 +29,3 @@ <enviNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00"> | ||
| <indPres>{{ ide.indPres }}</indPres> | ||
| <indIntermed>{{ ide.indIntermed }}</indIntermed> | ||
| <procEmi>{{ ide.procEmi }}</procEmi> | ||
@@ -31,0 +32,0 @@ <verProc>{{ ide.verProc }}</verProc> |
@@ -21,4 +21,6 @@ # -*- coding: utf-8 -*- | ||
| reference = "" | ||
| if method == "RecepcionarLoteRpsV3": | ||
| if method in ("RecepcionarLoteRpsV3", "RecepcionarLoteRpsSincronoV3"): | ||
| reference = "rps%s" % kwargs["nfse"]["lista_rps"][0]["numero"] | ||
| elif method == "CancelarNfseV3": | ||
| reference = "C%s" % kwargs["cancelamento"]["numero_nfse"] | ||
@@ -67,2 +69,12 @@ signer = Assinatura(certificado.pfx, certificado.password) | ||
| def xml_recepcionar_lote_rps_sync(certificado, **kwargs): | ||
| return _render(certificado, "RecepcionarLoteRpsSincronoV3", **kwargs) | ||
| def recepcionar_lote_rps_sync(certificado, **kwargs): | ||
| if "xml" not in kwargs: | ||
| kwargs["xml"] = xml_recepcionar_lote_rps(certificado, **kwargs) | ||
| return _send(certificado, "RecepcionarLoteRpsSincronoV3", **kwargs) | ||
| def xml_consultar_situacao_lote(certificado, **kwargs): | ||
@@ -78,6 +90,11 @@ return _render(certificado, "ConsultarSituacaoLoteRpsV3", **kwargs) | ||
| def xml_consultar_nfse_por_rps(certificado, **kwargs): | ||
| return _render(certificado, "ConsultarNfsePorRpsV3", **kwargs) | ||
| def consultar_nfse_por_rps(certificado, **kwargs): | ||
| if "xml" not in kwargs: | ||
| kwargs["xml"] = xml_consultar_nfse_por_rps(certificado, **kwargs) | ||
| return _send(certificado, "ConsultarNfsePorRpsV3", **kwargs) | ||
| def xml_consultar_lote_rps(certificado, **kwargs): | ||
@@ -92,4 +109,9 @@ return _render(certificado, "ConsultarLoteRpsV3", **kwargs) | ||
| def xml_consultar_nfse(certificado, **kwargs): | ||
| return _render(certificado, "ConsultarNfseV3", **kwargs) | ||
| def consultar_nfse(certificado, **kwargs): | ||
| if "xml" not in kwargs: | ||
| kwargs["xml"] = xml_consultar_nfse(certificado, **kwargs) | ||
| return _send(certificado, "ConsultarNfseV3", **kwargs) | ||
@@ -96,0 +118,0 @@ |
@@ -1,15 +0,14 @@ | ||
| <CancelarNfseEnvio xmlns="http://www.betha.com.br/e-nota-contribuinte-ws"> | ||
| <Pedido> | ||
| <InfPedidoCancelamento Id="1"> | ||
| <IdentificacaoNfse> | ||
| <Numero>{{ cancelamento.numero_nfse }}</Numero> | ||
| <CpfCnpj> | ||
| <Cnpj>{{ cancelamento.cnpj_prestador }}</Cnpj> | ||
| </CpfCnpj> | ||
| <InscricaoMunicipal>{{ cancelamento.inscricao_municipal }}</InscricaoMunicipal> | ||
| <CodigoMunicipio>{{ cancelamento.cidade }}</CodigoMunicipio> | ||
| </IdentificacaoNfse> | ||
| <CodigoCancelamento>{{ cancelamento.codigo_cancelamento }}</CodigoCancelamento> | ||
| </InfPedidoCancelamento> | ||
| <CancelarNfseEnvio xmlns="http://www.ginfes.com.br/servico_cancelar_nfse_envio_v03.xsd" | ||
| xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd"> | ||
| <Pedido xmlns=""> | ||
| <tipos:InfPedidoCancelamento Id="C{{ cancelamento.numero_nfse }}"> | ||
| <tipos:IdentificacaoNfse> | ||
| <tipos:Numero>{{ cancelamento.numero_nfse }}</tipos:Numero> | ||
| <tipos:Cnpj>{{ cancelamento.cnpj_prestador }}</tipos:Cnpj> | ||
| <tipos:InscricaoMunicipal>{{ cancelamento.inscricao_municipal }}</tipos:InscricaoMunicipal> | ||
| <tipos:CodigoMunicipio>{{ cancelamento.cidade }}</tipos:CodigoMunicipio> | ||
| </tipos:IdentificacaoNfse> | ||
| <tipos:CodigoCancelamento>{{ cancelamento.codigo_cancelamento }}</tipos:CodigoCancelamento> | ||
| </tipos:InfPedidoCancelamento> | ||
| </Pedido> | ||
| </CancelarNfseEnvio> |
@@ -1,13 +0,12 @@ | ||
| <ConsultarNfseRpsEnvio xmlns="http://www.betha.com.br/e-nota-contribuinte-ws"> | ||
| <ConsultarNfseRpsEnvio xmlns="http://www.ginfes.com.br/servico_consultar_nfse_rps_envio_v03.xsd" | ||
| xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd"> | ||
| <IdentificacaoRps> | ||
| <Numero>24</Numero> | ||
| <Serie>A1</Serie> | ||
| <Tipo>1</Tipo> | ||
| <tipos:Numero>{{ consulta.numero }}</tipos:Numero> | ||
| <tipos:Serie>{{ consulta.serie }}</tipos:Serie> | ||
| <tipos:Tipo>{{ consulta.tipo }}</tipos:Tipo> | ||
| </IdentificacaoRps> | ||
| <Prestador> | ||
| <CpfCnpj> | ||
| <Cnpj>45111111111100</Cnpj> | ||
| </CpfCnpj> | ||
| <InscricaoMunicipal>123498</InscricaoMunicipal> | ||
| <tipos:Cnpj>{{ consulta.cnpj_prestador }}</tipos:Cnpj> | ||
| <tipos:InscricaoMunicipal>{{ consulta.inscricao_municipal }}</tipos:InscricaoMunicipal> | ||
| </Prestador> | ||
| </ConsultarNfseRpsEnvio> |
@@ -1,8 +0,8 @@ | ||
| <ConsultarLoteRpsEnvio xmlns="http://www.betha.com.br/e-nota-contribuinte-ws"> | ||
| <ConsultarNfseEnvio xmlns="http://www.ginfes.com.br/servico_consultar_nfse_envio_v03.xsd" | ||
| xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd"> | ||
| <Prestador> | ||
| <CpfCnpj> | ||
| <Cnpj>45111111111100</Cnpj> | ||
| </CpfCnpj> | ||
| <tipos:Cnpj>{{ consulta.cnpj_prestador }}</tipos:Cnpj> | ||
| <tipos:InscricaoMunicipal>{{ consulta.inscricao_municipal }}</tipos:InscricaoMunicipal> | ||
| </Prestador> | ||
| <Protocolo>141542179222170</Protocolo> | ||
| </ConsultarLoteRpsEnvio> | ||
| <NumeroNfse>{{ consulta.numero_nfse }}</NumeroNfse> | ||
| </ConsultarNfseEnvio> |
+12
-10
@@ -16,3 +16,3 @@ pytrustnfe/Servidores.py,sha256=UMno4pLVzsMk3KhSe6BdKY4hTtCTxll1ENUOLd-Jz-c,34097 | ||
| pytrustnfe/nfe/templates/NFeDistribuicaoDFe.xml,sha256=zkXTR1ZgHdMzWbjrenN0wb088_zCF_7sX7ACRs6gRaM,389 | ||
| pytrustnfe/nfe/templates/NfeAutorizacao.xml,sha256=0lOjtCXggrK3vwE9BgUbwzppFbRgOzKpFZEIBuznXIw,51636 | ||
| pytrustnfe/nfe/templates/NfeAutorizacao.xml,sha256=R3nUxBXEDJZww6qpbMbruzBIHSuNhJ0MfLqykDF00wY,51701 | ||
| pytrustnfe/nfe/templates/NfeConsultaCadastro.xml,sha256=GK6gLNzKBn1_742j0Ey0lbfnlQRo9NiHvYx4IpQVe1A,201 | ||
@@ -64,10 +64,12 @@ pytrustnfe/nfe/templates/NfeConsultaDest.xml,sha256=AU_ufUN-aXhqy4nNtfAJnaf02pB65lLzSvj9fDiij9M,338 | ||
| pytrustnfe/nfse/floripa/templates/processar_nota.xml,sha256=1w7kdCsJL3WN8C3XhL6poDvdzld2HyooDWE79Q8lHPg,2149 | ||
| pytrustnfe/nfse/ginfes/__init__.py,sha256=nESAf9Bb_c656nqoU2fW0nf_xNjcRfylYPLG-y460-Q,3419 | ||
| pytrustnfe/nfse/ginfes/templates/CancelarNfseV3.xml,sha256=XXrLbCXFKiibUc30B30t2u5QJI07Px52MvisnXmqYLY,724 | ||
| pytrustnfe/nfse/ginfes/__init__.py,sha256=V7rUUY1xiUFfuAe7dQuLY0dg5ONeemQ9f-2Yyb58O88,4354 | ||
| pytrustnfe/nfse/ginfes/templates/CancelarNfseV3.xml,sha256=f676AqSHIMGDWYg1cdcXbXuYyZxzdW3gK3tyh9jUpxM,860 | ||
| pytrustnfe/nfse/ginfes/templates/ConsultarLoteRpsV3.xml,sha256=V_s3uCLAaPddfkA5sB9sgnrMP2reDy_AnzlpqGP_mrQ,427 | ||
| pytrustnfe/nfse/ginfes/templates/ConsultarNfsePorRpsV3.xml,sha256=q__O-xZCCbfevdjlfBye9f-KmDSx0b4QJdaowB4XxJo,407 | ||
| pytrustnfe/nfse/ginfes/templates/ConsultarNfseV3.xml,sha256=KblM-QOB_X6MsGIydGqN30rs8gkzlOsZ7437HNJi6TA,265 | ||
| pytrustnfe/nfse/ginfes/templates/ConsultarNfsePorRpsV3.xml,sha256=TLglV1vNUduON2djlCagV3vHCQ0z2O_3rud2cLET9P0,599 | ||
| pytrustnfe/nfse/ginfes/templates/ConsultarNfseV3.xml,sha256=9Tm0P2mCc5SstOJasBx_uIva4kd0nZKIl3Y_yOha_sc,426 | ||
| pytrustnfe/nfse/ginfes/templates/ConsultarSituacaoLoteRpsV3.xml,sha256=JcU0bULSQZuHW2KjKrM4Ri8uZFin99vzXEJIai8SEv4,452 | ||
| pytrustnfe/nfse/ginfes/templates/RecepcionarLoteRpsV3.xml,sha256=mSwtwNrH5qgHs6jNboQWn0WVXvr2pGbsadv7_OFSCeA,718 | ||
| pytrustnfe/nfse/ginfes/templates/Rps.xml,sha256=vNfzp7KLNvNl8DICqrze46dyL6-NpLEen7eZJKld5PU,4583 | ||
| pytrustnfe/nfse/goiania/__init__.py,sha256=fm9W899KEBiMQ0EVdkE2XYwHtkGfBHUWuex9j7va2dA,1965 | ||
| pytrustnfe/nfse/goiania/assinatura.py,sha256=J7UM28nY5ggGpMC1SpkwDWowdmspnpa-teTlq0GY3KY,1356 | ||
| pytrustnfe/nfse/imperial/__init__.py,sha256=qFvgXZJtqjn2_zUvhzRMVC6OtabdnSk5iepyuXU1b3g,1722 | ||
@@ -119,6 +121,6 @@ pytrustnfe/nfse/imperial/templates/CancelarNota.xml,sha256=znRfhD6g8hdhi30JQ6N1Uddk3NzUgV4nlemJHRxx2y0,555 | ||
| pytrustnfe/xml/schemas/xmldsig-core-schema_v1.01.xsd,sha256=9WdEpfUcA_An3hPzn4aTBwkXganvHZGx6-FHGc4o4aw,3747 | ||
| pytrustnfe3-1.0.56.dist-info/LICENSE.txt,sha256=lWyqyST4jTn4XVBaaQpfZwoyXXa3DHw66K7nHVY6P_4,33893 | ||
| pytrustnfe3-1.0.56.dist-info/METADATA,sha256=9aGC7BQvjCTGWUinhktwAz4XyVY2Dt7Xgzv9RE_r5-k,8293 | ||
| pytrustnfe3-1.0.56.dist-info/WHEEL,sha256=EVRjI69F5qVjm_YgqcTXPnTAv3BfSUr0WVAHuSP3Xoo,92 | ||
| pytrustnfe3-1.0.56.dist-info/top_level.txt,sha256=8qzOFGgNgSalbe42iXXfKIhTpZxoR6egXmnzenbdFko,11 | ||
| pytrustnfe3-1.0.56.dist-info/RECORD,, | ||
| pytrustnfe3-1.0.57.dist-info/LICENSE.txt,sha256=lWyqyST4jTn4XVBaaQpfZwoyXXa3DHw66K7nHVY6P_4,33893 | ||
| pytrustnfe3-1.0.57.dist-info/METADATA,sha256=dunDpvP6iSAxUfq6rhEemFnPvu9GakoPYQPEGF_2FEw,8323 | ||
| pytrustnfe3-1.0.57.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92 | ||
| pytrustnfe3-1.0.57.dist-info/top_level.txt,sha256=8qzOFGgNgSalbe42iXXfKIhTpZxoR6egXmnzenbdFko,11 | ||
| pytrustnfe3-1.0.57.dist-info/RECORD,, |
+1
-1
| Wheel-Version: 1.0 | ||
| Generator: bdist_wheel (0.35.1) | ||
| Generator: bdist_wheel (0.36.2) | ||
| Root-Is-Purelib: true | ||
| Tag: py3-none-any | ||
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.