spei-python 0.23.0__tar.gz → 0.25.0__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.
Files changed (29) hide show
  1. {spei_python-0.23.0 → spei_python-0.25.0}/PKG-INFO +1 -1
  2. {spei_python-0.23.0 → spei_python-0.25.0}/pyproject.toml +2 -2
  3. spei_python-0.25.0/spei/cep_generator.py +81 -0
  4. spei_python-0.25.0/spei/resources/acuse.py +72 -0
  5. spei_python-0.25.0/spei/responses/acuse.py +22 -0
  6. {spei_python-0.23.0 → spei_python-0.25.0}/spei/types.py +7 -0
  7. spei_python-0.23.0/spei/resources/acuse.py +0 -5
  8. spei_python-0.23.0/spei/responses/acuse.py +0 -29
  9. {spei_python-0.23.0 → spei_python-0.25.0}/README.md +0 -0
  10. {spei_python-0.23.0 → spei_python-0.25.0}/spei/README.md +0 -0
  11. {spei_python-0.23.0 → spei_python-0.25.0}/spei/__init__.py +0 -0
  12. {spei_python-0.23.0 → spei_python-0.25.0}/spei/client.py +0 -0
  13. {spei_python-0.23.0 → spei_python-0.25.0}/spei/errors.py +0 -0
  14. {spei_python-0.23.0 → spei_python-0.25.0}/spei/mappings.py +0 -0
  15. {spei_python-0.23.0 → spei_python-0.25.0}/spei/requests/__init__.py +0 -0
  16. {spei_python-0.23.0 → spei_python-0.25.0}/spei/requests/cda.py +0 -0
  17. {spei_python-0.23.0 → spei_python-0.25.0}/spei/requests/orden.py +0 -0
  18. {spei_python-0.23.0 → spei_python-0.25.0}/spei/requests/respuesta.py +0 -0
  19. {spei_python-0.23.0 → spei_python-0.25.0}/spei/resources/__init__.py +0 -0
  20. {spei_python-0.23.0 → spei_python-0.25.0}/spei/resources/cda.py +0 -0
  21. {spei_python-0.23.0 → spei_python-0.25.0}/spei/resources/mensaje.py +0 -0
  22. {spei_python-0.23.0 → spei_python-0.25.0}/spei/resources/orden.py +0 -0
  23. {spei_python-0.23.0 → spei_python-0.25.0}/spei/resources/respuesta.py +0 -0
  24. {spei_python-0.23.0 → spei_python-0.25.0}/spei/responses/__init__.py +0 -0
  25. {spei_python-0.23.0 → spei_python-0.25.0}/spei/responses/orden.py +0 -0
  26. {spei_python-0.23.0 → spei_python-0.25.0}/spei/responses/respuesta.py +0 -0
  27. {spei_python-0.23.0 → spei_python-0.25.0}/spei/sice.py +0 -0
  28. {spei_python-0.23.0 → spei_python-0.25.0}/spei/utils.py +0 -0
  29. {spei_python-0.23.0 → spei_python-0.25.0}/spei/validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spei-python
3
- Version: 0.23.0
3
+ Version: 0.25.0
4
4
  Summary:
5
5
  Author: tech
6
6
  Author-email: tech@fondeadora.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "spei-python"
3
- version = "0.23.0"
3
+ version = "0.25.0"
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.23.0"
35
+ version = "0.25.0"
36
36
  tag_format = "v$version"
37
37
  bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
38
38
  version_files = [
@@ -0,0 +1,81 @@
1
+ import base64
2
+ import datetime
3
+ from enum import Enum
4
+ from os import urandom
5
+
6
+ from cryptography.hazmat.backends import default_backend
7
+ from cryptography.hazmat.primitives import padding
8
+ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
9
+
10
+ IV_LIMIT = 16
11
+
12
+
13
+ class SearchCriteria(Enum):
14
+ TRACKING_CODE = 'T'
15
+ REFERENCE_NUMBER = 'R'
16
+
17
+
18
+ class CepGenerator(object):
19
+ def __init__(self, key_base64, rng=urandom):
20
+ self.key_base64 = key_base64
21
+ self.rng = rng
22
+
23
+ def generate_cep(
24
+ self,
25
+ date: datetime.datetime,
26
+ search_criteria: SearchCriteria,
27
+ search_value: str,
28
+ origin_bank_code: str,
29
+ receiver_bank_code: str,
30
+ account_number: str,
31
+ amount: float,
32
+ ) -> str:
33
+ formatted_date = self._format_date(date)
34
+ string = '{0}|{1}|{2}|{3}|{4}|{5}|{6}'.format(
35
+ formatted_date,
36
+ search_criteria.value,
37
+ search_value,
38
+ origin_bank_code,
39
+ receiver_bank_code,
40
+ account_number,
41
+ amount,
42
+ )
43
+
44
+ return self._encrypt_string(string)
45
+
46
+ def decrypt_string(self, encrypted_data_base64: str) -> str: # noqa: WPS210
47
+ backend = default_backend()
48
+ encrypted_data = base64.b64decode(encrypted_data_base64)
49
+ iv = encrypted_data[:IV_LIMIT]
50
+ cipher = Cipher(
51
+ algorithms.AES(base64.b64decode(self.key_base64)),
52
+ modes.CBC(iv),
53
+ backend=backend,
54
+ )
55
+ decryptor = cipher.decryptor()
56
+ decrypted_data = decryptor.update(
57
+ encrypted_data[IV_LIMIT:],
58
+ ) + decryptor.finalize()
59
+ unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
60
+ unpadded_data = unpadder.update(decrypted_data) + unpadder.finalize()
61
+
62
+ return unpadded_data.decode()
63
+
64
+ def _format_date(self, date: datetime.datetime) -> str:
65
+ return date.strftime('%Y%m%d')
66
+
67
+ def _encrypt_string(self, string: str) -> str: # noqa: WPS210
68
+ backend = default_backend()
69
+ iv = self.rng(IV_LIMIT)
70
+ cipher = Cipher(
71
+ algorithms.AES(base64.b64decode(self.key_base64)),
72
+ modes.CBC(iv),
73
+ backend=backend,
74
+ )
75
+ encryptor = cipher.encryptor()
76
+ padder = padding.PKCS7(algorithms.AES.block_size).padder()
77
+ padded_data = padder.update(string.encode()) + padder.finalize()
78
+ encrypted_data = encryptor.update(padded_data) + encryptor.finalize()
79
+ encrypted_data_base64 = base64.b64encode(iv + encrypted_data)
80
+
81
+ return encrypted_data_base64.decode()
@@ -0,0 +1,72 @@
1
+ from pydantic import BaseModel
2
+
3
+ from spei.types import CodigoErrorAcuse, TipoRespuestaAcuse
4
+ from spei.utils import to_snake_case # noqa: WPS347
5
+
6
+
7
+ class Resultado(BaseModel):
8
+ codigo: CodigoErrorAcuse
9
+ descripcion: str
10
+
11
+ class Config: # noqa: WPS306, WPS431
12
+ use_enum_values = True
13
+
14
+
15
+ class Acuse(BaseModel):
16
+ cda_id: str
17
+ mensaje_id: str
18
+ tipo_respuesta: TipoRespuestaAcuse
19
+ resultado_enlace_cep: Resultado
20
+ resultado_banxico: Resultado
21
+
22
+ class Config: # noqa: WPS306, WPS431
23
+ use_enum_values = True
24
+
25
+ @classmethod
26
+ def parse_xml(cls, mensaje_element):
27
+ acuse_element = mensaje_element.find('acuse')
28
+
29
+ cda_data = cls._find_mensaje_attributes(mensaje_element, acuse_element)
30
+ enlace_cep_data = cls._find_enlace_cep_attributes(acuse_element)
31
+ banxico_data = cls._find_banxico_attributes(acuse_element)
32
+
33
+ return cls._build_acuse(acuse_element, cda_data, enlace_cep_data, banxico_data)
34
+
35
+ @classmethod
36
+ def _find_enlace_cep_attributes(cls, acuse_element):
37
+ resultado_element = acuse_element.find('resultadoEnlaceCep')
38
+ return {
39
+ 'codigo': resultado_element.attrib['codigo'],
40
+ 'descripcion': resultado_element.attrib['descripcion'],
41
+ }
42
+
43
+ @classmethod
44
+ def _find_banxico_attributes(cls, acuse_element):
45
+ resultado_element = acuse_element.find('resultadoBanxico')
46
+ return {
47
+ 'codigo': resultado_element.attrib['codigo'],
48
+ 'descripcion': resultado_element.attrib['descripcion'],
49
+ }
50
+
51
+ @classmethod
52
+ def _find_mensaje_attributes(cls, mensaje_element, acuse_element):
53
+ return {
54
+ 'tipo_respuesta': mensaje_element.attrib['tipoRespuesta'],
55
+ 'cda_id': acuse_element.attrib['idCda'],
56
+ 'mensaje_id': acuse_element.attrib['idMensaje'],
57
+ }
58
+
59
+ @classmethod
60
+ def _build_acuse(cls, acuse_element, cda_data, enlace_cep_data, banxico_data):
61
+ for element in acuse_element.getchildren():
62
+ tag = to_snake_case(element.tag)
63
+ if tag == 'resultado_enlace_cep':
64
+ cda_data[tag] = Resultado(**enlace_cep_data)
65
+ continue
66
+ if tag == 'resultado_banxico':
67
+ cda_data[tag] = Resultado(**banxico_data)
68
+ continue
69
+ if tag in cls.__fields__:
70
+ cda_data[tag] = element.text
71
+
72
+ return cls(**cda_data)
@@ -0,0 +1,22 @@
1
+ from lxml import etree
2
+
3
+ from spei.resources import Acuse
4
+
5
+
6
+ class MensajeElement(object):
7
+ def __new__(cls, body):
8
+ return body.find('mensajeRespuestaCDA')
9
+
10
+
11
+ class BodyElement(object):
12
+ def __new__(cls, mensaje):
13
+ return mensaje.find(
14
+ '{http://schemas.xmlsoap.org/soap/envelope/}Body',
15
+ )
16
+
17
+
18
+ class AcuseResponse(object):
19
+ def __new__(cls, acuse, acuse_cls=Acuse):
20
+ mensaje = etree.fromstring(acuse) # noqa: S320
21
+ mensaje_element = MensajeElement(BodyElement((mensaje)))
22
+ return acuse_cls.parse_xml(mensaje_element)
@@ -120,3 +120,10 @@ CodigoError = generate_error_codes()
120
120
 
121
121
  class CodigoErrorAcuse(str, Enum):
122
122
  exitoso = 'EA00'
123
+ envio_banxico = 'EQ00'
124
+ ok = '0'
125
+
126
+
127
+ class TipoRespuestaAcuse(str, Enum):
128
+ sincrona = 'sincrona'
129
+ asincrona = 'asincrona'
@@ -1,5 +0,0 @@
1
- from pydantic import BaseModel
2
-
3
-
4
- class Acuse(BaseModel):
5
- """Acuse XML representation."""
@@ -1,29 +0,0 @@
1
- from lxml import etree
2
-
3
- from spei.resources import Acuse
4
-
5
-
6
- class MensajeElement(object):
7
- def __new__(cls, acuse, acuse_cls: Acuse = Acuse):
8
- mensaje = etree.fromstring( # noqa: S320
9
- bytes(acuse.text, encoding='cp850'),
10
- )
11
- return acuse_cls.parse_xml(mensaje)
12
-
13
-
14
- class AcuseElement(object):
15
- def __new__(cls, body):
16
- return body.find('{http://www.praxis.com.mx/}acuse')
17
-
18
-
19
- class BodyElement(object):
20
- def __new__(cls, mensaje):
21
- return mensaje.find(
22
- '{http://schemas.xmlsoap.org/soap/envelope/}Body',
23
- )
24
-
25
-
26
- class AcuseResponse(object):
27
- def __new__(cls, acuse):
28
- mensaje = etree.fromstring(acuse) # noqa: S320
29
- return MensajeElement(AcuseElement(BodyElement((mensaje))))
File without changes
File without changes
File without changes