Example #1
1
def consulta_distribuicao_nfe(certificado, **kwargs):
    if "xml" not in kwargs:
        kwargs['xml'] = xml_consulta_distribuicao_nfe(certificado, **kwargs)
    xml_send = kwargs["xml"]
    base_url = localizar_url(
        'NFeDistribuicaoDFe',  kwargs['estado'], kwargs['modelo'],
        kwargs['ambiente'])

    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    xml_um = etree.fromstring('<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/"><cUF>AN</cUF><versaoDados>1.00</versaoDados></nfeCabecMsg>')
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = next(iter(client.wsdl.port_types[port].operations))
    with client.settings(raw_response=True):
        response = client.service[first_operation](nfeDadosMsg=xml, _soapheaders=[xml_um])
        response, obj = sanitize_response(response.text)
        return {
            'sent_xml': xml_send,
            'received_xml': response,
            'object': obj.Body.nfeDistDFeInteresseResponse.nfeDistDFeInteresseResult
        }
Example #2
0
def _send_v310(certificado, **kwargs):
    xml_send = kwargs["xml"]
    base_url = localizar_url(
        "NFeDistribuicaoDFe", kwargs["estado"], kwargs["modelo"], kwargs["ambiente"]
    )

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    xml_um = etree.fromstring(
        '<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/"><cUF>AN</cUF><versaoDados>1.00</versaoDados></nfeCabecMsg>'
    )
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = next(iter(client.wsdl.port_types[port].operations))
    with client.settings(raw_response=True):
        response = client.service[first_operation](
            nfeDadosMsg=xml, _soapheaders=[xml_um]
        )
        response, obj = sanitize_response(response.text)
        return {
            "sent_xml": xml_send,
            "received_xml": response,
            "object": obj.Body.nfeDistDFeInteresseResponse.nfeDistDFeInteresseResult,
        }
Example #3
0
def _send(certificado, method, **kwargs):
    base_url = ""
    if kwargs["ambiente"] == "producao":
        base_url = "https://wsnfsev1.natal.rn.gov.br:8444"
    else:
        base_url = "https://wsnfsev1homologacao.natal.rn.gov.br:8443/axis2/services/NfseWSServiceV1?wsdl"

    base_url = "https://wsnfsev1homologacao.natal.rn.gov.br:8443/axis2/services/NfseWSServiceV1?wsdl"
    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    disable_warnings()
    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(wsdl=base_url, transport=transport)
    xml_send = {}
    xml_send = {
        "nfseDadosMsg": kwargs["xml"],
        "nfseCabecMsg": """<?xml version="1.0"?>
        <cabecalho xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" versao="1" xmlns="http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd">
        <versaoDados>1</versaoDados>
        </cabecalho>""",
    }

    response = client.service[method](**xml_send)
    response, obj = sanitize_response(response)
    return {"sent_xml": xml_send, "received_xml": response, "object": obj}
Example #4
0
def _send(certificado, method, **kwargs):
    # A little hack to test
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS' \
       or method == 'CancelamentoNFe':
        sign_tag(certificado, **kwargs)

    if method == 'TesteEnvioLoteRPS':
        xml_send = render_xml(path, 'EnvioLoteRPS.xml', False, **kwargs)
    else:
        xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
    base_url = 'https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?wsdl'

    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)

    pfx_path = certificado.save_pfx()
    signer = Assinatura(pfx_path, certificado.password)
    xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault, e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
Example #5
0
def _send(certificado, method, **kwargs):
    base_url = ""
    if kwargs["ambiente"] == "producao":
        base_url = "https://notacarioca.rio.gov.br/WSNacional/nfse.asmx?wsdl"
    else:
        base_url = "https://notacariocahom.rio.gov.br/WSNacional/nfse.asmx?wsdl"  # noqa

    xml_send = kwargs["xml"].decode("utf-8")
    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 {
            "sent_xml": str(xml_send),
            "received_xml": str(e.fault.faultstring),
            "object": None,
        }

    response, obj = sanitize_response(response)
    return {
        "sent_xml": str(xml_send),
        "received_xml": str(response),
        "object": obj
    }
Example #6
0
def _send(certificado, method, **kwargs):
    # A little hack to test
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS' \
       or method == 'CancelamentoNFe':
        sign_tag(certificado, **kwargs)

    if method == 'TesteEnvioLoteRPS':
        xml_send = render_xml(path, 'EnvioLoteRPS.xml', False, **kwargs)
    else:
        xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
    base_url = 'https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?wsdl'

    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)

    signer = Assinatura(cert, key, certificado.password)
    xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }

    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #7
0
def _send(certificado, method, **kwargs):
    url = _get_url(**kwargs)

    path = os.path.join(os.path.dirname(__file__), 'templates')

    xml_send = _render(path, method, **kwargs)
    client = get_client(url)
    response = False

    if certificado:
        cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                                  certificado.password)
        cert, key = save_cert_key(cert, key)
        signer = Assinatura(cert, key, certificado.password)
        xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(xml_send)
        response, obj = sanitize_response(response.encode())
    except suds.WebFault as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
    except Exception as e:
        if response:
            raise Exception(response)
        else:
            raise e

    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #8
0
def _send(certificado, method, **kwargs):
    xml_send = kwargs["xml"]
    base_url = localizar_url(method, kwargs['estado'], kwargs['modelo'],
                             kwargs['ambiente'])

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = next(iter(client.wsdl.port_types[port].operations))
    with client.settings(raw_response=True):
        response = client.service[first_operation](xml)
        response, obj = sanitize_response(response.text)
        return {
            'sent_xml': xml_send,
            'received_xml': response,
            'object': obj.Body.getchildren()[0]
        }
Example #9
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://isse.maringa.gov.br/ws/?wsdl'
    else:
        base_url = 'https://isseteste.maringa.gov.br/ws/?wsdl'

    xml_send = kwargs["xml"].decode('utf-8')
    xml_cabecalho = '<?xml version="1.0" encoding="UTF-8"?>\
    <cabecalho xmlns="http://www.abrasf.org.br/nfse.xsd" versao="1.00">\
    <versaoDados>1.00</versaoDados></cabecalho>'

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(base_url, transport=transport)

    response = client.service[method](xml_cabecalho, xml_send)

    response, obj = sanitize_response(response.encode('utf-8'))
    return {
        'sent_xml': str(xml_send),
        'received_xml': str(response),
        'object': obj
    }
Example #10
0
def _send(certificado, method, **kwargs):
    # A little hack to test
    path = os.path.join(os.path.dirname(__file__), "templates")
    if (
        method == "TesteEnvioLoteRPS"
        or method == "EnvioLoteRPS"
        or method == "CancelamentoNFe"
    ):
        sign_tag(certificado, **kwargs)

    if method == "TesteEnvioLoteRPS":
        xml_send = render_xml(path, "EnvioLoteRPS.xml", False, **kwargs)
    else:
        xml_send = render_xml(path, "%s.xml" % method, False, **kwargs)
    base_url = "https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?wsdl"

    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)

    signer = Assinatura(cert, key, certificado.password)
    xml_send = signer.assina_xml(xml_send, "")

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            "sent_xml": xml_send,
            "received_xml": e.fault.faultstring,
            "object": None,
        }

    response, obj = sanitize_response(response)
    return {"sent_xml": xml_send, "received_xml": response, "object": obj}
Example #11
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://notacarioca.rio.gov.br/WSNacional/nfse.asmx?wsdl'
    else:
        base_url = 'https://homologacao.notacarioca.rio.gov.br/WSNacional/nfse.asmx?wsdl'  # noqa

    xml_send = kwargs["xml"].decode('utf-8')
    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 {
            'sent_xml': str(xml_send),
            'received_xml': str(e.fault.faultstring),
            'object': None
        }

    response, obj = sanitize_response(response)
    return {
        'sent_xml': str(xml_send),
        'received_xml': str(response),
        'object': obj
    }
Example #12
0
def _send(certificado, method, **kwargs):
    base_url = ""
    if kwargs["ambiente"] == "producao":
        base_url = "https://bhissdigital.pbh.gov.br/bhiss-ws/nfse?wsdl"
    else:
        base_url = "https://bhisshomologa.pbh.gov.br/bhiss-ws/nfse?wsdl"

    xml_send = kwargs["xml"].decode("utf-8")
    xml_cabecalho = '<?xml version="1.0" encoding="UTF-8"?>\
    <cabecalho xmlns="http://www.abrasf.org.br/nfse.xsd" versao="1.00">\
    <versaoDados>1.00</versaoDados></cabecalho>'

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(base_url, transport=transport)

    response = client.service[method](xml_cabecalho, xml_send)

    response, obj = sanitize_response(response)
    return {"sent_xml": xml_send, "received_xml": response, "object": obj}
Example #13
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://isse.maringa.pr.gov.br/ws/?wsdl'
    else:
        base_url = 'https://isseteste.maringa.pr.gov.br/ws/?wsdl'

    xml_send = kwargs["xml"].decode('utf-8')

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(base_url, transport=transport)
    response = client.service[method](xml_send)

    response, obj = sanitize_response(response)
    return {
        'sent_xml': str(xml_send),
        'received_xml': str(response),
        'object': obj
    }
Example #14
0
def _send(certificado, method, **kwargs):
    base_url = ""
    if kwargs["ambiente"] == "producao":
        base_url = "https://isse.maringa.pr.gov.br/ws/?wsdl"
    else:
        base_url = "https://isseteste.maringa.pr.gov.br/ws/?wsdl"

    xml_send = kwargs["xml"].decode("utf-8")

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(base_url, transport=transport)
    response = client.service[method](xml_send)

    response, obj = sanitize_response(response)
    return {
        "sent_xml": str(xml_send),
        "received_xml": str(response),
        "object": obj
    }
Example #15
0
def _send(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method in ('GerarNfse', 'RecepcionarLoteRps',
                  'RecepcionarLoteRpsSincrono', 'CancelarNfse',
                  'SubstituirNfse'):
        sign_tag(certificado, **kwargs)

    if kwargs['ambiente'] == 'producao':
        url = \
            'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl'
    else:
        url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'

    xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)
    client = get_authenticated_client(url, cert, key)

    pfx_path = certificado.save_pfx()
    signer = Assinatura(pfx_path, certificado.password)
    xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }

    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #16
0
def _send(certificado, method, **kwargs):
    xml_send = kwargs["xml"]
    base_url = localizar_url(
        method,  kwargs['estado'], kwargs['modelo'], kwargs['ambiente'])

    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = next(iter(client.wsdl.port_types[port].operations))
    
    namespaceNFe = xml.find(".//{http://www.portalfiscal.inf.br/nfe}NFe")
    if namespaceNFe is not None:
        namespaceNFe.set('xmlns', 'http://www.portalfiscal.inf.br/nfe')
            
    with client.settings(raw_response=True):
        response = client.service[first_operation](xml)
        response, obj = sanitize_response(response.text)
        return {
            'sent_xml': xml_send,
            'received_xml': response,
            'object': obj.Body.getchildren()[0]
        }
Example #17
0
def consulta_distribuicao_nfe(certificado, **kwargs):
    if "xml" not in kwargs:
        kwargs['xml'] = xml_consulta_distribuicao_nfe(certificado, **kwargs)
    xml_send = kwargs["xml"]
    base_url = localizar_url('NFeDistribuicaoDFe', kwargs['estado'],
                             kwargs['modelo'], kwargs['ambiente'])
    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    xml_um = etree.fromstring(
        '<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe"><cUF>AN</cUF><versaoDados>1.00</versaoDados></nfeCabecMsg>'
    )
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = [
        x for x in iter(client.wsdl.port_types[port].operations)
        if "Zip" not in x
    ][0]
    with client.settings(raw_response=True):
        response = client.service[first_operation](nfeDadosMsg=xml,
                                                   _soapheaders=[xml_um]).text
        response, obj = sanitize_response(response.encode())
        return {
            'sent_xml': xml_send,
            'received_xml': response.decode(),
            'object': obj
        }
Example #18
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://producao.ginfes.com.br/ServiceGinfesImpl?wsdl'
    else:
        base_url = 'https://homologacao.ginfes.com.br/ServiceGinfesImpl?wsdl'

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    header = '<ns2:cabecalho xmlns:ns2="http://www.ginfes.com.br/cabecalho_v03.xsd" versao="3"><versaoDados>3</versaoDados></ns2:cabecalho>'  #noqa

    disable_warnings()
    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(base_url, transport=transport)

    xml_send = kwargs['xml']
    response = client.service[method](header, xml_send)

    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #19
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://isscuritiba.curitiba.pr.gov.br/Iss.NfseWebService/nfsews.asmx'
    else:
        base_url = 'https://pilotoisscuritiba.curitiba.pr.gov.br/nfse_ws/nfsews.asmx'

    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)
    try:
        client = get_authenticated_client(base_url, cert, key)
    except Exception as e: 
        return {
            'sent_xml': kwargs.get('xml', False),
            'received_xml': str(e),
            'object': None
        }
    #_logger.info(str(client))
    try:
        xml_send = kwargs['xml']
        header = '<cabecalho xmlns="http://www.betha.com.br/e-nota-contribuinte-ws" versao="2.02"><versaoDados>2.02</versaoDados></cabecalho>' #noqa
        response = getattr(client.service, method)(header, xml_send)
    except suds.WebFault, e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
Example #20
0
def _get_session(certificado):
    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    return session
Example #21
0
 def test_save_cert_and_key(self):
     dir_pfx = open(os.path.join(self.caminho, "teste.pfx"), "rb").read()
     cert, key = extract_cert_and_key_from_pfx(dir_pfx, "123456")
     cert_path, key_path = save_cert_key(cert, key)
     cert_saved = open(cert_path, "r").read()
     key_saved = open(key_path, "r").read()
     self.assertEqual(cert, cert_saved, "Certificado não corresponde ao original")
     self.assertEqual(key, key_saved, "Chave não corresponde ao original")
Example #22
0
 def test_save_cert_and_key(self):
     dir_pfx = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
     cert, key = extract_cert_and_key_from_pfx(dir_pfx, '123456')
     cert_path, key_path = save_cert_key(cert, key)
     cert_saved = open(cert_path, 'r').read()
     key_saved = open(key_path, 'r').read()
     self.assertEqual(
         cert, cert_saved, 'Certificado não corresponde ao original')
     self.assertEqual(key, key_saved, 'Chave não corresponde ao original')
Example #23
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    xml_send = render_xml(path, "%s.xml" % method, False, **kwargs)

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)
    signer = Assinatura(cert, key, certificado.password)
    xml_send = signer.assina_xml(xml_send, "")
    return xml_send
Example #24
0
def executar_consulta(certificado, url, cabecalho, xmlEnviar):
    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert_path, key_path = save_cert_key(cert, key)
    client = HttpClient(url, cert_path, key_path)

    xml_enviar = _soap_xml(xmlEnviar, cabecalho)
    xml_retorno = client.post_soap(xml_enviar, cabecalho)
    return sanitize_response(xml_retorno)
Example #25
0
def executar_consulta(certificado, url, method, xmlEnviar, send_raw=False):
    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert_path, key_path = save_cert_key(cert, key)
    client = HttpClient(url, cert_path, key_path)
    xml_enviar = _soap_xml(xmlEnviar, method)

    if send_raw:
        xml = '<?xml version="1.0" encoding="utf-8"?>' + xmlEnviar.rstrip('\n')
        xml_enviar = xml
    xml_retorno = client.post_soap(xml_enviar, _post_header(method), send_raw)
    return sanitize_response(xml_retorno.encode())
Example #26
0
def executar_consulta(certificado, url, cabecalho, xmlEnviar, send_raw=False):
    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert_path, key_path = save_cert_key(cert, key)
    client = HttpClient(url, cert_path, key_path)

    xml_enviar = _soap_xml(xmlEnviar, cabecalho)
    if send_raw:
        xml = '<?xml version="1.0" encoding="utf-8"?>' + xmlEnviar.rstrip('\n')
        xml_enviar = xml
    xml_retorno = client.post_soap(xml_enviar, cabecalho)
    return sanitize_response(xml_retorno)
Example #27
0
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}
Example #28
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://producao.ginfes.com.br/ServiceGinfesImpl?wsdl'
    else:
        base_url = 'https://homologacao.ginfes.com.br/ServiceGinfesImpl?wsdl'

    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:
        xml_send = kwargs['xml']
        header = '<ns2:cabecalho xmlns:ns2="http://www.ginfes.com.br/cabecalho_v03.xsd" versao="3"><versaoDados>3</versaoDados></ns2:cabecalho>' #noqa
        response = getattr(client.service, method)(header, xml_send)
    except suds.WebFault, e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
Example #29
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://producao.ginfes.com.br/ServiceGinfesImpl?wsdl'
    else:
        base_url = 'https://homologacao.ginfes.com.br/ServiceGinfesImpl?wsdl'

    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:
        xml_send = kwargs['xml']
        header = '<ns2:cabecalho xmlns:ns2="http://www.ginfes.com.br/cabecalho_v03.xsd" versao="3"><versaoDados>3</versaoDados></ns2:cabecalho>'  #noqa
        response = getattr(client.service, method)(header, xml_send)
    except suds.WebFault, e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
Example #30
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'
    else:
        base_url = 'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl'

    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)
    #_logger.info(str(client))
    try:
        xml_send = kwargs['xml']
        header = '<cabecalho xmlns="http://www.betha.com.br/e-nota-contribuinte-ws" versao="2.02"><versaoDados>2.02</versaoDados></cabecalho>'  #noqa
        response = getattr(client.service, method)(header, xml_send)
    except suds.WebFault, e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
Example #31
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://aparecida.siltecnologia.com.br/tbw/services/Abrasf10?wsdl'
    else:
        base_url = 'https://aparecida.siltecnologia.com.br/tbwhomologacao/services/Abrasf10?wsdl'

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)

    disable_warnings()
    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    client = Client(base_url, transport=transport)

    xml_send = kwargs['xml']
    response = client.service[method](xml_send)
    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #32
0
def _send(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    if method in (
        "GerarNfse",
        "RecepcionarLoteRps",
        "RecepcionarLoteRpsSincrono",
        "CancelarNfse",
        "SubstituirNfse",
    ):
        sign_tag(certificado, **kwargs)

    if kwargs["ambiente"] == "producao":
        url = "http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl"
    else:
        url = "http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl"

    xml_send = render_xml(path, "%s.xml" % method, False, **kwargs)

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)
    client = get_authenticated_client(url, cert, key)

    pfx_path = certificado.save_pfx()
    signer = Assinatura(pfx_path, certificado.password)
    xml_send = signer.assina_xml(xml_send, "")

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            "sent_xml": xml_send,
            "received_xml": e.fault.faultstring,
            "object": None,
        }

    response, obj = sanitize_response(response)
    return {"sent_xml": xml_send, "received_xml": response, "object": obj}