spei-python 0.39.0__tar.gz → 0.40.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.
- {spei_python-0.39.0 → spei_python-0.40.0}/PKG-INFO +1 -1
- {spei_python-0.39.0 → spei_python-0.40.0}/pyproject.toml +3 -6
- spei_python-0.40.0/spei/checksum/__init__.py +0 -0
- spei_python-0.40.0/spei/checksum/factory.py +40 -0
- spei_python-0.40.0/spei/checksum/generator.py +134 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/client.py +7 -2
- spei_python-0.40.0/spei/mappings.py +37 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/requests/acuse.py +9 -5
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/acuse.py +31 -19
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/orden.py +4 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/payments.py +64 -0
- spei_python-0.40.0/spei/utils.py +11 -0
- spei_python-0.39.0/spei/mappings.py +0 -37
- spei_python-0.39.0/spei/resources/reversals.py +0 -66
- spei_python-0.39.0/spei/utils.py +0 -171
- {spei_python-0.39.0 → spei_python-0.40.0}/README.md +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/README.md +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/__init__.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/cep_generator.py +0 -0
- /spei_python-0.39.0/spei/types/checksum.py → /spei_python-0.40.0/spei/checksum/types.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/errors/__init__.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/errors/sice.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/errors/spei.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/requests/__init__.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/requests/cda.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/requests/orden.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/requests/respuesta.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/__init__.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/cda.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/mensaje.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/resources/respuesta.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/responses/__init__.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/responses/acuse.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/responses/orden.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/responses/respuesta.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/sice.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/types/__init__.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/types/sice.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/types/spei.py +0 -0
- {spei_python-0.39.0 → spei_python-0.40.0}/spei/validators.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "spei-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.40.0"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["tech <tech@fondeadora.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -21,13 +21,10 @@ expects = "^0.9.0"
|
|
|
21
21
|
Faker = "^13.12.0"
|
|
22
22
|
isort = "^5.10.1"
|
|
23
23
|
mamba = "^0.11.2"
|
|
24
|
-
wemake-python-styleguide = "^0.
|
|
24
|
+
wemake-python-styleguide = "^0.18.0"
|
|
25
25
|
pyformat = "^0.7"
|
|
26
26
|
mypy = "^0.960"
|
|
27
27
|
|
|
28
|
-
[tool.poetry.group.dev.dependencies]
|
|
29
|
-
wemake-python-styleguide = "^0.18.0"
|
|
30
|
-
|
|
31
28
|
[build-system]
|
|
32
29
|
requires = ["poetry-core>=1.0.0"]
|
|
33
30
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -35,7 +32,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
35
32
|
|
|
36
33
|
[tool.commitizen]
|
|
37
34
|
name = "cz_conventional_commits"
|
|
38
|
-
version = "0.
|
|
35
|
+
version = "0.40.0"
|
|
39
36
|
tag_format = "v$version"
|
|
40
37
|
bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
|
|
41
38
|
version_files = [
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from spei.checksum.generator import (
|
|
2
|
+
ChecksumGenerator,
|
|
3
|
+
ChecksumGeneratorBeneficiary,
|
|
4
|
+
ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary,
|
|
5
|
+
ChecksumGeneratorDefault,
|
|
6
|
+
ChecksumGeneratorEveryField,
|
|
7
|
+
ChecksumGeneratorOrigin,
|
|
8
|
+
ChecksumGeneratorOriginAndBeneficiary,
|
|
9
|
+
)
|
|
10
|
+
from spei.checksum.types import (
|
|
11
|
+
PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT,
|
|
12
|
+
PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
13
|
+
PAYMENT_TYPES_WITH_DEFAULT_FIELDS,
|
|
14
|
+
PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT,
|
|
15
|
+
PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT,
|
|
16
|
+
PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
17
|
+
)
|
|
18
|
+
from spei.types import TipoPagoOrdenPago
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_checksum_generator(payment_type: TipoPagoOrdenPago) -> ChecksumGenerator: # noqa: C901, WPS212, E501
|
|
22
|
+
if payment_type in PAYMENT_TYPES_WITH_DEFAULT_FIELDS:
|
|
23
|
+
return ChecksumGeneratorDefault()
|
|
24
|
+
|
|
25
|
+
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT:
|
|
26
|
+
return ChecksumGeneratorOrigin()
|
|
27
|
+
|
|
28
|
+
if payment_type in PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT:
|
|
29
|
+
return ChecksumGeneratorBeneficiary()
|
|
30
|
+
|
|
31
|
+
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT:
|
|
32
|
+
return ChecksumGeneratorOriginAndBeneficiary()
|
|
33
|
+
|
|
34
|
+
if payment_type in PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT: # noqa: E501
|
|
35
|
+
return ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary()
|
|
36
|
+
|
|
37
|
+
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT: # noqa: E501
|
|
38
|
+
return ChecksumGeneratorEveryField()
|
|
39
|
+
|
|
40
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from decimal import Decimal
|
|
3
|
+
from typing import Any, AnyStr, Dict, List
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ChecksumGenerator(object):
|
|
7
|
+
def format_data(self):
|
|
8
|
+
raise NotImplementedError
|
|
9
|
+
|
|
10
|
+
def split_amount(self, amount):
|
|
11
|
+
amount_as_cents = int(Decimal(str(amount)) * 100)
|
|
12
|
+
high = 0
|
|
13
|
+
low = amount_as_cents
|
|
14
|
+
tens_of_millons = amount_as_cents // 10**9
|
|
15
|
+
if tens_of_millons:
|
|
16
|
+
high = tens_of_millons
|
|
17
|
+
low = amount_as_cents - (tens_of_millons * 10**9)
|
|
18
|
+
return high, low
|
|
19
|
+
|
|
20
|
+
def _fecha_to_bytearray(self, fecha_operacion: int) -> bytearray:
|
|
21
|
+
fecha_operacion = datetime.strptime(str(fecha_operacion), '%Y%m%d')
|
|
22
|
+
|
|
23
|
+
day = int.to_bytes(int(fecha_operacion.day), 1, 'big')
|
|
24
|
+
month = int.to_bytes(int(fecha_operacion.month), 1, 'big')
|
|
25
|
+
year = int.to_bytes(int(fecha_operacion.year), 2, 'big')
|
|
26
|
+
return day + month + year
|
|
27
|
+
|
|
28
|
+
def _clave_to_bytearray(self, clave: str) -> bytearray:
|
|
29
|
+
return int.to_bytes(int(clave), 4, 'big')
|
|
30
|
+
|
|
31
|
+
def _monto_to_bytearray(self, amount: int) -> bytearray:
|
|
32
|
+
high, low = self.split_amount(amount)
|
|
33
|
+
high = int.to_bytes(int(high), 4, 'big')
|
|
34
|
+
low = int.to_bytes(int(low), 4, 'big')
|
|
35
|
+
return high + low
|
|
36
|
+
|
|
37
|
+
def _to_byte_array(
|
|
38
|
+
self,
|
|
39
|
+
value: str, # noqa: WPS110
|
|
40
|
+
add_zero_byte: bool = False,
|
|
41
|
+
) -> bytearray:
|
|
42
|
+
encoded = value.encode('utf-8')
|
|
43
|
+
bytes_ = bytearray(encoded)
|
|
44
|
+
if add_zero_byte:
|
|
45
|
+
bytes_.append(0)
|
|
46
|
+
return bytes_
|
|
47
|
+
|
|
48
|
+
def _list_to_bytes(self, message_data: List[Any]) -> bytes:
|
|
49
|
+
res = bytearray()
|
|
50
|
+
for field in message_data:
|
|
51
|
+
for element in field:
|
|
52
|
+
res.append(element)
|
|
53
|
+
return bytes(res)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ChecksumGeneratorDefault(ChecksumGenerator):
|
|
57
|
+
def format_data(self, message: Dict[AnyStr, Any]):
|
|
58
|
+
message_data = (
|
|
59
|
+
self._fecha_to_bytearray(message['op_fecha_oper']),
|
|
60
|
+
self._clave_to_bytearray(message['op_ins_clave_ord']),
|
|
61
|
+
self._clave_to_bytearray(message['op_ins_clave_ben']),
|
|
62
|
+
self._to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
63
|
+
self._monto_to_bytearray(message['op_monto']),
|
|
64
|
+
)
|
|
65
|
+
return self._list_to_bytes(message_data)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ChecksumGeneratorOrigin(ChecksumGenerator):
|
|
69
|
+
def format_data(self, message: Dict[AnyStr, Any]):
|
|
70
|
+
message_data = (
|
|
71
|
+
self._fecha_to_bytearray(message['op_fecha_oper']),
|
|
72
|
+
self._clave_to_bytearray(message['op_ins_clave_ord']),
|
|
73
|
+
self._clave_to_bytearray(message['op_ins_clave_ben']),
|
|
74
|
+
self._to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
75
|
+
self._monto_to_bytearray(message['op_monto']),
|
|
76
|
+
self._to_byte_array(message['op_cuenta_ord'], add_zero_byte=True),
|
|
77
|
+
)
|
|
78
|
+
return self._list_to_bytes(message_data)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class ChecksumGeneratorBeneficiary(ChecksumGenerator):
|
|
82
|
+
def format_data(self, message: Dict[AnyStr, Any]):
|
|
83
|
+
message_data = (
|
|
84
|
+
self._fecha_to_bytearray(message['op_fecha_oper']),
|
|
85
|
+
self._clave_to_bytearray(message['op_ins_clave_ord']),
|
|
86
|
+
self._clave_to_bytearray(message['op_ins_clave_ben']),
|
|
87
|
+
self._to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
88
|
+
self._monto_to_bytearray(message['op_monto']),
|
|
89
|
+
self._to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
90
|
+
)
|
|
91
|
+
return self._list_to_bytes(message_data)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class ChecksumGeneratorOriginAndBeneficiary(ChecksumGenerator):
|
|
95
|
+
def format_data(self, message: Dict[AnyStr, Any]):
|
|
96
|
+
message_data = (
|
|
97
|
+
self._fecha_to_bytearray(message['op_fecha_oper']),
|
|
98
|
+
self._clave_to_bytearray(message['op_ins_clave_ord']),
|
|
99
|
+
self._clave_to_bytearray(message['op_ins_clave_ben']),
|
|
100
|
+
self._to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
101
|
+
self._monto_to_bytearray(message['op_monto']),
|
|
102
|
+
self._to_byte_array(message['op_cuenta_ord'], add_zero_byte=True),
|
|
103
|
+
self._to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
104
|
+
)
|
|
105
|
+
return self._list_to_bytes(message_data)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary(ChecksumGenerator):
|
|
109
|
+
def format_data(self, message: Dict[AnyStr, Any]):
|
|
110
|
+
message_data = (
|
|
111
|
+
self._fecha_to_bytearray(message['op_fecha_oper']),
|
|
112
|
+
self._clave_to_bytearray(message['op_ins_clave_ord']),
|
|
113
|
+
self._clave_to_bytearray(message['op_ins_clave_ben']),
|
|
114
|
+
self._to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
115
|
+
self._monto_to_bytearray(message['op_monto']),
|
|
116
|
+
self._to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
117
|
+
self._to_byte_array(message['op_cuenta_ben_2'], add_zero_byte=True),
|
|
118
|
+
)
|
|
119
|
+
return self._list_to_bytes(message_data)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class ChecksumGeneratorEveryField(ChecksumGenerator):
|
|
123
|
+
def format_data(self, message: Dict[AnyStr, Any]):
|
|
124
|
+
message_data = (
|
|
125
|
+
self._fecha_to_bytearray(message['op_fecha_oper']),
|
|
126
|
+
self._clave_to_bytearray(message['op_ins_clave_ord']),
|
|
127
|
+
self._clave_to_bytearray(message['op_ins_clave_ben']),
|
|
128
|
+
self._to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
129
|
+
self._monto_to_bytearray(message['op_monto']),
|
|
130
|
+
self._to_byte_array(message['op_cuenta_ord'], add_zero_byte=True),
|
|
131
|
+
self._to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
132
|
+
self._to_byte_array(message['op_cuenta_ben_2'], add_zero_byte=True),
|
|
133
|
+
)
|
|
134
|
+
return self._list_to_bytes(message_data)
|
|
@@ -7,10 +7,10 @@ from cryptography.hazmat.primitives import serialization
|
|
|
7
7
|
from cryptography.hazmat.primitives.asymmetric import padding
|
|
8
8
|
from cryptography.hazmat.primitives.hashes import SHA256
|
|
9
9
|
|
|
10
|
+
from spei.checksum.factory import get_checksum_generator
|
|
10
11
|
from spei.requests import OrdenRequest
|
|
11
12
|
from spei.resources import Orden
|
|
12
13
|
from spei.responses import RespuestaResponse
|
|
13
|
-
from spei.utils import format_data
|
|
14
14
|
|
|
15
15
|
logger = logging.getLogger('spei')
|
|
16
16
|
logger.setLevel(logging.DEBUG)
|
|
@@ -26,6 +26,7 @@ class BaseClient(object):
|
|
|
26
26
|
password,
|
|
27
27
|
verify=False,
|
|
28
28
|
http_client=requests,
|
|
29
|
+
checksum_generator_factory=get_checksum_generator,
|
|
29
30
|
):
|
|
30
31
|
self.priv_key = priv_key
|
|
31
32
|
self.priv_key_passphrase = priv_key_passphrase or None
|
|
@@ -44,8 +45,12 @@ class BaseClient(object):
|
|
|
44
45
|
default_backend(),
|
|
45
46
|
)
|
|
46
47
|
|
|
48
|
+
self.checksum_generator_factory = checksum_generator_factory
|
|
49
|
+
|
|
47
50
|
def generate_checksum(self, message_data):
|
|
48
|
-
|
|
51
|
+
generator = self.checksum_generator_factory(message_data['op_tp_clave'])
|
|
52
|
+
|
|
53
|
+
message_as_bytes = generator.format_data(message_data)
|
|
49
54
|
|
|
50
55
|
signed_message = self.pkey.sign(
|
|
51
56
|
message_as_bytes,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from types import MappingProxyType
|
|
2
|
+
|
|
3
|
+
from spei.resources import payments
|
|
4
|
+
from spei.types import CategoriaOrdenPago, TipoPagoOrdenPago
|
|
5
|
+
|
|
6
|
+
ORDEN_RESPONSES = MappingProxyType({
|
|
7
|
+
CategoriaOrdenPago.odps_liquidadas_abonos: CategoriaOrdenPago.odps_liquidadas_abonos_respuesta, # noqa: E501
|
|
8
|
+
CategoriaOrdenPago.odps_liquidadas_cargos: CategoriaOrdenPago.odps_liquidadas_cargos_respuesta, # noqa: E501
|
|
9
|
+
CategoriaOrdenPago.odps_canceladas_local: CategoriaOrdenPago.odps_canceladas_local_respuesta, # noqa: E501
|
|
10
|
+
CategoriaOrdenPago.odps_canceladas_x_banxico: CategoriaOrdenPago.odps_canceladas_x_banxico_respuesta, # noqa: E501
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
ORDEN_PAYMENT_TYPES = MappingProxyType({
|
|
14
|
+
TipoPagoOrdenPago.devolucion_no_acreditada: payments.DevolucionNoAcreditada,
|
|
15
|
+
TipoPagoOrdenPago.tercero_a_tercero: payments.TerceroATercero,
|
|
16
|
+
TipoPagoOrdenPago.tercero_a_ventanilla: payments.TerceroAVentilla,
|
|
17
|
+
TipoPagoOrdenPago.tercero_a_tercero_vostro: payments.TerceroATerceroVostro,
|
|
18
|
+
TipoPagoOrdenPago.tercero_a_participante: payments.TerceroAParticipante,
|
|
19
|
+
TipoPagoOrdenPago.participante_a_tercero: payments.ParticipanteATercero,
|
|
20
|
+
TipoPagoOrdenPago.participante_a_tercero_vostro: payments.ParticipanteATerceroVostro,
|
|
21
|
+
TipoPagoOrdenPago.participante_a_participante: payments.ParticipanteAParticipante,
|
|
22
|
+
TipoPagoOrdenPago.tercero_a_tercero_fsw: payments.TerceroATerceroFSW,
|
|
23
|
+
TipoPagoOrdenPago.tercero_a_tercero_vostro_fsw: payments.TerceroATerceroVostroFSW,
|
|
24
|
+
TipoPagoOrdenPago.participante_a_tercero_fsw: payments.ParticipanteATerceroFSW,
|
|
25
|
+
TipoPagoOrdenPago.participante_a_tercero_vostro_fsw: payments.TerceroATerceroFSW,
|
|
26
|
+
TipoPagoOrdenPago.nomina: payments.Nomina,
|
|
27
|
+
TipoPagoOrdenPago.pago_factura: payments.PagoFactura,
|
|
28
|
+
TipoPagoOrdenPago.devolucion_extemporanea_no_acreditada: payments.DevolucionExtemporaneaNoAcreditada,
|
|
29
|
+
TipoPagoOrdenPago.devolucion_acreditada: payments.DevolucionAcreditada,
|
|
30
|
+
TipoPagoOrdenPago.devolucion_extemporanea_acreditada: payments.DevolucionExtemporaneaAcreditada,
|
|
31
|
+
TipoPagoOrdenPago.cobros_presenciales_de_una_ocasion: payments.CobrosPresencialesUnaOcasion,
|
|
32
|
+
TipoPagoOrdenPago.cobros_no_presenciales_de_una_ocasion: payments.CobrosNoPresencialesUnaOcasion,
|
|
33
|
+
TipoPagoOrdenPago.cobros_no_presenciales_recurrentes: payments.CobrosNoPresencialesRecurrentes,
|
|
34
|
+
TipoPagoOrdenPago.cobros_no_presenciales_a_nombre_de_tercero: payments.CobrosNoPresencialesNoRecurrentesTercero,
|
|
35
|
+
TipoPagoOrdenPago.devolucion_especial_acreditada: payments.DevolucionEspecialAcreditada,
|
|
36
|
+
TipoPagoOrdenPago.devolucion_extemporanea_especial_acreditada: payments.DevolucionEspecialAcreditada,
|
|
37
|
+
})
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
1
3
|
from lxml import etree
|
|
2
4
|
|
|
3
5
|
from spei.resources import Acuse
|
|
6
|
+
from spei.types.sice import TipoRespuestaAcuse
|
|
4
7
|
|
|
5
8
|
SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
|
|
6
9
|
XML_SCHEMA_NS = 'http://www.w3.org/2001/XMLSchema'
|
|
@@ -9,12 +12,13 @@ XML_XSD_NS = 'http://www.w3.org/2001/XMLSchema-instance'
|
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
class MensajeElement(object):
|
|
12
|
-
def __new__(cls,
|
|
15
|
+
def __new__(cls, acuses: List[Acuse], tipo_respuesta: TipoRespuestaAcuse):
|
|
13
16
|
mensaje = etree.Element(
|
|
14
17
|
'mensajeRespuestaCDA',
|
|
15
|
-
tipoRespuesta=
|
|
18
|
+
tipoRespuesta=tipo_respuesta,
|
|
16
19
|
)
|
|
17
|
-
|
|
20
|
+
for acuse in acuses:
|
|
21
|
+
mensaje.append(acuse.build_xml())
|
|
18
22
|
return mensaje
|
|
19
23
|
|
|
20
24
|
|
|
@@ -57,8 +61,8 @@ class EnvelopeElement(object):
|
|
|
57
61
|
|
|
58
62
|
|
|
59
63
|
class AcuseRequest(object):
|
|
60
|
-
def __new__(cls,
|
|
61
|
-
respuesta_element = RespuestaElement(ReturnElement(MensajeElement(
|
|
64
|
+
def __new__(cls, tipo_respuesta: TipoRespuestaAcuse, acuses: List[Acuse] = (), as_string=True): # noqa: E501
|
|
65
|
+
respuesta_element = RespuestaElement(ReturnElement(MensajeElement(acuses, tipo_respuesta))) # noqa: E501
|
|
62
66
|
envelope = EnvelopeElement(BodyElement(respuesta_element))
|
|
63
67
|
if not as_string:
|
|
64
68
|
return envelope
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Union
|
|
1
|
+
from typing import Any, Union
|
|
2
2
|
|
|
3
3
|
from lxml import etree
|
|
4
4
|
from pydantic import BaseModel
|
|
@@ -24,9 +24,9 @@ class ResultadoServidor(BaseModel):
|
|
|
24
24
|
use_enum_values = True
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
class MensajeRespuesta(
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
class MensajeRespuesta(BaseModel):
|
|
28
|
+
tipo_respuesta: TipoRespuestaAcuse
|
|
29
|
+
respuesta: Any
|
|
30
30
|
|
|
31
31
|
@classmethod
|
|
32
32
|
def parse_xml(cls, mensaje):
|
|
@@ -42,14 +42,21 @@ class MensajeRespuesta(object):
|
|
|
42
42
|
|
|
43
43
|
xml_element = respuesta_element.find('xml')
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
respuesta = etree.fromstring( # noqa: S320
|
|
46
46
|
bytes(xml_element.text, encoding='utf-8'),
|
|
47
47
|
)
|
|
48
|
+
respuesta_element = respuesta.xpath('//*[local-name()="mensajeRespuestaCDA"]')[0] # noqa: E501
|
|
49
|
+
tipo_respuesta = respuesta_element.attrib['tipoRespuesta']
|
|
50
|
+
|
|
51
|
+
return cls(
|
|
52
|
+
tipo_respuesta=tipo_respuesta,
|
|
53
|
+
respuesta=respuesta_element,
|
|
54
|
+
)
|
|
48
55
|
|
|
49
56
|
|
|
50
57
|
class Acuse(BaseModel):
|
|
51
58
|
cda_id: str
|
|
52
|
-
mensaje_id:
|
|
59
|
+
mensaje_id: Any = None
|
|
53
60
|
tipo_respuesta: TipoRespuestaAcuse
|
|
54
61
|
resultado_enlace_cep: ResultadoServidor
|
|
55
62
|
resultado_banxico: ResultadoBanxico = None
|
|
@@ -59,8 +66,9 @@ class Acuse(BaseModel):
|
|
|
59
66
|
|
|
60
67
|
@classmethod
|
|
61
68
|
def parse_synchronous_xml(cls, mensaje_element):
|
|
69
|
+
tipo_respuesta = mensaje_element.attrib['tipoRespuesta']
|
|
62
70
|
acuse_element = mensaje_element.find('{http://www.praxis.com.mx/EnvioCda/}acuseCda') # noqa: E501
|
|
63
|
-
cda_data = cls._find_mensaje_attributes(
|
|
71
|
+
cda_data = cls._find_mensaje_attributes(acuse_element, tipo_respuesta)
|
|
64
72
|
resultado_element = acuse_element.find('{http://www.praxis.com.mx/EnvioCda/}resultadoEnlaceCep') # noqa: E501
|
|
65
73
|
codigo = resultado_element.find('{http://www.praxis.com.mx/EnvioCda/}codigo')
|
|
66
74
|
descripcion = resultado_element.find('{http://www.praxis.com.mx/EnvioCda/}descripcion') # noqa: E501
|
|
@@ -71,11 +79,17 @@ class Acuse(BaseModel):
|
|
|
71
79
|
return cls._build_acuse(acuse_element, cda_data, enlace_cep_data)
|
|
72
80
|
|
|
73
81
|
def build_xml(self):
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
if self.mensaje_id:
|
|
83
|
+
acuse = etree.Element(
|
|
84
|
+
'acuse',
|
|
85
|
+
idCda=self.cda_id,
|
|
86
|
+
idMensaje=self.mensaje_id,
|
|
87
|
+
)
|
|
88
|
+
else:
|
|
89
|
+
acuse = etree.Element(
|
|
90
|
+
'acuse',
|
|
91
|
+
idCda=self.cda_id,
|
|
92
|
+
)
|
|
79
93
|
|
|
80
94
|
etree.SubElement(
|
|
81
95
|
acuse,
|
|
@@ -101,10 +115,8 @@ class Acuse(BaseModel):
|
|
|
101
115
|
return acuse
|
|
102
116
|
|
|
103
117
|
@classmethod
|
|
104
|
-
def parse_xml(cls,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
cda_data = cls._find_mensaje_attributes(mensaje_element, acuse_element)
|
|
118
|
+
def parse_xml(cls, acuse_element, tipo_respuesta):
|
|
119
|
+
cda_data = cls._find_mensaje_attributes(acuse_element, tipo_respuesta)
|
|
108
120
|
enlace_cep_data = cls._find_enlace_cep_attributes(acuse_element)
|
|
109
121
|
banxico_data = cls._find_banxico_attributes(acuse_element)
|
|
110
122
|
|
|
@@ -127,11 +139,11 @@ class Acuse(BaseModel):
|
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
@classmethod
|
|
130
|
-
def _find_mensaje_attributes(cls,
|
|
142
|
+
def _find_mensaje_attributes(cls, acuse_element, tipo_respuesta):
|
|
131
143
|
return {
|
|
132
|
-
'tipo_respuesta':
|
|
144
|
+
'tipo_respuesta': tipo_respuesta,
|
|
133
145
|
'cda_id': acuse_element.attrib['idCda'],
|
|
134
|
-
'mensaje_id': acuse_element.
|
|
146
|
+
'mensaje_id': acuse_element.get('idMensaje'),
|
|
135
147
|
}
|
|
136
148
|
|
|
137
149
|
@classmethod
|
|
@@ -144,6 +144,10 @@ class Orden(BaseModel):
|
|
|
144
144
|
subelement = etree.SubElement(ordenpago, 'opMontoInteres')
|
|
145
145
|
subelement.text = str(value)
|
|
146
146
|
continue
|
|
147
|
+
if element == 'op_comision_trans':
|
|
148
|
+
subelement = etree.SubElement(ordenpago, 'opComisionTrans')
|
|
149
|
+
subelement.text = str(value)
|
|
150
|
+
continue
|
|
147
151
|
upper_camel_case_element = to_upper_camel_case(element)
|
|
148
152
|
subelement = etree.SubElement(ordenpago, upper_camel_case_element)
|
|
149
153
|
subelement.text = str(value)
|
|
@@ -303,3 +303,67 @@ class CobrosNoPresencialesNoRecurrentesTercero(Orden):
|
|
|
303
303
|
|
|
304
304
|
op_cert_comer_env: int
|
|
305
305
|
op_digito_ver_comer: int
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
class DevolucionNoAcreditada(Orden):
|
|
309
|
+
op_cd_clave = types.TipoDevolucionOrdenPago
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
class DevolucionExtemporaneaNoAcreditada(Orden):
|
|
313
|
+
op_tc_clave_ord: types.TipoCuentaOrdenPago
|
|
314
|
+
op_cuenta_ord: str
|
|
315
|
+
|
|
316
|
+
op_concepto_pag_2: str
|
|
317
|
+
op_ref_numerica: str
|
|
318
|
+
|
|
319
|
+
op_cd_clave: types.TipoDevolucionOrdenPago
|
|
320
|
+
|
|
321
|
+
op_folio_ori: int = None
|
|
322
|
+
paq_folio_ori: int = None
|
|
323
|
+
|
|
324
|
+
op_fecha_oper_ori: int
|
|
325
|
+
op_rastreo_ori: str
|
|
326
|
+
op_monto_intereses: float
|
|
327
|
+
op_monto_ori: float
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class DevolucionAcreditada(Orden):
|
|
331
|
+
op_rastreo_ori: str
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class DevolucionExtemporaneaAcreditada(Orden):
|
|
335
|
+
op_cuenta_ord: str
|
|
336
|
+
|
|
337
|
+
op_concepto_pag_2: str
|
|
338
|
+
op_ref_numerica: str
|
|
339
|
+
|
|
340
|
+
op_folio_ori: int = None
|
|
341
|
+
paq_folio_ori: int = None
|
|
342
|
+
|
|
343
|
+
op_fecha_oper_ori: int
|
|
344
|
+
op_rastreo_ori: str
|
|
345
|
+
op_monto_ori: float
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
class DevolucionEspecialAcreditada(Orden):
|
|
349
|
+
op_rastreo_ori: str
|
|
350
|
+
op_monto_ori: float
|
|
351
|
+
|
|
352
|
+
op_indica_ben_rec: int = None
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
class DevolucionExtemporaneaEspecialAcreditada(Orden):
|
|
356
|
+
op_tc_clave_ord: types.TipoCuentaOrdenPago
|
|
357
|
+
op_cuenta_ord: str
|
|
358
|
+
|
|
359
|
+
op_concepto_pag_2: str
|
|
360
|
+
op_ref_numerica: str
|
|
361
|
+
|
|
362
|
+
op_folio_ori: int = None
|
|
363
|
+
paq_folio_ori: int = None
|
|
364
|
+
|
|
365
|
+
op_fecha_oper_ori: int
|
|
366
|
+
op_rastreo_ori: str
|
|
367
|
+
op_monto_ori: float
|
|
368
|
+
|
|
369
|
+
op_indica_ben_rec: int = None
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
from types import MappingProxyType
|
|
2
|
-
|
|
3
|
-
from spei.resources import orden
|
|
4
|
-
from spei.types import CategoriaOrdenPago, TipoPagoOrdenPago
|
|
5
|
-
|
|
6
|
-
ORDEN_RESPONSES = MappingProxyType({
|
|
7
|
-
CategoriaOrdenPago.odps_liquidadas_abonos: CategoriaOrdenPago.odps_liquidadas_abonos_respuesta, # noqa: E501
|
|
8
|
-
CategoriaOrdenPago.odps_liquidadas_cargos: CategoriaOrdenPago.odps_liquidadas_cargos_respuesta, # noqa: E501
|
|
9
|
-
CategoriaOrdenPago.odps_canceladas_local: CategoriaOrdenPago.odps_canceladas_local_respuesta, # noqa: E501
|
|
10
|
-
CategoriaOrdenPago.odps_canceladas_x_banxico: CategoriaOrdenPago.odps_canceladas_x_banxico_respuesta, # noqa: E501
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
ORDEN_PAYMENT_TYPES = MappingProxyType({
|
|
14
|
-
TipoPagoOrdenPago.devolucion_no_acreditada: orden.DevolucionNoAcreditada,
|
|
15
|
-
TipoPagoOrdenPago.tercero_a_tercero: orden.TerceroATercero,
|
|
16
|
-
TipoPagoOrdenPago.tercero_a_ventanilla: orden.TerceroAVentilla,
|
|
17
|
-
TipoPagoOrdenPago.tercero_a_tercero_vostro: orden.TerceroATerceroVostro,
|
|
18
|
-
TipoPagoOrdenPago.tercero_a_participante: orden.TerceroAParticipante,
|
|
19
|
-
TipoPagoOrdenPago.participante_a_tercero: orden.ParticipanteATercero,
|
|
20
|
-
TipoPagoOrdenPago.participante_a_tercero_vostro: orden.ParticipanteATerceroVostro,
|
|
21
|
-
TipoPagoOrdenPago.participante_a_participante: orden.ParticipanteAParticipante,
|
|
22
|
-
TipoPagoOrdenPago.tercero_a_tercero_fsw: orden.TerceroATerceroFSW,
|
|
23
|
-
TipoPagoOrdenPago.tercero_a_tercero_vostro_fsw: orden.TerceroATerceroVostroFSW,
|
|
24
|
-
TipoPagoOrdenPago.participante_a_tercero_fsw: orden.ParticipanteATerceroFSW,
|
|
25
|
-
TipoPagoOrdenPago.participante_a_tercero_vostro_fsw: orden.TerceroATerceroFSW,
|
|
26
|
-
TipoPagoOrdenPago.nomina: orden.Nomina,
|
|
27
|
-
TipoPagoOrdenPago.pago_factura: orden.PagoFactura,
|
|
28
|
-
TipoPagoOrdenPago.devolucion_extemporanea_no_acreditada: orden.DevolucionExtemporaneaNoAcreditada,
|
|
29
|
-
TipoPagoOrdenPago.devolucion_acreditada: orden.DevolucionAcreditada,
|
|
30
|
-
TipoPagoOrdenPago.devolucion_extemporanea_acreditada: orden.DevolucionExtemporaneaAcreditada,
|
|
31
|
-
TipoPagoOrdenPago.cobros_presenciales_de_una_ocasion: orden.CobrosPresencialesUnaOcasion,
|
|
32
|
-
TipoPagoOrdenPago.cobros_no_presenciales_de_una_ocasion: orden.CobrosNoPresencialesUnaOcasion,
|
|
33
|
-
TipoPagoOrdenPago.cobros_no_presenciales_recurrentes: orden.CobrosNoPresencialesRecurrentes,
|
|
34
|
-
TipoPagoOrdenPago.cobros_no_presenciales_a_nombre_de_tercero: orden.CobrosNoPresencialesNoRecurrentesTercero,
|
|
35
|
-
TipoPagoOrdenPago.devolucion_especial_acreditada: orden.DevolucionEspecialAcreditada,
|
|
36
|
-
TipoPagoOrdenPago.devolucion_extemporanea_especial_acreditada: orden.DevolucionEspecialAcreditada,
|
|
37
|
-
})
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
from spei import types
|
|
2
|
-
from spei.resources.orden import Orden
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class DevolucionNoAcreditada(Orden):
|
|
6
|
-
op_cd_clave = types.TipoDevolucionOrdenPago
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class DevolucionExtemporaneaNoAcreditada(Orden):
|
|
10
|
-
op_tc_clave_ord: types.TipoCuentaOrdenPago
|
|
11
|
-
op_cuenta_ord: str
|
|
12
|
-
|
|
13
|
-
op_concepto_pag_2: str
|
|
14
|
-
op_ref_numerica: str
|
|
15
|
-
|
|
16
|
-
op_cd_clave: types.TipoDevolucionOrdenPago
|
|
17
|
-
|
|
18
|
-
op_folio_ori: int = None
|
|
19
|
-
paq_folio_ori: int = None
|
|
20
|
-
|
|
21
|
-
op_fecha_oper_ori: int
|
|
22
|
-
op_rastreo_ori: str
|
|
23
|
-
op_monto_intereses: float
|
|
24
|
-
op_monto_ori: float
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class DevolucionAcreditada(Orden):
|
|
28
|
-
op_rastreo_ori: str
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class DevolucionExtemporaneaAcreditada(Orden):
|
|
32
|
-
op_cuenta_ord: str
|
|
33
|
-
|
|
34
|
-
op_concepto_pag_2: str
|
|
35
|
-
op_ref_numerica: str
|
|
36
|
-
|
|
37
|
-
op_folio_ori: int = None
|
|
38
|
-
paq_folio_ori: int = None
|
|
39
|
-
|
|
40
|
-
op_fecha_oper_ori: int
|
|
41
|
-
op_rastreo_ori: str
|
|
42
|
-
op_monto_ori: float
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class DevolucionEspecialAcreditada(Orden):
|
|
46
|
-
op_rastreo_ori: str
|
|
47
|
-
op_monto_ori: float
|
|
48
|
-
|
|
49
|
-
op_indica_ben_rec: int = None
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class DevolucionExtemporaneaEspecialAcreditada(Orden):
|
|
53
|
-
op_tc_clave_ord: types.TipoCuentaOrdenPago
|
|
54
|
-
op_cuenta_ord: str
|
|
55
|
-
|
|
56
|
-
op_concepto_pag_2: str
|
|
57
|
-
op_ref_numerica: str
|
|
58
|
-
|
|
59
|
-
op_folio_ori: int = None
|
|
60
|
-
paq_folio_ori: int = None
|
|
61
|
-
|
|
62
|
-
op_fecha_oper_ori: int
|
|
63
|
-
op_rastreo_ori: str
|
|
64
|
-
op_monto_ori: float
|
|
65
|
-
|
|
66
|
-
op_indica_ben_rec: int = None
|
spei_python-0.39.0/spei/utils.py
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from decimal import Decimal
|
|
4
|
-
from typing import Any, AnyStr, Dict, List
|
|
5
|
-
|
|
6
|
-
from spei.types.checksum import (
|
|
7
|
-
PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT,
|
|
8
|
-
PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
9
|
-
PAYMENT_TYPES_WITH_DEFAULT_FIELDS,
|
|
10
|
-
PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT,
|
|
11
|
-
PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT,
|
|
12
|
-
PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def format_data(message: Dict[AnyStr, Any]) -> bytes: # noqa: C901, WPS212
|
|
17
|
-
payment_type = message['op_tp_clave']
|
|
18
|
-
|
|
19
|
-
if payment_type in PAYMENT_TYPES_WITH_DEFAULT_FIELDS:
|
|
20
|
-
return format_default_fields(message=message)
|
|
21
|
-
|
|
22
|
-
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT:
|
|
23
|
-
return _format_origin(message=message)
|
|
24
|
-
|
|
25
|
-
if payment_type in PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT:
|
|
26
|
-
return _format_beneficiary(message=message)
|
|
27
|
-
|
|
28
|
-
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT:
|
|
29
|
-
return _format_origin_beneficiary(message=message)
|
|
30
|
-
|
|
31
|
-
if payment_type in PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT: # noqa: E501
|
|
32
|
-
return _format_beneficiary_and_additional_beneficiary(message=message)
|
|
33
|
-
|
|
34
|
-
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT: # noqa: E501
|
|
35
|
-
return _format_origin_beneficiary_and_additional_beneficiary(message=message)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def _format_origin(message):
|
|
39
|
-
message_data = (
|
|
40
|
-
_fecha_to_bytearray(message['op_fecha_oper']),
|
|
41
|
-
_clave_to_bytearray(message['op_ins_clave_ord']),
|
|
42
|
-
_clave_to_bytearray(message['op_ins_clave_ben']),
|
|
43
|
-
_to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
44
|
-
_monto_to_bytearray(message['op_monto']),
|
|
45
|
-
_to_byte_array(message['op_cuenta_ord'], add_zero_byte=True),
|
|
46
|
-
)
|
|
47
|
-
return _list_to_bytes(message_data)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _format_beneficiary(message):
|
|
51
|
-
message_data = (
|
|
52
|
-
_fecha_to_bytearray(message['op_fecha_oper']),
|
|
53
|
-
_clave_to_bytearray(message['op_ins_clave_ord']),
|
|
54
|
-
_clave_to_bytearray(message['op_ins_clave_ben']),
|
|
55
|
-
_to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
56
|
-
_monto_to_bytearray(message['op_monto']),
|
|
57
|
-
_to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
return _list_to_bytes(message_data)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _format_origin_beneficiary(message):
|
|
64
|
-
message_data = (
|
|
65
|
-
_fecha_to_bytearray(message['op_fecha_oper']),
|
|
66
|
-
_clave_to_bytearray(message['op_ins_clave_ord']),
|
|
67
|
-
_clave_to_bytearray(message['op_ins_clave_ben']),
|
|
68
|
-
_to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
69
|
-
_monto_to_bytearray(message['op_monto']),
|
|
70
|
-
_to_byte_array(message['op_cuenta_ord'], add_zero_byte=True),
|
|
71
|
-
_to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
72
|
-
)
|
|
73
|
-
return _list_to_bytes(message_data)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def format_default_fields(message):
|
|
77
|
-
message_data = (
|
|
78
|
-
_fecha_to_bytearray(message['op_fecha_oper']),
|
|
79
|
-
_clave_to_bytearray(message['op_ins_clave_ord']),
|
|
80
|
-
_clave_to_bytearray(message['op_ins_clave_ben']),
|
|
81
|
-
_to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
82
|
-
_monto_to_bytearray(message['op_monto']),
|
|
83
|
-
)
|
|
84
|
-
return _list_to_bytes(message_data)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def _format_beneficiary_and_additional_beneficiary(message):
|
|
88
|
-
message_data = (
|
|
89
|
-
_fecha_to_bytearray(message['op_fecha_oper']),
|
|
90
|
-
_clave_to_bytearray(message['op_ins_clave_ord']),
|
|
91
|
-
_clave_to_bytearray(message['op_ins_clave_ben']),
|
|
92
|
-
_to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
93
|
-
_monto_to_bytearray(message['op_monto']),
|
|
94
|
-
_to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
95
|
-
_to_byte_array(message['op_cuenta_ben_2'], add_zero_byte=True),
|
|
96
|
-
)
|
|
97
|
-
return _list_to_bytes(message_data)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def _format_origin_beneficiary_and_additional_beneficiary(message):
|
|
101
|
-
message_data = (
|
|
102
|
-
_fecha_to_bytearray(message['op_fecha_oper']),
|
|
103
|
-
_clave_to_bytearray(message['op_ins_clave_ord']),
|
|
104
|
-
_clave_to_bytearray(message['op_ins_clave_ben']),
|
|
105
|
-
_to_byte_array(message['op_cve_rastreo'], add_zero_byte=True),
|
|
106
|
-
_monto_to_bytearray(message['op_monto']),
|
|
107
|
-
_to_byte_array(message['op_cuenta_ord'], add_zero_byte=True),
|
|
108
|
-
_to_byte_array(message['op_cuenta_ben'], add_zero_byte=True),
|
|
109
|
-
_to_byte_array(message['op_cuenta_ben_2'], add_zero_byte=True),
|
|
110
|
-
)
|
|
111
|
-
return _list_to_bytes(message_data)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
def split_amount(amount):
|
|
115
|
-
amount_as_cents = int(Decimal(str(amount)) * 100)
|
|
116
|
-
high = 0
|
|
117
|
-
low = amount_as_cents
|
|
118
|
-
tens_of_millons = amount_as_cents // 10**9
|
|
119
|
-
if tens_of_millons:
|
|
120
|
-
high = tens_of_millons
|
|
121
|
-
low = amount_as_cents - (tens_of_millons * 10**9)
|
|
122
|
-
return high, low
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def _fecha_to_bytearray(fecha_operacion: int) -> bytearray:
|
|
126
|
-
fecha_operacion = datetime.strptime(str(fecha_operacion), '%Y%m%d')
|
|
127
|
-
|
|
128
|
-
day = int.to_bytes(int(fecha_operacion.day), 1, 'big')
|
|
129
|
-
month = int.to_bytes(int(fecha_operacion.month), 1, 'big')
|
|
130
|
-
year = int.to_bytes(int(fecha_operacion.year), 2, 'big')
|
|
131
|
-
return day + month + year
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def _clave_to_bytearray(clave: str) -> bytearray:
|
|
135
|
-
return int.to_bytes(int(clave), 4, 'big')
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def _monto_to_bytearray(amount: int) -> bytearray:
|
|
139
|
-
high, low = split_amount(amount)
|
|
140
|
-
high = int.to_bytes(int(high), 4, 'big')
|
|
141
|
-
low = int.to_bytes(int(low), 4, 'big')
|
|
142
|
-
return high + low
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def _to_byte_array(
|
|
146
|
-
value: str, # noqa: WPS110
|
|
147
|
-
add_zero_byte: bool = False,
|
|
148
|
-
) -> bytearray:
|
|
149
|
-
encoded = value.encode('utf-8')
|
|
150
|
-
bytes_ = bytearray(encoded)
|
|
151
|
-
if add_zero_byte:
|
|
152
|
-
bytes_.append(0)
|
|
153
|
-
return bytes_
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def _list_to_bytes(message_data: List[Any]) -> bytes:
|
|
157
|
-
res = bytearray()
|
|
158
|
-
for field in message_data:
|
|
159
|
-
for element in field:
|
|
160
|
-
res.append(element)
|
|
161
|
-
return bytes(res)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def to_upper_camel_case(string):
|
|
165
|
-
temp = string.split('_')
|
|
166
|
-
new_string = [ele.title() for ele in temp]
|
|
167
|
-
return ''.join(new_string)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def to_snake_case(string):
|
|
171
|
-
return re.sub('(.)([A-Z0-9])', r'\1_\2', str(string)).lower()
|
|
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
|