spei-python 1.0.6__tar.gz → 1.0.7__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-1.0.6 → spei_python-1.0.7}/PKG-INFO +22 -8
- {spei_python-1.0.6 → spei_python-1.0.7}/README.md +19 -6
- {spei_python-1.0.6 → spei_python-1.0.7}/pyproject.toml +2 -2
- spei_python-1.0.7/spei/checksum/factory.py +17 -0
- spei_python-1.0.7/spei/checksum/generator.py +105 -0
- spei_python-1.0.7/spei/checksum/types.py +29 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/client.py +79 -8
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/errors/sice.py +21 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/acuse.py +20 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/orden.py +1 -1
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/responses/__init__.py +0 -2
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/sice.py +9 -6
- spei_python-1.0.7/spei/signature/__init__.py +67 -0
- spei_python-1.0.7/spei/signature/factory.py +71 -0
- spei_python-1.0.6/spei/checksum/generator.py → spei_python-1.0.7/spei/signature/payload.py +84 -36
- {spei_python-1.0.6/spei/checksum → spei_python-1.0.7/spei/signature}/types.py +11 -1
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/types/spei.py +1 -0
- spei_python-1.0.6/spei/checksum/factory.py +0 -54
- spei_python-1.0.6/spei/responses/acuse.py +0 -24
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/README.md +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/__init__.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/cep_generator.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/checksum/__init__.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/errors/__init__.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/errors/spei.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/exceptions.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/mappings.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/requests/__init__.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/requests/acuse.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/requests/cda.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/requests/orden.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/requests/respuesta.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/__init__.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/cda.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/ensesion.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/mensaje.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/payments.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/respuesta.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/resources/validators.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/responses/orden.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/responses/respuesta.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/types/__init__.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/types/common.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/types/sice.py +0 -0
- {spei_python-1.0.6 → spei_python-1.0.7}/spei/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: spei-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.7
|
|
4
4
|
Summary:
|
|
5
5
|
Author: tech
|
|
6
6
|
Author-email: tech@fondeadora.com
|
|
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.11
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.12
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
13
|
Requires-Dist: cryptography (>=3.0,<44.1)
|
|
13
14
|
Requires-Dist: lxml (>=5.0.0,<6.0.0)
|
|
14
15
|
Requires-Dist: pydantic (>=1.10.17,<3)
|
|
@@ -18,19 +19,20 @@ Description-Content-Type: text/markdown
|
|
|
18
19
|
|
|
19
20
|
[](https://github.com/wemake-services/wemake-python-styleguide)
|
|
20
21
|
|
|
21
|
-
spei-python
|
|
22
|
-
===========
|
|
22
|
+
# spei-python
|
|
23
23
|
|
|
24
24
|
A library for accessing the SPEI API and SICE API for python.
|
|
25
25
|
|
|
26
|
-
|
|
27
26
|
## Installation
|
|
27
|
+
|
|
28
28
|
Use the package manager [poetry](https://pypi.org/project/poetry/) to install.
|
|
29
29
|
|
|
30
30
|
poetry install spei-python
|
|
31
31
|
|
|
32
32
|
## Usage
|
|
33
|
+
|
|
33
34
|
Use our client to send orders to SPEI.
|
|
35
|
+
|
|
34
36
|
```python
|
|
35
37
|
from spei.client import BaseClient
|
|
36
38
|
|
|
@@ -44,6 +46,7 @@ client = BaseClient(
|
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
Use our client to send orders to SICE.
|
|
49
|
+
|
|
47
50
|
```python
|
|
48
51
|
from spei.sice import BaseClient
|
|
49
52
|
|
|
@@ -53,10 +56,12 @@ client = BaseClient(
|
|
|
53
56
|
```
|
|
54
57
|
|
|
55
58
|
## Methods
|
|
59
|
+
|
|
56
60
|
- [registra_orden](/spei/client.py#58)
|
|
57
61
|
- [registra_cda](/spei/sice.py#25)
|
|
58
62
|
|
|
59
63
|
## Resources
|
|
64
|
+
|
|
60
65
|
There are four main resources.
|
|
61
66
|
|
|
62
67
|
- [Orden](spei/resources/orden.py) our abstraction of order, this goes through SPEI as XML.
|
|
@@ -65,6 +70,7 @@ There are four main resources.
|
|
|
65
70
|
- [Acuse](spei/resources/acuse.py) our abstraction of received SICE messages and confirmation message to SICE.
|
|
66
71
|
|
|
67
72
|
## Types
|
|
73
|
+
|
|
68
74
|
- [TipoPagoOrdenPago](/spei/types.py#6) Order payment type.
|
|
69
75
|
- [TipoOrdenPago](/spei/types.py#33) Order type.
|
|
70
76
|
- [TipoCuentaOrdenPago](/spei/types.py#38) Account type.
|
|
@@ -77,38 +83,46 @@ There are four main resources.
|
|
|
77
83
|
- [TopologiaOrdenPago](/spei/types.py#107) Order notification method.
|
|
78
84
|
|
|
79
85
|
## Requests
|
|
86
|
+
|
|
80
87
|
These are used to perform requests to karpay using our resources.
|
|
88
|
+
|
|
81
89
|
- [OrdenRequest](spei/requests/orden.py) Maps an existing orden to XML.
|
|
82
90
|
- [RespuestaRequest](spei/requests/respuesta.py) Maps an existing respuesta to XML.
|
|
83
91
|
- [CDARequest](spei/requests/cda.py) Maps an existing CDA to XML.
|
|
84
92
|
|
|
85
93
|
## Responses
|
|
94
|
+
|
|
86
95
|
These are used to map karpay results to our resources.
|
|
87
|
-
|
|
96
|
+
|
|
88
97
|
- [RespuestaResponse](spei/responses/respuesta.py) Maps a respuesta XML to our Response resource.
|
|
89
98
|
|
|
90
99
|
## Errors
|
|
100
|
+
|
|
91
101
|
Available [errors](/spei/errors.py) messages from Karpay.
|
|
92
102
|
|
|
93
103
|
These errors are included inside respuesta.
|
|
94
104
|
|
|
95
105
|
## Test
|
|
106
|
+
|
|
96
107
|
Tested with [mamba](https://mamba-framework.readthedocs.io/en/latest/), install poetry dev packages and then run tests.
|
|
97
108
|
|
|
98
109
|
poetry run make test
|
|
99
110
|
|
|
100
111
|
## Contributing
|
|
112
|
+
|
|
101
113
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
102
114
|
|
|
103
115
|
Please make sure to update tests as appropriate.
|
|
104
116
|
|
|
105
117
|
## License
|
|
118
|
+
|
|
106
119
|
[MIT](https://choosealicense.com/licenses/mit/)
|
|
107
120
|
|
|
108
|
-
##
|
|
121
|
+
## Signature verification
|
|
122
|
+
|
|
109
123
|
This repo includes a utility to generate [firma digital aplicada](https://www.notion.so/fondeadoraroot/Algoritmo-de-Firma-e-Karpay-SPEI-02e6c25b7c5943bea054ae37c9605bdc)
|
|
110
124
|
|
|
111
125
|
```sh
|
|
112
|
-
python bin/
|
|
126
|
+
python bin/generate_signature.py bin/message.json # legacy script name; generates digital signatures
|
|
113
127
|
```
|
|
114
128
|
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
[](https://github.com/wemake-services/wemake-python-styleguide)
|
|
2
2
|
|
|
3
|
-
spei-python
|
|
4
|
-
===========
|
|
3
|
+
# spei-python
|
|
5
4
|
|
|
6
5
|
A library for accessing the SPEI API and SICE API for python.
|
|
7
6
|
|
|
8
|
-
|
|
9
7
|
## Installation
|
|
8
|
+
|
|
10
9
|
Use the package manager [poetry](https://pypi.org/project/poetry/) to install.
|
|
11
10
|
|
|
12
11
|
poetry install spei-python
|
|
13
12
|
|
|
14
13
|
## Usage
|
|
14
|
+
|
|
15
15
|
Use our client to send orders to SPEI.
|
|
16
|
+
|
|
16
17
|
```python
|
|
17
18
|
from spei.client import BaseClient
|
|
18
19
|
|
|
@@ -26,6 +27,7 @@ client = BaseClient(
|
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
Use our client to send orders to SICE.
|
|
30
|
+
|
|
29
31
|
```python
|
|
30
32
|
from spei.sice import BaseClient
|
|
31
33
|
|
|
@@ -35,10 +37,12 @@ client = BaseClient(
|
|
|
35
37
|
```
|
|
36
38
|
|
|
37
39
|
## Methods
|
|
40
|
+
|
|
38
41
|
- [registra_orden](/spei/client.py#58)
|
|
39
42
|
- [registra_cda](/spei/sice.py#25)
|
|
40
43
|
|
|
41
44
|
## Resources
|
|
45
|
+
|
|
42
46
|
There are four main resources.
|
|
43
47
|
|
|
44
48
|
- [Orden](spei/resources/orden.py) our abstraction of order, this goes through SPEI as XML.
|
|
@@ -47,6 +51,7 @@ There are four main resources.
|
|
|
47
51
|
- [Acuse](spei/resources/acuse.py) our abstraction of received SICE messages and confirmation message to SICE.
|
|
48
52
|
|
|
49
53
|
## Types
|
|
54
|
+
|
|
50
55
|
- [TipoPagoOrdenPago](/spei/types.py#6) Order payment type.
|
|
51
56
|
- [TipoOrdenPago](/spei/types.py#33) Order type.
|
|
52
57
|
- [TipoCuentaOrdenPago](/spei/types.py#38) Account type.
|
|
@@ -59,37 +64,45 @@ There are four main resources.
|
|
|
59
64
|
- [TopologiaOrdenPago](/spei/types.py#107) Order notification method.
|
|
60
65
|
|
|
61
66
|
## Requests
|
|
67
|
+
|
|
62
68
|
These are used to perform requests to karpay using our resources.
|
|
69
|
+
|
|
63
70
|
- [OrdenRequest](spei/requests/orden.py) Maps an existing orden to XML.
|
|
64
71
|
- [RespuestaRequest](spei/requests/respuesta.py) Maps an existing respuesta to XML.
|
|
65
72
|
- [CDARequest](spei/requests/cda.py) Maps an existing CDA to XML.
|
|
66
73
|
|
|
67
74
|
## Responses
|
|
75
|
+
|
|
68
76
|
These are used to map karpay results to our resources.
|
|
69
|
-
|
|
77
|
+
|
|
70
78
|
- [RespuestaResponse](spei/responses/respuesta.py) Maps a respuesta XML to our Response resource.
|
|
71
79
|
|
|
72
80
|
## Errors
|
|
81
|
+
|
|
73
82
|
Available [errors](/spei/errors.py) messages from Karpay.
|
|
74
83
|
|
|
75
84
|
These errors are included inside respuesta.
|
|
76
85
|
|
|
77
86
|
## Test
|
|
87
|
+
|
|
78
88
|
Tested with [mamba](https://mamba-framework.readthedocs.io/en/latest/), install poetry dev packages and then run tests.
|
|
79
89
|
|
|
80
90
|
poetry run make test
|
|
81
91
|
|
|
82
92
|
## Contributing
|
|
93
|
+
|
|
83
94
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
84
95
|
|
|
85
96
|
Please make sure to update tests as appropriate.
|
|
86
97
|
|
|
87
98
|
## License
|
|
99
|
+
|
|
88
100
|
[MIT](https://choosealicense.com/licenses/mit/)
|
|
89
101
|
|
|
90
|
-
##
|
|
102
|
+
## Signature verification
|
|
103
|
+
|
|
91
104
|
This repo includes a utility to generate [firma digital aplicada](https://www.notion.so/fondeadoraroot/Algoritmo-de-Firma-e-Karpay-SPEI-02e6c25b7c5943bea054ae37c9605bdc)
|
|
92
105
|
|
|
93
106
|
```sh
|
|
94
|
-
python bin/
|
|
107
|
+
python bin/generate_signature.py bin/message.json # legacy script name; generates digital signatures
|
|
95
108
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "spei-python"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.7"
|
|
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 = "1.0.
|
|
35
|
+
version = "1.0.7"
|
|
36
36
|
tag_format = "v$version"
|
|
37
37
|
bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
|
|
38
38
|
version_files = ["pyproject.toml:version"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from spei.signature.factory import get_signature_builder
|
|
4
|
+
from spei.signature.payload import SignaturePayloadBuilder
|
|
5
|
+
from spei.types import TipoPagoOrdenPago
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_checksum_generator(payment_type: TipoPagoOrdenPago) -> SignaturePayloadBuilder:
|
|
9
|
+
warnings.warn(
|
|
10
|
+
'get_checksum_generator is deprecated; use spei.signature.factory.get_signature_builder instead.', # noqa: E501
|
|
11
|
+
DeprecationWarning,
|
|
12
|
+
stacklevel=2,
|
|
13
|
+
)
|
|
14
|
+
return get_signature_builder(payment_type)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = ['get_checksum_generator']
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from spei.signature import payload as signature_payload
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _warn(name: str) -> None:
|
|
7
|
+
warnings.warn(
|
|
8
|
+
f'{name} is deprecated; use spei.signature.payload equivalents instead.',
|
|
9
|
+
DeprecationWarning,
|
|
10
|
+
stacklevel=3,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ChecksumGenerator(
|
|
15
|
+
signature_payload.SignaturePayloadBuilder,
|
|
16
|
+
):
|
|
17
|
+
def __init__(self, *args, **kwargs):
|
|
18
|
+
_warn('ChecksumGenerator')
|
|
19
|
+
super().__init__(*args, **kwargs)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ChecksumGeneratorRemittance(
|
|
23
|
+
signature_payload.RemittanceSignaturePayloadBuilder,
|
|
24
|
+
):
|
|
25
|
+
def __init__(self, *args, **kwargs):
|
|
26
|
+
_warn('ChecksumGeneratorRemittance')
|
|
27
|
+
super().__init__(*args, **kwargs)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ChecksumGeneratorDefault(
|
|
31
|
+
signature_payload.DefaultSignaturePayloadBuilder,
|
|
32
|
+
):
|
|
33
|
+
def __init__(self, *args, **kwargs):
|
|
34
|
+
_warn('ChecksumGeneratorDefault')
|
|
35
|
+
super().__init__(*args, **kwargs)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ChecksumGeneratorOrigin(
|
|
39
|
+
signature_payload.OriginSignaturePayloadBuilder,
|
|
40
|
+
):
|
|
41
|
+
def __init__(self, *args, **kwargs):
|
|
42
|
+
_warn('ChecksumGeneratorOrigin')
|
|
43
|
+
super().__init__(*args, **kwargs)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ChecksumGeneratorBeneficiary(
|
|
47
|
+
signature_payload.BeneficiarySignaturePayloadBuilder,
|
|
48
|
+
):
|
|
49
|
+
def __init__(self, *args, **kwargs):
|
|
50
|
+
_warn('ChecksumGeneratorBeneficiary')
|
|
51
|
+
super().__init__(*args, **kwargs)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class ChecksumGeneratorOriginAndBeneficiary(
|
|
55
|
+
signature_payload.OriginAndBeneficiarySignaturePayloadBuilder,
|
|
56
|
+
):
|
|
57
|
+
def __init__(self, *args, **kwargs):
|
|
58
|
+
_warn('ChecksumGeneratorOriginAndBeneficiary')
|
|
59
|
+
super().__init__(*args, **kwargs)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary(
|
|
63
|
+
signature_payload.BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder,
|
|
64
|
+
):
|
|
65
|
+
def __init__(self, *args, **kwargs):
|
|
66
|
+
_warn('ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary')
|
|
67
|
+
super().__init__(*args, **kwargs)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class ChecksumGeneratorIndirectToParticipant(
|
|
71
|
+
signature_payload.IndirectToParticipantSignaturePayloadBuilder,
|
|
72
|
+
):
|
|
73
|
+
def __init__(self, *args, **kwargs):
|
|
74
|
+
_warn('ChecksumGeneratorIndirectToParticipant')
|
|
75
|
+
super().__init__(*args, **kwargs)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class ChecksumGeneratorIndirect(
|
|
79
|
+
signature_payload.IndirectSignaturePayloadBuilder,
|
|
80
|
+
):
|
|
81
|
+
def __init__(self, *args, **kwargs):
|
|
82
|
+
_warn('ChecksumGeneratorIndirect')
|
|
83
|
+
super().__init__(*args, **kwargs)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class ChecksumGeneratorEveryField(
|
|
87
|
+
signature_payload.EveryFieldSignaturePayloadBuilder,
|
|
88
|
+
):
|
|
89
|
+
def __init__(self, *args, **kwargs):
|
|
90
|
+
_warn('ChecksumGeneratorEveryField')
|
|
91
|
+
super().__init__(*args, **kwargs)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
__all__ = [
|
|
95
|
+
'ChecksumGenerator',
|
|
96
|
+
'ChecksumGeneratorBeneficiary',
|
|
97
|
+
'ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary',
|
|
98
|
+
'ChecksumGeneratorDefault',
|
|
99
|
+
'ChecksumGeneratorEveryField',
|
|
100
|
+
'ChecksumGeneratorIndirect',
|
|
101
|
+
'ChecksumGeneratorIndirectToParticipant',
|
|
102
|
+
'ChecksumGeneratorOrigin',
|
|
103
|
+
'ChecksumGeneratorOriginAndBeneficiary',
|
|
104
|
+
'ChecksumGeneratorRemittance',
|
|
105
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from spei.signature.types import (
|
|
4
|
+
INDIRECT_PAYMENT_TYPES,
|
|
5
|
+
PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT,
|
|
6
|
+
PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
7
|
+
PAYMENT_TYPES_WITH_DEFAULT_FIELDS,
|
|
8
|
+
PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT,
|
|
9
|
+
PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT,
|
|
10
|
+
PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
11
|
+
REMITTANCE_PAYMENT_TYPES,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
warnings.warn(
|
|
15
|
+
'spei.checksum.types is deprecated; import from spei.signature.types instead.',
|
|
16
|
+
DeprecationWarning,
|
|
17
|
+
stacklevel=2,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
'INDIRECT_PAYMENT_TYPES',
|
|
22
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT',
|
|
23
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT',
|
|
24
|
+
'PAYMENT_TYPES_WITH_DEFAULT_FIELDS',
|
|
25
|
+
'PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT',
|
|
26
|
+
'PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT',
|
|
27
|
+
'PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT',
|
|
28
|
+
'REMITTANCE_PAYMENT_TYPES',
|
|
29
|
+
]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
import logging
|
|
3
|
+
import warnings
|
|
3
4
|
|
|
4
5
|
import requests
|
|
5
6
|
from cryptography.hazmat.backends import default_backend
|
|
@@ -8,16 +9,27 @@ from cryptography.hazmat.primitives.asymmetric import padding
|
|
|
8
9
|
from cryptography.hazmat.primitives.hashes import SHA256
|
|
9
10
|
|
|
10
11
|
from spei import exceptions
|
|
11
|
-
from spei.checksum.factory import get_checksum_generator
|
|
12
12
|
from spei.errors import spei as errors
|
|
13
13
|
from spei.requests import OrdenRequest
|
|
14
14
|
from spei.resources import Orden, Respuesta
|
|
15
15
|
from spei.responses import RespuestaResponse
|
|
16
|
+
from spei.signature.factory import get_signature_builder
|
|
16
17
|
|
|
17
18
|
logger = logging.getLogger('spei')
|
|
18
19
|
logger.setLevel(logging.DEBUG)
|
|
19
20
|
|
|
20
21
|
|
|
22
|
+
_DEPRECATED_FACTORY_ARGUMENT_MESSAGE = (
|
|
23
|
+
'Use signature_builder_factory; checksum_generator_factory is deprecated.'
|
|
24
|
+
)
|
|
25
|
+
_DEPRECATED_FACTORY_ACCESS_MESSAGE = (
|
|
26
|
+
'checksum_generator_factory is deprecated; use signature_builder_factory.'
|
|
27
|
+
)
|
|
28
|
+
_DEPRECATED_GENERATE_CHECKSUM_MESSAGE = (
|
|
29
|
+
'generate_checksum is deprecated; use generate_signature instead.'
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
21
33
|
class BaseClient(object):
|
|
22
34
|
def __init__(
|
|
23
35
|
self,
|
|
@@ -28,7 +40,8 @@ class BaseClient(object):
|
|
|
28
40
|
password,
|
|
29
41
|
verify=False,
|
|
30
42
|
http_client=requests,
|
|
31
|
-
checksum_generator_factory=
|
|
43
|
+
checksum_generator_factory=None,
|
|
44
|
+
signature_builder_factory=None,
|
|
32
45
|
):
|
|
33
46
|
self.priv_key = priv_key
|
|
34
47
|
self.priv_key_passphrase = priv_key_passphrase or None
|
|
@@ -52,7 +65,56 @@ class BaseClient(object):
|
|
|
52
65
|
default_backend(),
|
|
53
66
|
)
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
factories_conflict = (
|
|
69
|
+
signature_builder_factory is not None
|
|
70
|
+
and checksum_generator_factory is not None
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
if factories_conflict:
|
|
74
|
+
warnings.warn(
|
|
75
|
+
_DEPRECATED_FACTORY_ARGUMENT_MESSAGE,
|
|
76
|
+
DeprecationWarning,
|
|
77
|
+
stacklevel=2,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if signature_builder_factory is None:
|
|
81
|
+
if checksum_generator_factory is not None:
|
|
82
|
+
warnings.warn(
|
|
83
|
+
_DEPRECATED_FACTORY_ACCESS_MESSAGE,
|
|
84
|
+
DeprecationWarning,
|
|
85
|
+
stacklevel=2,
|
|
86
|
+
)
|
|
87
|
+
signature_builder_factory = checksum_generator_factory
|
|
88
|
+
else:
|
|
89
|
+
signature_builder_factory = get_signature_builder
|
|
90
|
+
|
|
91
|
+
self._signature_builder_factory = signature_builder_factory
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def signature_builder_factory(self):
|
|
95
|
+
return self._signature_builder_factory
|
|
96
|
+
|
|
97
|
+
@signature_builder_factory.setter
|
|
98
|
+
def signature_builder_factory(self, factory):
|
|
99
|
+
self._signature_builder_factory = factory
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def checksum_generator_factory(self):
|
|
103
|
+
warnings.warn(
|
|
104
|
+
_DEPRECATED_FACTORY_ACCESS_MESSAGE,
|
|
105
|
+
DeprecationWarning,
|
|
106
|
+
stacklevel=2,
|
|
107
|
+
)
|
|
108
|
+
return self._signature_builder_factory
|
|
109
|
+
|
|
110
|
+
@checksum_generator_factory.setter
|
|
111
|
+
def checksum_generator_factory(self, factory):
|
|
112
|
+
warnings.warn(
|
|
113
|
+
_DEPRECATED_FACTORY_ACCESS_MESSAGE,
|
|
114
|
+
DeprecationWarning,
|
|
115
|
+
stacklevel=2,
|
|
116
|
+
)
|
|
117
|
+
self._signature_builder_factory = factory
|
|
56
118
|
|
|
57
119
|
def registra_orden(
|
|
58
120
|
self,
|
|
@@ -60,8 +122,8 @@ class BaseClient(object):
|
|
|
60
122
|
orden_cls=Orden,
|
|
61
123
|
respuesta_response_cls=RespuestaResponse,
|
|
62
124
|
):
|
|
63
|
-
|
|
64
|
-
orden = orden_cls(op_firma_dig=
|
|
125
|
+
signature = self.generate_signature(orden_data)
|
|
126
|
+
orden = orden_cls(op_firma_dig=signature, **orden_data)
|
|
65
127
|
soap_request = OrdenRequest(orden).to_string()
|
|
66
128
|
logger.info(soap_request)
|
|
67
129
|
|
|
@@ -76,10 +138,10 @@ class BaseClient(object):
|
|
|
76
138
|
|
|
77
139
|
return respuesta
|
|
78
140
|
|
|
79
|
-
def
|
|
141
|
+
def generate_signature(self, message_data):
|
|
80
142
|
orden = Orden(**message_data, op_firma_dig='')
|
|
81
|
-
|
|
82
|
-
message_as_bytes =
|
|
143
|
+
builder = self.signature_builder_factory(orden.op_tp_clave)
|
|
144
|
+
message_as_bytes = builder.build(orden)
|
|
83
145
|
|
|
84
146
|
signed_message = self.pkey.sign(
|
|
85
147
|
message_as_bytes,
|
|
@@ -89,6 +151,15 @@ class BaseClient(object):
|
|
|
89
151
|
|
|
90
152
|
return base64.b64encode(signed_message)
|
|
91
153
|
|
|
154
|
+
def generate_checksum(self, message_data):
|
|
155
|
+
warnings.warn(
|
|
156
|
+
_DEPRECATED_GENERATE_CHECKSUM_MESSAGE,
|
|
157
|
+
DeprecationWarning,
|
|
158
|
+
stacklevel=2,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
return self.generate_signature(message_data)
|
|
162
|
+
|
|
92
163
|
def _raise_error(self, respuesta: Respuesta):
|
|
93
164
|
if respuesta.err_codigo == errors.GenericoCodigoError.tipo_pago_invalido:
|
|
94
165
|
raise exceptions.TipoPagoInvalidoError(respuesta)
|
|
@@ -91,9 +91,30 @@ class CodigoErrorAcuseServidor(str, Enum):
|
|
|
91
91
|
envio_resultado = 'EQ00'
|
|
92
92
|
|
|
93
93
|
mensaje_xml_invalido = 'ER01'
|
|
94
|
+
nombre_participante_indirecto_ordenante_solo_espacios = 'ER02'
|
|
95
|
+
nombre_participante_indirecto_ordenante_excede_longitud = 'ER03'
|
|
96
|
+
nombre_participante_indirecto_ordenante_caracteres_invalidos = 'ER04'
|
|
97
|
+
rfc_curp_participante_indirecto_ordenante_solo_espacios = 'ER05'
|
|
98
|
+
rfc_curp_participante_indirecto_ordenante_excede_longitud = 'ER06'
|
|
99
|
+
rfc_curp_participante_indirecto_ordenante_caracteres_invalidos = 'ER07'
|
|
100
|
+
cuenta_participante_indirecto_ordenante_obligatoria = 'ER08'
|
|
101
|
+
cuenta_participante_indirecto_ordenante_solo_numerica = 'ER09'
|
|
102
|
+
cuenta_participante_indirecto_ordenante_solo_ceros = 'ER10'
|
|
103
|
+
cuenta_participante_indirecto_ordenante_longitud_invalida = 'ER11'
|
|
104
|
+
nombre_participante_indirecto_ordenante_2_solo_espacios = 'ER12'
|
|
105
|
+
nombre_participante_indirecto_ordenante_2_excede_longitud = 'ER13'
|
|
106
|
+
nombre_participante_indirecto_ordenante_2_caracteres_invalidos = 'ER14'
|
|
107
|
+
cuenta_participante_indirecto_ordenante_2_obligatoria = 'ER15'
|
|
108
|
+
cuenta_participante_indirecto_ordenante_2_solo_numerica = 'ER16'
|
|
109
|
+
cuenta_participante_indirecto_ordenante_2_solo_ceros = 'ER17'
|
|
110
|
+
cuenta_participante_indirecto_ordenante_2_longitud_invalida = 'ER18'
|
|
111
|
+
rfc_curp_participante_indirecto_ordenante_2_solo_espacios = 'ER19'
|
|
112
|
+
rfc_curp_participante_indirecto_ordenante_2_excede_longitud = 'ER20'
|
|
113
|
+
rfc_curp_participante_indirecto_ordenante_2_caracteres_invalidos = 'ER21'
|
|
94
114
|
informacion_no_encontrada = 'ES01'
|
|
95
115
|
folio_pago_original_invalido = 'ET01'
|
|
96
116
|
folio_paquete_original_invalido = 'ET02'
|
|
117
|
+
folio_paquete_original_longitud_excedida = 'ET03'
|
|
97
118
|
tipo_pago_obligatorio = 'EV01'
|
|
98
119
|
tipo_pago_invalido = 'EV02'
|
|
99
120
|
tipo_pago_no_catalogado = 'EV03'
|
|
@@ -52,6 +52,20 @@ class MensajeRespuesta(BaseModel):
|
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
class RespuestaElement(object):
|
|
56
|
+
def __new__(cls, body):
|
|
57
|
+
return body.find(
|
|
58
|
+
'{http://www.praxis.com.mx/EnvioCda/}generaCdaResponse',
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class BodyElement(object):
|
|
63
|
+
def __new__(cls, mensaje):
|
|
64
|
+
return mensaje.find(
|
|
65
|
+
'{http://schemas.xmlsoap.org/soap/envelope/}Body',
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
55
69
|
class Acuse(BaseModel):
|
|
56
70
|
cda_id: int
|
|
57
71
|
mensaje_id: Any = None
|
|
@@ -60,6 +74,12 @@ class Acuse(BaseModel):
|
|
|
60
74
|
resultado_banxico: Optional[ResultadoBanxico] = None
|
|
61
75
|
model_config = ConfigDict(use_enum_values=True)
|
|
62
76
|
|
|
77
|
+
@classmethod
|
|
78
|
+
def from_xml(cls, acuse) -> 'Acuse':
|
|
79
|
+
mensaje = etree.fromstring(acuse) # noqa: S320
|
|
80
|
+
mensaje_element = RespuestaElement(BodyElement((mensaje)))
|
|
81
|
+
return Acuse.parse_synchronous_xml(mensaje_element)
|
|
82
|
+
|
|
63
83
|
@classmethod
|
|
64
84
|
def parse_synchronous_xml(cls, mensaje_element):
|
|
65
85
|
tipo_respuesta = mensaje_element.attrib['tipoRespuesta']
|
|
@@ -6,7 +6,7 @@ import requests
|
|
|
6
6
|
|
|
7
7
|
from spei.requests import CDARequest
|
|
8
8
|
from spei.resources import CDA
|
|
9
|
-
from spei.
|
|
9
|
+
from spei.resources.acuse import Acuse
|
|
10
10
|
|
|
11
11
|
logger = logging.getLogger('sice')
|
|
12
12
|
logger.setLevel(logging.DEBUG)
|
|
@@ -35,16 +35,19 @@ class BaseClient(object):
|
|
|
35
35
|
def registra_cda(
|
|
36
36
|
self,
|
|
37
37
|
cda_data: Dict[str, Any],
|
|
38
|
-
cda_cls: Type[CDA] = CDA,
|
|
39
|
-
acuse_response_cls: Type[AcuseResponse] = AcuseResponse,
|
|
40
38
|
endpoint: str = '/enlace-cep/EnvioCdaPortTypeImpl?wsdl',
|
|
41
|
-
) ->
|
|
42
|
-
orden =
|
|
39
|
+
) -> Acuse:
|
|
40
|
+
orden = CDA(**cda_data)
|
|
43
41
|
soap_request = CDARequest(orden).to_string()
|
|
44
42
|
logger.info(soap_request)
|
|
45
43
|
|
|
46
44
|
response = self._make_request(soap_request, endpoint)
|
|
47
|
-
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
return Acuse.from_xml(response.text)
|
|
48
|
+
except Exception:
|
|
49
|
+
logger.exception(f'Error parsing Acuse response: {response.text}')
|
|
50
|
+
raise
|
|
48
51
|
|
|
49
52
|
def _make_request(self, soap_request: bytes, endpoint: str) -> requests.Response:
|
|
50
53
|
url = urljoin(self.host, endpoint)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from spei.signature import factory as _factory
|
|
2
|
+
from spei.signature import payload as _payload
|
|
3
|
+
from spei.signature import types as _types
|
|
4
|
+
|
|
5
|
+
get_signature_builder = _factory.get_signature_builder
|
|
6
|
+
|
|
7
|
+
SignaturePayloadBuilder = _payload.SignaturePayloadBuilder
|
|
8
|
+
RemittanceSignaturePayloadBuilder = (
|
|
9
|
+
_payload.RemittanceSignaturePayloadBuilder
|
|
10
|
+
)
|
|
11
|
+
DefaultSignaturePayloadBuilder = _payload.DefaultSignaturePayloadBuilder
|
|
12
|
+
OriginSignaturePayloadBuilder = _payload.OriginSignaturePayloadBuilder
|
|
13
|
+
BeneficiarySignaturePayloadBuilder = (
|
|
14
|
+
_payload.BeneficiarySignaturePayloadBuilder
|
|
15
|
+
)
|
|
16
|
+
OriginAndBeneficiarySignaturePayloadBuilder = (
|
|
17
|
+
_payload.OriginAndBeneficiarySignaturePayloadBuilder
|
|
18
|
+
)
|
|
19
|
+
BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder = (
|
|
20
|
+
_payload.BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder
|
|
21
|
+
)
|
|
22
|
+
IndirectToParticipantSignaturePayloadBuilder = (
|
|
23
|
+
_payload.IndirectToParticipantSignaturePayloadBuilder
|
|
24
|
+
)
|
|
25
|
+
IndirectSignaturePayloadBuilder = _payload.IndirectSignaturePayloadBuilder
|
|
26
|
+
EveryFieldSignaturePayloadBuilder = (
|
|
27
|
+
_payload.EveryFieldSignaturePayloadBuilder
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
INDIRECT_PAYMENT_TYPES = _types.INDIRECT_PAYMENT_TYPES
|
|
31
|
+
PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT = (
|
|
32
|
+
_types.PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT
|
|
33
|
+
)
|
|
34
|
+
PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT = (
|
|
35
|
+
_types.PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT
|
|
36
|
+
)
|
|
37
|
+
PAYMENT_TYPES_WITH_DEFAULT_FIELDS = _types.PAYMENT_TYPES_WITH_DEFAULT_FIELDS
|
|
38
|
+
PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT = _types.PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT
|
|
39
|
+
PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT = (
|
|
40
|
+
_types.PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT
|
|
41
|
+
)
|
|
42
|
+
PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT = (
|
|
43
|
+
_types.PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT
|
|
44
|
+
)
|
|
45
|
+
REMITTANCE_PAYMENT_TYPES = _types.REMITTANCE_PAYMENT_TYPES
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
'BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder',
|
|
49
|
+
'BeneficiarySignaturePayloadBuilder',
|
|
50
|
+
'DefaultSignaturePayloadBuilder',
|
|
51
|
+
'EveryFieldSignaturePayloadBuilder',
|
|
52
|
+
'IndirectSignaturePayloadBuilder',
|
|
53
|
+
'IndirectToParticipantSignaturePayloadBuilder',
|
|
54
|
+
'OriginAndBeneficiarySignaturePayloadBuilder',
|
|
55
|
+
'OriginSignaturePayloadBuilder',
|
|
56
|
+
'RemittanceSignaturePayloadBuilder',
|
|
57
|
+
'SignaturePayloadBuilder',
|
|
58
|
+
'INDIRECT_PAYMENT_TYPES',
|
|
59
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT',
|
|
60
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT',
|
|
61
|
+
'PAYMENT_TYPES_WITH_DEFAULT_FIELDS',
|
|
62
|
+
'PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT',
|
|
63
|
+
'PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT',
|
|
64
|
+
'PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT',
|
|
65
|
+
'REMITTANCE_PAYMENT_TYPES',
|
|
66
|
+
'get_signature_builder',
|
|
67
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from spei.signature import payload as signature_payload
|
|
2
|
+
from spei.signature import types as signature_types
|
|
3
|
+
from spei.signature.payload import SignaturePayloadBuilder
|
|
4
|
+
from spei.types import TipoPagoOrdenPago
|
|
5
|
+
|
|
6
|
+
_BENEFICIARY_EXTRA_ACCOUNT_ATTR = (
|
|
7
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT'
|
|
8
|
+
)
|
|
9
|
+
_BENEFICIARY_EXTRA_ACCOUNT_TYPES = getattr(
|
|
10
|
+
signature_types,
|
|
11
|
+
_BENEFICIARY_EXTRA_ACCOUNT_ATTR,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
_ORIGIN_BENEFICIARY_EXTRA_ACCOUNT_ATTR = (
|
|
15
|
+
'PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT'
|
|
16
|
+
)
|
|
17
|
+
_ORIGIN_BENEFICIARY_EXTRA_ACCOUNT_TYPES = getattr(
|
|
18
|
+
signature_types,
|
|
19
|
+
_ORIGIN_BENEFICIARY_EXTRA_ACCOUNT_ATTR,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
_BUILDER_BY_PAYMENT_GROUP = (
|
|
23
|
+
(
|
|
24
|
+
signature_types.PAYMENT_TYPES_WITH_DEFAULT_FIELDS,
|
|
25
|
+
signature_payload.DefaultSignaturePayloadBuilder,
|
|
26
|
+
),
|
|
27
|
+
(
|
|
28
|
+
signature_types.PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT,
|
|
29
|
+
signature_payload.OriginSignaturePayloadBuilder,
|
|
30
|
+
),
|
|
31
|
+
(
|
|
32
|
+
signature_types.PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT,
|
|
33
|
+
signature_payload.BeneficiarySignaturePayloadBuilder,
|
|
34
|
+
),
|
|
35
|
+
(
|
|
36
|
+
signature_types.PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT,
|
|
37
|
+
signature_payload.OriginAndBeneficiarySignaturePayloadBuilder,
|
|
38
|
+
),
|
|
39
|
+
(
|
|
40
|
+
_BENEFICIARY_EXTRA_ACCOUNT_TYPES,
|
|
41
|
+
signature_payload.BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder,
|
|
42
|
+
),
|
|
43
|
+
(
|
|
44
|
+
signature_types.REMITTANCE_PAYMENT_TYPES,
|
|
45
|
+
signature_payload.RemittanceSignaturePayloadBuilder,
|
|
46
|
+
),
|
|
47
|
+
(
|
|
48
|
+
signature_types.INDIRECT_PAYMENT_TYPES,
|
|
49
|
+
signature_payload.IndirectSignaturePayloadBuilder,
|
|
50
|
+
),
|
|
51
|
+
(
|
|
52
|
+
_ORIGIN_BENEFICIARY_EXTRA_ACCOUNT_TYPES,
|
|
53
|
+
signature_payload.EveryFieldSignaturePayloadBuilder,
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_signature_builder(
|
|
59
|
+
payment_type: TipoPagoOrdenPago,
|
|
60
|
+
) -> SignaturePayloadBuilder:
|
|
61
|
+
for payment_group, builder_cls in _BUILDER_BY_PAYMENT_GROUP:
|
|
62
|
+
if payment_type in payment_group:
|
|
63
|
+
return builder_cls()
|
|
64
|
+
|
|
65
|
+
if payment_type == TipoPagoOrdenPago.tercero_indirecto_a_participante:
|
|
66
|
+
return signature_payload.IndirectToParticipantSignaturePayloadBuilder()
|
|
67
|
+
|
|
68
|
+
raise NotImplementedError
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
__all__ = ['get_signature_builder']
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from datetime import date
|
|
2
3
|
from decimal import Decimal
|
|
3
4
|
from typing import Optional, Tuple
|
|
@@ -5,18 +6,28 @@ from typing import Optional, Tuple
|
|
|
5
6
|
from spei.resources import Orden
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
class
|
|
9
|
-
|
|
9
|
+
class SignaturePayloadBuilder(object):
|
|
10
|
+
"""Builds byte payloads to sign or verify SPEI orders."""
|
|
11
|
+
|
|
12
|
+
def build(self, orden: Orden) -> bytes:
|
|
10
13
|
raise NotImplementedError
|
|
11
14
|
|
|
12
|
-
def
|
|
15
|
+
def format_data(self, orden: Orden) -> bytes:
|
|
16
|
+
warnings.warn(
|
|
17
|
+
'SignaturePayloadBuilder.format_data is deprecated; use build instead.',
|
|
18
|
+
DeprecationWarning,
|
|
19
|
+
stacklevel=2,
|
|
20
|
+
)
|
|
21
|
+
return self.build(orden)
|
|
22
|
+
|
|
23
|
+
def split_amount(self, amount: str) -> Tuple[int, int]:
|
|
13
24
|
amount_as_cents = int(Decimal(str(amount)) * 100)
|
|
14
25
|
high = 0
|
|
15
26
|
low = amount_as_cents
|
|
16
|
-
|
|
17
|
-
if
|
|
18
|
-
high =
|
|
19
|
-
low = amount_as_cents - (
|
|
27
|
+
tens_of_millions = amount_as_cents // 10**9
|
|
28
|
+
if tens_of_millions:
|
|
29
|
+
high = tens_of_millions
|
|
30
|
+
low = amount_as_cents - (tens_of_millions * 10**9)
|
|
20
31
|
return high, low
|
|
21
32
|
|
|
22
33
|
def _fecha_to_bytearray(self, fecha_operacion: date) -> bytearray:
|
|
@@ -27,24 +38,23 @@ class ChecksumGenerator(object):
|
|
|
27
38
|
return bytearray(day + month + year)
|
|
28
39
|
|
|
29
40
|
def _clave_to_bytearray(self, clave: Optional[str]) -> bytearray:
|
|
30
|
-
|
|
31
|
-
clave = ''
|
|
41
|
+
clave = clave or ''
|
|
32
42
|
|
|
33
43
|
return bytearray(int.to_bytes(int(clave), 4, 'big'))
|
|
34
44
|
|
|
35
45
|
def _monto_to_bytearray(self, amount: str) -> bytearray:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
high_value, low_value = self.split_amount(amount)
|
|
47
|
+
high_bytes = int.to_bytes(int(high_value), 4, 'big')
|
|
48
|
+
low_bytes = int.to_bytes(int(low_value), 4, 'big')
|
|
39
49
|
|
|
40
|
-
return bytearray(
|
|
50
|
+
return bytearray(high_bytes + low_bytes)
|
|
41
51
|
|
|
42
52
|
def _to_byte_array(
|
|
43
53
|
self,
|
|
44
|
-
value: Optional[str],
|
|
54
|
+
value: Optional[str],
|
|
45
55
|
add_zero_byte: bool = False,
|
|
46
56
|
) -> bytearray:
|
|
47
|
-
value = value or ''
|
|
57
|
+
value = value or ''
|
|
48
58
|
encoded = value.encode('utf-8')
|
|
49
59
|
bytes_ = bytearray(encoded)
|
|
50
60
|
if add_zero_byte:
|
|
@@ -64,8 +74,10 @@ class ChecksumGenerator(object):
|
|
|
64
74
|
return bytes(res)
|
|
65
75
|
|
|
66
76
|
|
|
67
|
-
class
|
|
68
|
-
|
|
77
|
+
class RemittanceSignaturePayloadBuilder(
|
|
78
|
+
SignaturePayloadBuilder,
|
|
79
|
+
):
|
|
80
|
+
def build(self, orden: Orden) -> bytes:
|
|
69
81
|
message_data = (
|
|
70
82
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
71
83
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -74,13 +86,18 @@ class ChecksumGeneratorRemittance(ChecksumGenerator):
|
|
|
74
86
|
self._monto_to_bytearray(orden.op_monto),
|
|
75
87
|
self._to_byte_array(orden.op_cuenta_ord, add_zero_byte=True),
|
|
76
88
|
self._to_byte_array(orden.op_cuenta_ben, add_zero_byte=True),
|
|
77
|
-
self._to_byte_array(
|
|
89
|
+
self._to_byte_array(
|
|
90
|
+
orden.op_cuenta_participante_ord,
|
|
91
|
+
add_zero_byte=True,
|
|
92
|
+
),
|
|
78
93
|
)
|
|
79
94
|
return self._list_to_bytes(message_data)
|
|
80
95
|
|
|
81
96
|
|
|
82
|
-
class
|
|
83
|
-
|
|
97
|
+
class DefaultSignaturePayloadBuilder(
|
|
98
|
+
SignaturePayloadBuilder,
|
|
99
|
+
):
|
|
100
|
+
def build(self, orden: Orden) -> bytes:
|
|
84
101
|
message_data = (
|
|
85
102
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
86
103
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -91,8 +108,10 @@ class ChecksumGeneratorDefault(ChecksumGenerator):
|
|
|
91
108
|
return self._list_to_bytes(message_data)
|
|
92
109
|
|
|
93
110
|
|
|
94
|
-
class
|
|
95
|
-
|
|
111
|
+
class OriginSignaturePayloadBuilder(
|
|
112
|
+
SignaturePayloadBuilder,
|
|
113
|
+
):
|
|
114
|
+
def build(self, orden: Orden) -> bytes:
|
|
96
115
|
message_data = (
|
|
97
116
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
98
117
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -104,8 +123,10 @@ class ChecksumGeneratorOrigin(ChecksumGenerator):
|
|
|
104
123
|
return self._list_to_bytes(message_data)
|
|
105
124
|
|
|
106
125
|
|
|
107
|
-
class
|
|
108
|
-
|
|
126
|
+
class BeneficiarySignaturePayloadBuilder(
|
|
127
|
+
SignaturePayloadBuilder,
|
|
128
|
+
):
|
|
129
|
+
def build(self, orden: Orden) -> bytes:
|
|
109
130
|
message_data = (
|
|
110
131
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
111
132
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -117,8 +138,10 @@ class ChecksumGeneratorBeneficiary(ChecksumGenerator):
|
|
|
117
138
|
return self._list_to_bytes(message_data)
|
|
118
139
|
|
|
119
140
|
|
|
120
|
-
class
|
|
121
|
-
|
|
141
|
+
class OriginAndBeneficiarySignaturePayloadBuilder(
|
|
142
|
+
SignaturePayloadBuilder,
|
|
143
|
+
):
|
|
144
|
+
def build(self, orden: Orden) -> bytes:
|
|
122
145
|
message_data = (
|
|
123
146
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
124
147
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -131,8 +154,10 @@ class ChecksumGeneratorOriginAndBeneficiary(ChecksumGenerator):
|
|
|
131
154
|
return self._list_to_bytes(message_data)
|
|
132
155
|
|
|
133
156
|
|
|
134
|
-
class
|
|
135
|
-
|
|
157
|
+
class BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder(
|
|
158
|
+
SignaturePayloadBuilder,
|
|
159
|
+
):
|
|
160
|
+
def build(self, orden: Orden) -> bytes:
|
|
136
161
|
message_data = (
|
|
137
162
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
138
163
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -145,8 +170,10 @@ class ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary(ChecksumGenerator):
|
|
|
145
170
|
return self._list_to_bytes(message_data)
|
|
146
171
|
|
|
147
172
|
|
|
148
|
-
class
|
|
149
|
-
|
|
173
|
+
class IndirectToParticipantSignaturePayloadBuilder(
|
|
174
|
+
SignaturePayloadBuilder,
|
|
175
|
+
):
|
|
176
|
+
def build(self, orden: Orden) -> bytes:
|
|
150
177
|
message_data = (
|
|
151
178
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
152
179
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -154,13 +181,18 @@ class ChecksumGeneratorIndirectToParticipant(ChecksumGenerator):
|
|
|
154
181
|
self._to_byte_array(orden.op_cve_rastreo, add_zero_byte=True),
|
|
155
182
|
self._monto_to_bytearray(orden.op_monto),
|
|
156
183
|
self._to_byte_array(orden.op_cuenta_ord, add_zero_byte=True),
|
|
157
|
-
self._to_byte_array(
|
|
184
|
+
self._to_byte_array(
|
|
185
|
+
orden.op_cuenta_participante_ord,
|
|
186
|
+
add_zero_byte=True,
|
|
187
|
+
),
|
|
158
188
|
)
|
|
159
189
|
return self._list_to_bytes(message_data)
|
|
160
190
|
|
|
161
191
|
|
|
162
|
-
class
|
|
163
|
-
|
|
192
|
+
class IndirectSignaturePayloadBuilder(
|
|
193
|
+
SignaturePayloadBuilder,
|
|
194
|
+
):
|
|
195
|
+
def build(self, orden: Orden) -> bytes:
|
|
164
196
|
message_data = (
|
|
165
197
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
166
198
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -169,13 +201,15 @@ class ChecksumGeneratorIndirect(ChecksumGenerator):
|
|
|
169
201
|
self._monto_to_bytearray(orden.op_monto),
|
|
170
202
|
self._to_byte_array(orden.op_cuenta_ord, add_zero_byte=True),
|
|
171
203
|
self._to_byte_array(orden.op_cuenta_ben, add_zero_byte=True),
|
|
172
|
-
self._to_byte_array(orden.op_cuenta_participante_ord, add_zero_byte=True),
|
|
204
|
+
self._to_byte_array(orden.op_cuenta_participante_ord, add_zero_byte=True),
|
|
173
205
|
)
|
|
174
206
|
return self._list_to_bytes(message_data)
|
|
175
207
|
|
|
176
208
|
|
|
177
|
-
class
|
|
178
|
-
|
|
209
|
+
class EveryFieldSignaturePayloadBuilder(
|
|
210
|
+
SignaturePayloadBuilder,
|
|
211
|
+
):
|
|
212
|
+
def build(self, orden: Orden) -> bytes:
|
|
179
213
|
message_data = (
|
|
180
214
|
self._fecha_to_bytearray(orden.op_fecha_oper),
|
|
181
215
|
self._clave_to_bytearray(str(orden.op_ins_clave_ord)),
|
|
@@ -187,3 +221,17 @@ class ChecksumGeneratorEveryField(ChecksumGenerator):
|
|
|
187
221
|
self._to_byte_array(orden.op_cuenta_ben_2, add_zero_byte=True),
|
|
188
222
|
)
|
|
189
223
|
return self._list_to_bytes(message_data)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
__all__ = [
|
|
227
|
+
'SignaturePayloadBuilder',
|
|
228
|
+
'RemittanceSignaturePayloadBuilder',
|
|
229
|
+
'DefaultSignaturePayloadBuilder',
|
|
230
|
+
'OriginSignaturePayloadBuilder',
|
|
231
|
+
'BeneficiarySignaturePayloadBuilder',
|
|
232
|
+
'OriginAndBeneficiarySignaturePayloadBuilder',
|
|
233
|
+
'BeneficiaryAndAdditionalBeneficiarySignaturePayloadBuilder',
|
|
234
|
+
'IndirectToParticipantSignaturePayloadBuilder',
|
|
235
|
+
'IndirectSignaturePayloadBuilder',
|
|
236
|
+
'EveryFieldSignaturePayloadBuilder',
|
|
237
|
+
]
|
|
@@ -5,7 +5,6 @@ PAYMENT_TYPES_WITH_DEFAULT_FIELDS = (
|
|
|
5
5
|
TipoPagoOrdenPago.devolucion_extemporanea_no_acreditada,
|
|
6
6
|
TipoPagoOrdenPago.participante_a_participante,
|
|
7
7
|
TipoPagoOrdenPago.devolucion_acreditada,
|
|
8
|
-
TipoPagoOrdenPago.devolucion_especial_acreditada,
|
|
9
8
|
)
|
|
10
9
|
|
|
11
10
|
PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT = (
|
|
@@ -52,3 +51,14 @@ INDIRECT_PAYMENT_TYPES = (
|
|
|
52
51
|
TipoPagoOrdenPago.no_presencial_de_una_ocasion_indirecto,
|
|
53
52
|
TipoPagoOrdenPago.no_presencial_recurrente_indirecto,
|
|
54
53
|
)
|
|
54
|
+
|
|
55
|
+
__all__ = [
|
|
56
|
+
'INDIRECT_PAYMENT_TYPES',
|
|
57
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT',
|
|
58
|
+
'PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT',
|
|
59
|
+
'PAYMENT_TYPES_WITH_DEFAULT_FIELDS',
|
|
60
|
+
'PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT',
|
|
61
|
+
'PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT',
|
|
62
|
+
'PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT',
|
|
63
|
+
'REMITTANCE_PAYMENT_TYPES',
|
|
64
|
+
]
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
from spei.checksum.generator import (
|
|
2
|
-
ChecksumGenerator,
|
|
3
|
-
ChecksumGeneratorBeneficiary,
|
|
4
|
-
ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary,
|
|
5
|
-
ChecksumGeneratorDefault,
|
|
6
|
-
ChecksumGeneratorEveryField,
|
|
7
|
-
ChecksumGeneratorIndirect,
|
|
8
|
-
ChecksumGeneratorIndirectToParticipant,
|
|
9
|
-
ChecksumGeneratorOrigin,
|
|
10
|
-
ChecksumGeneratorOriginAndBeneficiary,
|
|
11
|
-
ChecksumGeneratorRemittance,
|
|
12
|
-
)
|
|
13
|
-
from spei.checksum.types import (
|
|
14
|
-
INDIRECT_PAYMENT_TYPES,
|
|
15
|
-
PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT,
|
|
16
|
-
PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
17
|
-
PAYMENT_TYPES_WITH_DEFAULT_FIELDS,
|
|
18
|
-
PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT,
|
|
19
|
-
PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT,
|
|
20
|
-
PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT,
|
|
21
|
-
REMITTANCE_PAYMENT_TYPES,
|
|
22
|
-
)
|
|
23
|
-
from spei.types import TipoPagoOrdenPago
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def get_checksum_generator(payment_type: TipoPagoOrdenPago) -> ChecksumGenerator: # noqa: C901, WPS212, E501
|
|
27
|
-
if payment_type in PAYMENT_TYPES_WITH_DEFAULT_FIELDS:
|
|
28
|
-
return ChecksumGeneratorDefault()
|
|
29
|
-
|
|
30
|
-
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_ACCOUNT:
|
|
31
|
-
return ChecksumGeneratorOrigin()
|
|
32
|
-
|
|
33
|
-
if payment_type in PAYMENT_TYPES_WITH_BENEFICIARY_ACCOUNT:
|
|
34
|
-
return ChecksumGeneratorBeneficiary()
|
|
35
|
-
|
|
36
|
-
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_AND_BENEFICIARY_ACCOUNT:
|
|
37
|
-
return ChecksumGeneratorOriginAndBeneficiary()
|
|
38
|
-
|
|
39
|
-
if payment_type in PAYMENT_TYPES_WITH_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT: # noqa: E501
|
|
40
|
-
return ChecksumGeneratorBeneficiaryAndAdditionalBeneficiary()
|
|
41
|
-
|
|
42
|
-
if payment_type in REMITTANCE_PAYMENT_TYPES:
|
|
43
|
-
return ChecksumGeneratorRemittance()
|
|
44
|
-
|
|
45
|
-
if payment_type in INDIRECT_PAYMENT_TYPES:
|
|
46
|
-
return ChecksumGeneratorIndirect()
|
|
47
|
-
|
|
48
|
-
if payment_type == TipoPagoOrdenPago.tercero_indirecto_a_participante:
|
|
49
|
-
return ChecksumGeneratorIndirectToParticipant()
|
|
50
|
-
|
|
51
|
-
if payment_type in PAYMENT_TYPES_WITH_ORIGIN_BENEFICIARY_AND_ADDITIONAL_BENEFICIARY_ACCOUNT: # noqa: E501
|
|
52
|
-
return ChecksumGeneratorEveryField()
|
|
53
|
-
|
|
54
|
-
raise NotImplementedError
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
from lxml import etree
|
|
2
|
-
|
|
3
|
-
from spei.resources import Acuse
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class RespuestaElement(object):
|
|
7
|
-
def __new__(cls, body):
|
|
8
|
-
return body.find(
|
|
9
|
-
'{http://www.praxis.com.mx/EnvioCda/}generaCdaResponse',
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class BodyElement(object):
|
|
14
|
-
def __new__(cls, mensaje):
|
|
15
|
-
return mensaje.find(
|
|
16
|
-
'{http://schemas.xmlsoap.org/soap/envelope/}Body',
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class AcuseResponse(object):
|
|
21
|
-
def __new__(cls, acuse, acuse_cls=Acuse):
|
|
22
|
-
mensaje = etree.fromstring(acuse) # noqa: S320
|
|
23
|
-
mensaje_element = RespuestaElement(BodyElement((mensaje)))
|
|
24
|
-
return acuse_cls.parse_synchronous_xml(mensaje_element)
|
|
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
|