spei-python 0.53.0__tar.gz → 0.53.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {spei_python-0.53.0 → spei_python-0.53.1}/PKG-INFO +1 -1
- {spei_python-0.53.0 → spei_python-0.53.1}/pyproject.toml +2 -2
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/client.py +30 -16
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/errors/sice.py +1 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/errors/spei.py +3 -1
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/requests/cda.py +12 -5
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/requests/orden.py +18 -7
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/cda.py +16 -3
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/orden.py +86 -42
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/respuesta.py +2 -2
- spei_python-0.53.1/spei/resources/validators.py +107 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/sice.py +20 -12
- spei_python-0.53.1/spei/utils.py +18 -0
- spei_python-0.53.0/spei/utils.py +0 -11
- {spei_python-0.53.0 → spei_python-0.53.1}/README.md +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/README.md +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/cep_generator.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/checksum/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/checksum/factory.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/checksum/generator.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/checksum/types.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/errors/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/exceptions.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/mappings.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/requests/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/requests/acuse.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/requests/respuesta.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/acuse.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/ensesion.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/mensaje.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/resources/payments.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/responses/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/responses/acuse.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/responses/orden.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/responses/respuesta.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/types/__init__.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/types/sice.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/types/spei.py +0 -0
- {spei_python-0.53.0 → spei_python-0.53.1}/spei/validators.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "spei-python"
|
|
3
|
-
version = "0.53.
|
|
3
|
+
version = "0.53.1"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["tech <tech@fondeadora.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -32,7 +32,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
32
32
|
|
|
33
33
|
[tool.commitizen]
|
|
34
34
|
name = "cz_conventional_commits"
|
|
35
|
-
version = "0.53.
|
|
35
|
+
version = "0.53.1"
|
|
36
36
|
tag_format = "v$version"
|
|
37
37
|
bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
|
|
38
38
|
version_files = [
|
|
@@ -34,7 +34,12 @@ class BaseClient(object):
|
|
|
34
34
|
self.priv_key_passphrase = priv_key_passphrase or None
|
|
35
35
|
self.host = host
|
|
36
36
|
self.session = http_client.Session()
|
|
37
|
-
self.session.headers.update(
|
|
37
|
+
self.session.headers.update(
|
|
38
|
+
{
|
|
39
|
+
'Content-Type': 'application/xml; charset=cp850',
|
|
40
|
+
'User-Agent': 'Fondeadora/Karpay/v0.52.0',
|
|
41
|
+
},
|
|
42
|
+
)
|
|
38
43
|
self.session.verify = verify
|
|
39
44
|
self.session.auth = (username, password)
|
|
40
45
|
|
|
@@ -49,19 +54,6 @@ class BaseClient(object):
|
|
|
49
54
|
|
|
50
55
|
self.checksum_generator_factory = checksum_generator_factory
|
|
51
56
|
|
|
52
|
-
def generate_checksum(self, message_data):
|
|
53
|
-
orden = Orden(**message_data, op_firma_dig='')
|
|
54
|
-
generator = self.checksum_generator_factory(orden.op_tp_clave)
|
|
55
|
-
message_as_bytes = generator.format_data(orden)
|
|
56
|
-
|
|
57
|
-
signed_message = self.pkey.sign(
|
|
58
|
-
message_as_bytes,
|
|
59
|
-
padding.PKCS1v15(),
|
|
60
|
-
SHA256(),
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
return base64.b64encode(signed_message)
|
|
64
|
-
|
|
65
57
|
def registra_orden(
|
|
66
58
|
self,
|
|
67
59
|
orden_data,
|
|
@@ -70,19 +62,41 @@ class BaseClient(object):
|
|
|
70
62
|
):
|
|
71
63
|
checksum = self.generate_checksum(orden_data)
|
|
72
64
|
orden = orden_cls(op_firma_dig=checksum, **orden_data)
|
|
73
|
-
soap_request = OrdenRequest(orden)
|
|
65
|
+
soap_request = OrdenRequest(orden).to_string()
|
|
74
66
|
logger.info(soap_request)
|
|
67
|
+
|
|
75
68
|
response = self.session.post(data=soap_request, url=self.host)
|
|
76
69
|
logger.info(response.text)
|
|
77
70
|
response.raise_for_status()
|
|
71
|
+
|
|
78
72
|
respuesta = respuesta_response_cls(response.text)
|
|
73
|
+
|
|
79
74
|
if respuesta.err_codigo != errors.GenericoCodigoError.exitoso:
|
|
80
75
|
self._raise_error(respuesta)
|
|
76
|
+
|
|
81
77
|
return respuesta
|
|
82
78
|
|
|
79
|
+
def generate_checksum(self, message_data):
|
|
80
|
+
orden = Orden(**message_data, op_firma_dig='')
|
|
81
|
+
generator = self.checksum_generator_factory(orden.op_tp_clave)
|
|
82
|
+
message_as_bytes = generator.format_data(orden)
|
|
83
|
+
|
|
84
|
+
signed_message = self.pkey.sign(
|
|
85
|
+
message_as_bytes,
|
|
86
|
+
padding.PKCS1v15(),
|
|
87
|
+
SHA256(),
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return base64.b64encode(signed_message)
|
|
91
|
+
|
|
83
92
|
def _raise_error(self, respuesta: Respuesta):
|
|
84
93
|
if respuesta.err_codigo == errors.GenericoCodigoError.tipo_pago_invalido:
|
|
85
94
|
raise exceptions.TipoPagoInvalidoError(respuesta)
|
|
86
|
-
|
|
95
|
+
|
|
96
|
+
if ( # noqa: WPS337
|
|
97
|
+
respuesta.err_codigo
|
|
98
|
+
== errors.OtrosCodigoError.otros_fecha_operacion_incorrecta
|
|
99
|
+
):
|
|
87
100
|
raise exceptions.FechaOperacionIncorrectaError(respuesta)
|
|
101
|
+
|
|
88
102
|
raise exceptions.SPEIError(respuesta)
|
|
@@ -99,6 +99,7 @@ class CodigoErrorAcuseServidor(str, Enum):
|
|
|
99
99
|
tipo_pago_no_catalogado = 'EV03'
|
|
100
100
|
clasificacion_operacion_obligatoria = 'EW01'
|
|
101
101
|
clasificacion_operacion_maximo_2_digitos = 'EW02'
|
|
102
|
+
emisor_remesa_vacio = 'EW13'
|
|
102
103
|
|
|
103
104
|
folio_codi_no_corresponde = 'EY01'
|
|
104
105
|
folio_codi_invalido = 'EY02'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
|
+
from typing import List, Tuple
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
class GenericoCodigoError(str, Enum):
|
|
@@ -445,8 +446,9 @@ ERROR_CODES = (
|
|
|
445
446
|
|
|
446
447
|
|
|
447
448
|
def generate_error_codes():
|
|
448
|
-
error_codes = []
|
|
449
|
+
error_codes: List[Tuple[str, int]] = []
|
|
449
450
|
for error_code in ERROR_CODES:
|
|
450
451
|
for err in error_code:
|
|
451
452
|
error_codes.append((err.name, err.value))
|
|
453
|
+
|
|
452
454
|
return Enum('CodigoError', dict(error_codes))
|
|
@@ -37,8 +37,15 @@ class EnvelopeElement(object):
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class CDARequest(object):
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
def __init__(self, mensaje: CDA):
|
|
41
|
+
self._envelope = EnvelopeElement(BodyElement(CDAElement(mensaje.build_xml())))
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def tree(self):
|
|
45
|
+
return self._envelope
|
|
46
|
+
|
|
47
|
+
def to_string(self) -> bytes:
|
|
48
|
+
"""
|
|
49
|
+
Returns the SOAP request as a string encoded in cp850 (bytes).
|
|
50
|
+
"""
|
|
51
|
+
return etree.tostring(self._envelope, encoding='cp850', xml_declaration=True)
|
|
@@ -10,14 +10,17 @@ class MensajeElement(object):
|
|
|
10
10
|
def __new__(cls, orden: Orden):
|
|
11
11
|
mensaje = etree.Element('mensaje', categoria=orden.categoria)
|
|
12
12
|
mensaje.append(orden.build_xml())
|
|
13
|
+
|
|
13
14
|
return mensaje
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class OrdenPagoElement(object):
|
|
17
18
|
def __new__(cls, mensaje):
|
|
18
19
|
ordenpago = etree.Element(etree.QName(PRAXIS_NS, 'ordenpago'))
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
mensaje_str = etree.tostring(mensaje, encoding='cp850')
|
|
22
|
+
ordenpago.text = etree.CDATA(mensaje_str.decode('cp850'))
|
|
23
|
+
|
|
21
24
|
return ordenpago
|
|
22
25
|
|
|
23
26
|
|
|
@@ -25,6 +28,7 @@ class BodyElement(object):
|
|
|
25
28
|
def __new__(cls, ordenpago):
|
|
26
29
|
body = etree.Element(etree.QName(SOAP_NS, 'Body'))
|
|
27
30
|
body.append(ordenpago)
|
|
31
|
+
|
|
28
32
|
return body
|
|
29
33
|
|
|
30
34
|
|
|
@@ -39,12 +43,19 @@ class EnvelopeElement(object):
|
|
|
39
43
|
nsmap=namespaces_uris,
|
|
40
44
|
)
|
|
41
45
|
envelope.append(body)
|
|
46
|
+
|
|
42
47
|
return envelope
|
|
43
48
|
|
|
44
49
|
|
|
45
50
|
class OrdenRequest(object):
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
def __init__(self, orden: Orden):
|
|
52
|
+
self._envelope: etree._Element = EnvelopeElement( # noqa: WPS437
|
|
53
|
+
BodyElement(OrdenPagoElement(MensajeElement(orden))),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def tree(self) -> etree._Element: # noqa: WPS437
|
|
58
|
+
return self._envelope
|
|
59
|
+
|
|
60
|
+
def to_string(self) -> bytes:
|
|
61
|
+
return etree.tostring(self._envelope, encoding='cp850', xml_declaration=True)
|
|
@@ -4,7 +4,7 @@ from lxml import etree
|
|
|
4
4
|
from pydantic.v1 import BaseModel
|
|
5
5
|
|
|
6
6
|
from spei import types
|
|
7
|
-
from spei.utils import
|
|
7
|
+
from spei.utils import to_pascal_case, to_snake_case # noqa: WPS347
|
|
8
8
|
|
|
9
9
|
SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
|
|
10
10
|
PRAXIS_NS = 'http://www.praxis.com.mx/'
|
|
@@ -52,10 +52,23 @@ class CDA(BaseModel):
|
|
|
52
52
|
op_cta_part_indirecto_ord: Optional[str] = None
|
|
53
53
|
op_rfc_curp_part_indirecto_ord: Optional[str] = None
|
|
54
54
|
|
|
55
|
+
# remesas
|
|
56
|
+
op_id_remesa: Optional[str] = None
|
|
57
|
+
op_pais: Optional[str] = None
|
|
58
|
+
op_divisa: Optional[str] = None
|
|
59
|
+
op_nom_emisor_rem: Optional[str] = None
|
|
60
|
+
op_cta_emisor_rem: Optional[str] = None
|
|
61
|
+
op_rfc_curp_emisor_rem: Optional[str] = None
|
|
62
|
+
op_nom_ben_rem: Optional[str] = None
|
|
63
|
+
op_cta_ben_rem: Optional[str] = None
|
|
64
|
+
op_rfc_curp_ben_rem: Optional[str] = None
|
|
65
|
+
op_nom_prov_rem_ext: Optional[str] = None
|
|
66
|
+
op_nom_prov_rem_nac: Optional[str] = None
|
|
67
|
+
|
|
55
68
|
class Config: # noqa: WPS306, WPS431
|
|
56
69
|
use_enum_values = True
|
|
57
70
|
|
|
58
|
-
def build_xml(self):
|
|
71
|
+
def build_xml(self) -> etree._Element: # noqa: WPS437
|
|
59
72
|
mensaje = etree.Element(
|
|
60
73
|
etree.QName(ENVIO_PRAXIS_NS, 'datosCda'),
|
|
61
74
|
idCda=str(self.id),
|
|
@@ -67,7 +80,7 @@ class CDA(BaseModel):
|
|
|
67
80
|
|
|
68
81
|
for element, value in elements.items(): # noqa: WPS110
|
|
69
82
|
if element in self.__fields__:
|
|
70
|
-
upper_camel_case_element =
|
|
83
|
+
upper_camel_case_element = to_pascal_case(element)
|
|
71
84
|
subelement = etree.SubElement(
|
|
72
85
|
mensaje,
|
|
73
86
|
etree.QName(ENVIO_PRAXIS_NS, upper_camel_case_element),
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import re
|
|
2
|
-
from typing import Optional
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
3
|
|
|
4
4
|
from lxml import etree
|
|
5
|
+
from lxml.etree import _Element # noqa: WPS450, WPS458
|
|
5
6
|
from pydantic.v1 import BaseModel, validator
|
|
6
|
-
from unidecode import unidecode
|
|
7
7
|
|
|
8
8
|
from spei import types
|
|
9
|
-
from spei.
|
|
9
|
+
from spei.resources.validators import validate_alphanumeric
|
|
10
|
+
from spei.utils import to_camel_case, to_pascal_case, to_snake_case # noqa: WPS347
|
|
10
11
|
from spei.validators import digits
|
|
11
12
|
|
|
12
13
|
SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
|
|
13
14
|
PRAXIS_NS = 'http://www.praxis.com.mx/'
|
|
15
|
+
_DATE_PATTERN = re.compile(r'^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$')
|
|
16
|
+
_WHITESPACE_PATTERN = re.compile(r'\s+')
|
|
17
|
+
_CAMEL_CASE_FIELDS = frozenset(
|
|
18
|
+
(
|
|
19
|
+
'op_rastreo_ori',
|
|
20
|
+
'op_fecha_oper_ori',
|
|
21
|
+
'op_monto_ori',
|
|
22
|
+
'op_monto_intereses',
|
|
23
|
+
'op_comision_trans',
|
|
24
|
+
),
|
|
25
|
+
)
|
|
14
26
|
|
|
15
27
|
|
|
16
28
|
class Orden(BaseModel):
|
|
@@ -36,6 +48,11 @@ class Orden(BaseModel):
|
|
|
36
48
|
op_tc_clave_ord: Optional[types.TipoCuentaOrdenPago] = None
|
|
37
49
|
op_cuenta_ord: Optional[str] = None
|
|
38
50
|
op_rfc_curp_ord: Optional[str] = None
|
|
51
|
+
# In Karpay only OpInsClave exists.
|
|
52
|
+
# It is always the institution that generates the payment order.
|
|
53
|
+
# For deposits, it is the other institution.
|
|
54
|
+
# For transfers, it is Fondeadora.
|
|
55
|
+
# Here we use OpInsClaveOrd and OpInsClaveBen to differentiate between them.
|
|
39
56
|
op_ins_clave_ord: Optional[digits(3, 5)] = None # type: ignore
|
|
40
57
|
# destination info
|
|
41
58
|
op_nom_ben: Optional[str] = None
|
|
@@ -105,6 +122,20 @@ class Orden(BaseModel):
|
|
|
105
122
|
ah_ar_clave: Optional[int] = None
|
|
106
123
|
emp_clave: Optional[int] = None
|
|
107
124
|
|
|
125
|
+
# remesas
|
|
126
|
+
op_id_remesa: Optional[str] = None
|
|
127
|
+
op_pais: Optional[str] = None
|
|
128
|
+
op_divisa: Optional[str] = None
|
|
129
|
+
op_tipo_cambio: Optional[float] = None
|
|
130
|
+
op_nom_emisor_remesa: Optional[str] = None
|
|
131
|
+
tc_clave_emisor_remesa: Optional[int] = None
|
|
132
|
+
op_cuenta_emisor_remesa: Optional[str] = None
|
|
133
|
+
op_rfc_curp_emisor_remesa: Optional[str] = None
|
|
134
|
+
op_nom_ben_remesa: Optional[str] = None
|
|
135
|
+
op_nom_prov_remesa_extranjera: Optional[str] = None
|
|
136
|
+
op_nom_prov_remesa_nacional: Optional[str] = None
|
|
137
|
+
op_nom_ben_indirecto_receptor: Optional[str] = None
|
|
138
|
+
|
|
108
139
|
class Config: # noqa: WPS306, WPS431
|
|
109
140
|
use_enum_values = True
|
|
110
141
|
|
|
@@ -115,14 +146,13 @@ class Orden(BaseModel):
|
|
|
115
146
|
|
|
116
147
|
@validator('op_fecha_oper')
|
|
117
148
|
def op_fecha_oper_must_be_iso_format(cls, value): # noqa: WPS110, N805
|
|
118
|
-
|
|
119
|
-
if re.findall(regex, str(value)):
|
|
149
|
+
if _DATE_PATTERN.findall(str(value)):
|
|
120
150
|
return value
|
|
121
151
|
|
|
122
152
|
raise ValueError('must be in YYYYMMDD format')
|
|
123
153
|
|
|
124
|
-
def build_xml(self): # noqa: WPS231, C901
|
|
125
|
-
ordenpago = etree.Element('ordenpago', Id=str(self.id))
|
|
154
|
+
def build_xml(self) -> _Element: # noqa: WPS231, C901
|
|
155
|
+
ordenpago: _Element = etree.Element('ordenpago', Id=str(self.id))
|
|
126
156
|
|
|
127
157
|
elements = self.dict(
|
|
128
158
|
exclude_none=True,
|
|
@@ -131,55 +161,69 @@ class Orden(BaseModel):
|
|
|
131
161
|
|
|
132
162
|
for element, value in elements.items(): # noqa: WPS110
|
|
133
163
|
if element in self.__fields__:
|
|
134
|
-
if element == '
|
|
135
|
-
subelement = etree.SubElement(ordenpago, 'opFirmaDig')
|
|
136
|
-
subelement.text = str(value)
|
|
137
|
-
continue
|
|
138
|
-
if element == 'op_ins_clave_ben':
|
|
164
|
+
if element == 'op_ins_clave_ben': # We have a different name for this
|
|
139
165
|
subelement = etree.SubElement(ordenpago, 'OpInsClave')
|
|
140
166
|
subelement.text = str(value)
|
|
141
167
|
continue
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
subelement
|
|
145
|
-
continue
|
|
146
|
-
if element == 'op_fecha_oper_ori':
|
|
147
|
-
subelement = etree.SubElement(ordenpago, 'opFechaOperOri')
|
|
148
|
-
subelement.text = str(value)
|
|
149
|
-
continue
|
|
150
|
-
if element == 'op_monto_ori':
|
|
151
|
-
subelement = etree.SubElement(ordenpago, 'opMontoOri')
|
|
152
|
-
subelement.text = str(value)
|
|
153
|
-
continue
|
|
154
|
-
if element == 'op_monto_intereses':
|
|
155
|
-
subelement = etree.SubElement(ordenpago, 'opMontoInteres')
|
|
168
|
+
|
|
169
|
+
if element == 'op_firma_dig': # Lower case o in op
|
|
170
|
+
subelement = etree.SubElement(ordenpago, 'opFirmaDig')
|
|
156
171
|
subelement.text = str(value)
|
|
157
172
|
continue
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
173
|
+
|
|
174
|
+
text = self._process_text(str(value), element)
|
|
175
|
+
|
|
176
|
+
if element in _CAMEL_CASE_FIELDS:
|
|
177
|
+
subelement = etree.SubElement(ordenpago, to_camel_case(element))
|
|
178
|
+
subelement.text = text
|
|
161
179
|
continue
|
|
162
|
-
|
|
163
|
-
subelement = etree.SubElement(ordenpago,
|
|
164
|
-
subelement.text =
|
|
180
|
+
|
|
181
|
+
subelement = etree.SubElement(ordenpago, to_pascal_case(element))
|
|
182
|
+
subelement.text = text
|
|
165
183
|
|
|
166
184
|
return ordenpago
|
|
167
185
|
|
|
168
186
|
@classmethod
|
|
169
|
-
def parse_xml(cls, orden_element, categoria: types.CategoriaOrdenPago):
|
|
170
|
-
|
|
187
|
+
def parse_xml(cls, orden_element: _Element, categoria: types.CategoriaOrdenPago):
|
|
188
|
+
"""Parse XML element into an Orden instance."""
|
|
189
|
+
orden_data: Dict[str, Any] = {
|
|
171
190
|
'id': orden_element.attrib['Id'],
|
|
172
191
|
'categoria': categoria,
|
|
173
192
|
}
|
|
174
193
|
|
|
175
194
|
for element in orden_element.getchildren():
|
|
176
|
-
|
|
177
|
-
if tag in cls.__fields__:
|
|
178
|
-
if element.text:
|
|
179
|
-
orden_data[tag] = unidecode(element.text.strip())
|
|
180
|
-
else:
|
|
181
|
-
orden_data[tag] = None
|
|
182
|
-
if tag == 'op_ins_clave':
|
|
183
|
-
orden_data['op_ins_clave_ord'] = element.text
|
|
195
|
+
cls._process_xml_element(element, orden_data)
|
|
184
196
|
|
|
185
197
|
return cls(**orden_data)
|
|
198
|
+
|
|
199
|
+
@classmethod
|
|
200
|
+
def _process_xml_element(
|
|
201
|
+
cls,
|
|
202
|
+
element: _Element,
|
|
203
|
+
orden_data: Dict[str, Any],
|
|
204
|
+
) -> None:
|
|
205
|
+
"""Process a single XML element and update orden_data."""
|
|
206
|
+
if not element.text:
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
tag = to_snake_case(element.tag)
|
|
210
|
+
stripped = _WHITESPACE_PATTERN.sub(' ', element.text.strip())
|
|
211
|
+
|
|
212
|
+
if tag == 'op_ins_clave':
|
|
213
|
+
orden_data['op_ins_clave_ord'] = stripped
|
|
214
|
+
return
|
|
215
|
+
|
|
216
|
+
if tag == 'op_firma_dig':
|
|
217
|
+
orden_data['op_firma_dig'] = stripped
|
|
218
|
+
return
|
|
219
|
+
|
|
220
|
+
if tag in cls.__fields__:
|
|
221
|
+
orden_data[tag] = cls._process_text(stripped, tag)
|
|
222
|
+
|
|
223
|
+
@classmethod
|
|
224
|
+
def _process_text(cls, text: str, tag: str) -> Optional[str]:
|
|
225
|
+
"""Process and validate the text content of an XML element."""
|
|
226
|
+
try:
|
|
227
|
+
return validate_alphanumeric(text)
|
|
228
|
+
except ValueError as error:
|
|
229
|
+
raise ValueError(f'{error} in {tag}') from error
|
|
@@ -4,7 +4,7 @@ from lxml import etree
|
|
|
4
4
|
from pydantic.v1 import BaseModel
|
|
5
5
|
|
|
6
6
|
from spei import types
|
|
7
|
-
from spei.utils import
|
|
7
|
+
from spei.utils import to_pascal_case, to_snake_case # noqa: WPS347
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class DataDict(TypedDict, total=False):
|
|
@@ -30,7 +30,7 @@ class Respuesta(BaseModel):
|
|
|
30
30
|
|
|
31
31
|
for element, value in self.dict(exclude={'categoria'}).items(): # noqa: WPS110
|
|
32
32
|
if element in self.__fields__:
|
|
33
|
-
upper_camel_case_element =
|
|
33
|
+
upper_camel_case_element = to_pascal_case(element)
|
|
34
34
|
subelement = etree.SubElement(respuesta, upper_camel_case_element)
|
|
35
35
|
subelement.text = str(value)
|
|
36
36
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# From “APÉNDICE B: TABLA DE CARACTERES VÁLIDOS Y CÓDIGOS ASCII RESPECTIVOS”
|
|
2
|
+
# in SPEI Manual.
|
|
3
|
+
VALID_CHARACTERS = frozenset(
|
|
4
|
+
(
|
|
5
|
+
' ',
|
|
6
|
+
'!',
|
|
7
|
+
'"',
|
|
8
|
+
'#',
|
|
9
|
+
'$',
|
|
10
|
+
'%',
|
|
11
|
+
'&',
|
|
12
|
+
"'",
|
|
13
|
+
'(',
|
|
14
|
+
')',
|
|
15
|
+
'*',
|
|
16
|
+
'+',
|
|
17
|
+
',',
|
|
18
|
+
'-',
|
|
19
|
+
'.',
|
|
20
|
+
'/',
|
|
21
|
+
'0',
|
|
22
|
+
'1',
|
|
23
|
+
'2',
|
|
24
|
+
'3',
|
|
25
|
+
'4',
|
|
26
|
+
'5',
|
|
27
|
+
'6',
|
|
28
|
+
'7',
|
|
29
|
+
'8',
|
|
30
|
+
'9',
|
|
31
|
+
':',
|
|
32
|
+
';',
|
|
33
|
+
'?',
|
|
34
|
+
'@',
|
|
35
|
+
'A',
|
|
36
|
+
'B',
|
|
37
|
+
'C',
|
|
38
|
+
'D',
|
|
39
|
+
'E',
|
|
40
|
+
'F',
|
|
41
|
+
'G',
|
|
42
|
+
'H',
|
|
43
|
+
'I',
|
|
44
|
+
'J',
|
|
45
|
+
'K',
|
|
46
|
+
'L',
|
|
47
|
+
'M',
|
|
48
|
+
'N',
|
|
49
|
+
'O',
|
|
50
|
+
'P',
|
|
51
|
+
'Q',
|
|
52
|
+
'R',
|
|
53
|
+
'S',
|
|
54
|
+
'T',
|
|
55
|
+
'U',
|
|
56
|
+
'V',
|
|
57
|
+
'W',
|
|
58
|
+
'X',
|
|
59
|
+
'Y',
|
|
60
|
+
'Z',
|
|
61
|
+
'\\',
|
|
62
|
+
'_',
|
|
63
|
+
'a',
|
|
64
|
+
'b',
|
|
65
|
+
'c',
|
|
66
|
+
'd',
|
|
67
|
+
'e',
|
|
68
|
+
'f',
|
|
69
|
+
'g',
|
|
70
|
+
'h',
|
|
71
|
+
'i',
|
|
72
|
+
'j',
|
|
73
|
+
'k',
|
|
74
|
+
'l',
|
|
75
|
+
'm',
|
|
76
|
+
'n',
|
|
77
|
+
'o',
|
|
78
|
+
'p',
|
|
79
|
+
'q',
|
|
80
|
+
'r',
|
|
81
|
+
's',
|
|
82
|
+
't',
|
|
83
|
+
'u',
|
|
84
|
+
'v',
|
|
85
|
+
'w',
|
|
86
|
+
'x',
|
|
87
|
+
'y',
|
|
88
|
+
'z',
|
|
89
|
+
'é',
|
|
90
|
+
'á',
|
|
91
|
+
'í',
|
|
92
|
+
'ó',
|
|
93
|
+
'ú',
|
|
94
|
+
'ñ',
|
|
95
|
+
'Ñ',
|
|
96
|
+
'¿',
|
|
97
|
+
'¡',
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def validate_alphanumeric(text: str) -> str:
|
|
103
|
+
if not all(char in VALID_CHARACTERS for char in text):
|
|
104
|
+
invalid_chars = set(text) - VALID_CHARACTERS
|
|
105
|
+
raise ValueError(f'Invalid characters found: {invalid_chars}')
|
|
106
|
+
|
|
107
|
+
return text
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from typing import Optional, Tuple, Type
|
|
2
|
+
from typing import Any, Dict, Optional, Tuple, Type
|
|
3
3
|
from urllib.parse import urljoin
|
|
4
4
|
|
|
5
5
|
import requests
|
|
@@ -20,28 +20,36 @@ class BaseClient(object):
|
|
|
20
20
|
http_client: Type[requests.Session] = requests.Session,
|
|
21
21
|
auth: Optional[Tuple[str, str]] = None,
|
|
22
22
|
) -> None:
|
|
23
|
-
self.host
|
|
24
|
-
self.session
|
|
25
|
-
self.session.headers.update(
|
|
23
|
+
self.host = host
|
|
24
|
+
self.session = http_client()
|
|
25
|
+
self.session.headers.update(
|
|
26
|
+
{
|
|
27
|
+
'Content-Type': 'application/xml; charset=cp850',
|
|
28
|
+
'User-Agent': 'Fondeadora/SICE/v0.52.0',
|
|
29
|
+
},
|
|
30
|
+
)
|
|
26
31
|
self.session.verify = verify
|
|
27
32
|
if auth:
|
|
28
33
|
self.session.auth = auth
|
|
29
34
|
|
|
30
35
|
def registra_cda(
|
|
31
36
|
self,
|
|
32
|
-
cda_data:
|
|
37
|
+
cda_data: Dict[str, Any],
|
|
33
38
|
cda_cls: Type[CDA] = CDA,
|
|
34
39
|
acuse_response_cls: Type[AcuseResponse] = AcuseResponse,
|
|
35
40
|
endpoint: str = '/enlace-cep/EnvioCdaPortTypeImpl?wsdl',
|
|
36
41
|
) -> AcuseResponse:
|
|
37
42
|
orden = cda_cls(**cda_data)
|
|
38
|
-
soap_request = CDARequest(orden)
|
|
43
|
+
soap_request = CDARequest(orden).to_string()
|
|
39
44
|
logger.info(soap_request)
|
|
40
|
-
|
|
41
|
-
response
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
response = self._make_request(soap_request, endpoint)
|
|
47
|
+
return acuse_response_cls(response.text)
|
|
48
|
+
|
|
49
|
+
def _make_request(self, soap_request: bytes, endpoint: str) -> requests.Response:
|
|
50
|
+
url = urljoin(self.host, endpoint)
|
|
51
|
+
response = self.session.post(data=soap_request, url=url)
|
|
45
52
|
logger.info(response.text)
|
|
46
53
|
response.raise_for_status()
|
|
47
|
-
|
|
54
|
+
|
|
55
|
+
return response
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
_SNAKE_CASE_PATTERN = re.compile('(.)([A-Z0-9])')
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def to_pascal_case(string: str) -> str:
|
|
7
|
+
temp = string.split('_')
|
|
8
|
+
new_string = [ele.title() for ele in temp]
|
|
9
|
+
|
|
10
|
+
return ''.join(new_string)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def to_camel_case(string: str) -> str:
|
|
14
|
+
return to_pascal_case(string)[0].lower() + to_pascal_case(string)[1:] # noqa: E501, WPS221
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def to_snake_case(string: str) -> str:
|
|
18
|
+
return _SNAKE_CASE_PATTERN.sub(r'\1_\2', str(string)).lower()
|
spei_python-0.53.0/spei/utils.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|