示例#1
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}
示例#2
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}
示例#3
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
    }
示例#4
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
        }
示例#5
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}
示例#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)

    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
        }
示例#7
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
    }
示例#8
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}
示例#9
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
        }
示例#10
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
        }
示例#11
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
        }
示例#12
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}