|
|
|
@ -10,6 +10,17 @@ from pytrustnfe.xml import render_xml, sanitize_response |
|
|
|
from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key |
|
|
|
from pytrustnfe.nfse.assinatura import Assinatura |
|
|
|
|
|
|
|
URLS = { |
|
|
|
'producao': { |
|
|
|
'processar_nota': 'https://nfps-e.pmf.sc.gov.br/api/v1/processamento/notas/processa', |
|
|
|
'cancelar_nota': 'https://nfps-e.pmf.sc.gov.br/api/v1/cancelamento/notas/cancela' |
|
|
|
}, |
|
|
|
'homologacao': { |
|
|
|
'processar_nota': 'https://nfps-e-hml.pmf.sc.gov.br/api/v1/processamento/notas/processa', |
|
|
|
'cancelar_nota': 'https://nfps-e-hml.pmf.sc.gov.br/api/v1/cancelamento/notas/cancela' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def _render(certificado, method, **kwargs): |
|
|
|
path = os.path.join(os.path.dirname(__file__), 'templates') |
|
|
|
@ -49,11 +60,7 @@ def _get_oauth_token(**kwargs): |
|
|
|
|
|
|
|
|
|
|
|
def _send(certificado, method, **kwargs): |
|
|
|
if kwargs['ambiente'] == 'producao': |
|
|
|
url = 'https://nfps-e.pmf.sc.gov.br/api/v1/processamento/notas/processa' #noqa |
|
|
|
else: |
|
|
|
url = 'https://nfps-e-hml.pmf.sc.gov.br/api/v1/processamento/notas/processa' |
|
|
|
|
|
|
|
url = URLS[kwargs['ambiente']][method] |
|
|
|
xml_send = kwargs['xml'] |
|
|
|
|
|
|
|
token = _get_oauth_token(**kwargs) |
|
|
|
@ -62,7 +69,8 @@ def _send(certificado, method, **kwargs): |
|
|
|
token["message"])) |
|
|
|
kwargs.update({"numero": 1, 'access_token': token["access_token"]}) |
|
|
|
|
|
|
|
headers = {"Accept": "application/xml", |
|
|
|
headers = {"Accept": "application/xml;charset=UTF-8", |
|
|
|
"Content-Type": "application/xml", |
|
|
|
"Authorization": "Bearer %s" % kwargs['access_token']} |
|
|
|
r = requests.post(url, headers=headers, data=xml_send) |
|
|
|
|
|
|
|
|