python-redsys 2.2.0__tar.gz → 2.3.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 (61) hide show
  1. {python_redsys-2.2.0/python_redsys.egg-info → python_redsys-2.3.0}/PKG-INFO +19 -5
  2. {python_redsys-2.2.0 → python_redsys-2.3.0}/README.md +18 -4
  3. {python_redsys-2.2.0 → python_redsys-2.3.0}/pyproject.toml +3 -1
  4. {python_redsys-2.2.0 → python_redsys-2.3.0/python_redsys.egg-info}/PKG-INFO +19 -5
  5. {python_redsys-2.2.0 → python_redsys-2.3.0}/python_redsys.egg-info/SOURCES.txt +6 -0
  6. python_redsys-2.3.0/redsys/_deprecation.py +27 -0
  7. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/environments.py +17 -3
  8. python_redsys-2.3.0/redsys/api/languages.py +138 -0
  9. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/transactions.py +10 -3
  10. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/clients.py +122 -28
  11. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/codes.py +9 -11
  12. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/exceptions.py +1 -1
  13. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/models.py +31 -3
  14. python_redsys-2.3.0/redsys/testing.py +77 -0
  15. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_bizum.py +1 -1
  16. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_codes.py +1 -1
  17. python_redsys-2.3.0/tests/test_deprecated_names.py +125 -0
  18. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_direct.py +5 -4
  19. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_environments.py +20 -20
  20. python_redsys-2.3.0/tests/test_languages.py +52 -0
  21. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_live.py +7 -7
  22. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_operations.py +9 -9
  23. python_redsys-2.3.0/tests/test_parse_response.py +187 -0
  24. python_redsys-2.3.0/tests/test_testing.py +116 -0
  25. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_threeds.py +5 -5
  26. python_redsys-2.2.0/redsys/api/languages.py +0 -75
  27. {python_redsys-2.2.0 → python_redsys-2.3.0}/LICENSE +0 -0
  28. {python_redsys-2.2.0 → python_redsys-2.3.0}/NOTICE +0 -0
  29. {python_redsys-2.2.0 → python_redsys-2.3.0}/python_redsys.egg-info/dependency_links.txt +0 -0
  30. {python_redsys-2.2.0 → python_redsys-2.3.0}/python_redsys.egg-info/requires.txt +0 -0
  31. {python_redsys-2.2.0 → python_redsys-2.3.0}/python_redsys.egg-info/top_level.txt +0 -0
  32. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/__init__.py +0 -0
  33. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/_code_texts.py +0 -0
  34. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/__init__.py +0 -0
  35. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/bizum.py +0 -0
  36. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/cards.py +0 -0
  37. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/cof.py +0 -0
  38. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/currencies.py +0 -0
  39. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/emv3ds.py +0 -0
  40. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/options.py +0 -0
  41. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/pay_methods.py +0 -0
  42. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/paygold.py +0 -0
  43. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/processed_pay_methods.py +0 -0
  44. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/responses.py +0 -0
  45. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/sca.py +0 -0
  46. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/secure_payment.py +0 -0
  47. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/api/xpay.py +0 -0
  48. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/crypto.py +0 -0
  49. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/orders.py +0 -0
  50. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/py.typed +0 -0
  51. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/request.py +0 -0
  52. {python_redsys-2.2.0 → python_redsys-2.3.0}/redsys/threeds.py +0 -0
  53. {python_redsys-2.2.0 → python_redsys-2.3.0}/setup.cfg +0 -0
  54. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_clients.py +0 -0
  55. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_constants.py +0 -0
  56. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_crypto.py +0 -0
  57. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_models.py +0 -0
  58. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_orders.py +0 -0
  59. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_parameters.py +0 -0
  60. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_paygold.py +0 -0
  61. {python_redsys-2.2.0 → python_redsys-2.3.0}/tests/test_xpay.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-redsys
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A simple, lightweight client to handle payments through the RedSys platform.
5
5
  Author-email: David Díaz <d.diazp@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -97,7 +97,7 @@ from redsys import emv3ds, threeds
97
97
  card = dict(pan="4548810000000003", expiry_date="4912", cvv2="123")
98
98
  operation = dict(order=generate_order(), amount=Decimal("10.56"))
99
99
 
100
- config = client.inicia_payment(**operation, **card).send()
100
+ config = client.start_payment(**operation, **card).send()
101
101
  # Optional 3DSMethod: the browser posts threeds.method_data(...) to config.three_ds_method_url.
102
102
 
103
103
  authentication = threeds.authentication_data(
@@ -134,7 +134,7 @@ client.payment(
134
134
  ## Payment methods
135
135
 
136
136
  - **Bizum, redirect:** `pay_methods=pay_methods.BIZUM` on `payment()`.
137
- - **Bizum Request-to-Pay, direct:** the same, plus `bizum_mobile_number` and `endpoint=client.url(environments.RTP_TRATA_PATH)`; read `response.rtp_status` and `response.rtp_response` (`redsys.bizum`).
137
+ - **Bizum Request-to-Pay, direct:** the same, plus `bizum_mobile_number` and `endpoint=client.url(environments.RTP_OPERATION_PATH)`; read `response.rtp_status` and `response.rtp_response` (`redsys.bizum`).
138
138
  - **PayGold link:** `pay_gold(customer_mobile=..., customer_sms_text=f"{paygold.SMS_AMOUNT} {paygold.SMS_URL}")`; the link is `response.url_pago_2_fases`.
139
139
  - **Google Pay and Apple Pay:** `xpay_data` (or `xpay_decoded_data`) with `xpay_type=xpay.GOOGLE` and `xpay_origen=xpay.WEB`.
140
140
  - **inSite:** `idoper=` with the token from RedSys's JavaScript, on a direct `payment()`.
@@ -149,6 +149,7 @@ client.payment(
149
149
  | `signature_version=` | `HMAC_SHA512_V2` (default), `HMAC_SHA512_V1` or legacy `HMAC_SHA256_V1`, from `redsys.clients` |
150
150
  | `module=` | `Ds_Merchant_Module` of every request: `python-redsys/<version>` by default, another text, or `None` to leave it out |
151
151
  | `endpoint=` on an operation | Sends that request to another HTTPS URL; `client.url(path)` builds one |
152
+ | `consumer_language=` on an operation | Payment page language: `languages.from_iso("es-ES")` turns an ISO 639-1 code or a locale tag into its `redsys.languages` value, `languages.DEFAULT` for a language RedSys does not list |
152
153
 
153
154
  Every documented value has a named constant in `redsys` (`transactions`, `currencies`, `languages`, `pay_methods`, `cof`, `sca`, `options`, `emv3ds`, `cards`, `responses`, ...). Use them instead of literals.
154
155
 
@@ -161,11 +162,24 @@ Fields are validated when the operation method is called, before anything is sig
161
162
  | A field with the wrong type or format, a missing required field, a misspelled or 1.x field name, an unknown currency or transaction type | `pydantic.ValidationError`; `.errors()` lists each field |
162
163
  | A transaction type that contradicts the operation or the redirect connection, a non-HTTPS `endpoint`, an invalid API key or environment | `redsys.exceptions.ValidationError` |
163
164
  | A signature that does not match in `parse_response()` | `ValueError` |
165
+ | A payload in `parse_response()` or an answer in `send()` that is not a well-formed RedSys result, for example without a signature or not a Base64-encoded JSON object | `redsys.exceptions.ValidationError` |
164
166
  | RedSys answers with an error code instead of a signed result | `redsys.exceptions.ResponseError`; `.error_code` holds the `SISnnnn` code |
165
167
  | An HTTP error status from RedSys in `send()` | `httpx.HTTPStatusError` |
166
168
 
167
169
  A parameter the library does not model yet can be passed by its wire name (`Ds_Merchant_...`): it is sent as given, with an `UnknownParameterWarning`.
168
170
 
171
+ ## Testing
172
+
173
+ `redsys.testing.signed_response()` builds what RedSys posts to `merchant_url` or answers to a direct call, signed with the client's key, to test the code that receives it. `response` defaults to `"0000"`; other fields go by attribute or wire name, and `amount` in major units.
174
+
175
+ ```python
176
+ from redsys import responses
177
+ from redsys.testing import signed_response
178
+
179
+ payload = signed_response(client, order="1234ABCD", amount=Decimal("10.56"), response=responses.DECLINED)
180
+ assert not client.parse_response(payload).is_paid()
181
+ ```
182
+
169
183
  ## Response codes
170
184
 
171
185
  `response.response_code` is the integer `Ds_Response`; `response.is_paid()` (0 to 99), `is_refunded()` (900), `is_canceled()` (400) and `is_authorized()` (any of them) cover the common outcomes. `response.describe(language)` and `redsys.codes.describe(code, language)` give the meaning of any `Ds_Response`, `SISnnnn` or Bizum `BIZnnnnn` code. Table: [`docs/response-codes.md`](docs/response-codes.md).
@@ -174,7 +188,7 @@ A parameter the library does not model yet can be passed by its wire name (`Ds_M
174
188
 
175
189
  | | |
176
190
  |---|---|
177
- | Version | 2.2.0; 1.x receives fixes until 2026-12-31 ([migration guide](docs/migration-1x-to-2x.md)) |
191
+ | Version | 2.3.0; 1.x receives fixes until 2026-12-31 ([migration guide](docs/migration-1x-to-2x.md)) |
178
192
  | Python | 3.10 to 3.15 |
179
193
  | RedSys documents followed | Redirection guide 4.2, REST guide 4.0.1, Bizum guide 2.6, inSite guide 4.1, PayGold guide 1.8.2, Google Pay guide 1.9, Apple Pay guide 3.2, "Parámetros de entrada y salida" page |
180
194
  | Verified against the RedSys test environment | Redirect in a browser with the 3DS challenge; direct end to end (frictionless and challenged 3DS, 3DSMethod, refund, void, payment cancellation, stored-card merchant-initiated charge), in all three signature versions |
@@ -183,5 +197,5 @@ A parameter the library does not model yet can be passed by its wire name (`Ds_M
183
197
 
184
198
  - [`docs/redirect-connection.md`](docs/redirect-connection.md) and [`docs/direct-connection.md`](docs/direct-connection.md): protocol reference for each connection.
185
199
  - [`docs/response-codes.md`](docs/response-codes.md): response, SIS and Bizum codes.
186
- - [`docs/official-libraries.md`](docs/official-libraries.md): equivalences for integrators of RedSys's PHP and Java libraries.
200
+ - [`docs/official-libraries.md`](docs/official-libraries.md): RedSys's names (operations, endpoints, the libraries' concepts) and their python-redsys equivalents, including the names deprecated until 3.0.
187
201
  - [`CONTRIBUTING.md`](CONTRIBUTING.md): development setup, checks and live tests.
@@ -68,7 +68,7 @@ from redsys import emv3ds, threeds
68
68
  card = dict(pan="4548810000000003", expiry_date="4912", cvv2="123")
69
69
  operation = dict(order=generate_order(), amount=Decimal("10.56"))
70
70
 
71
- config = client.inicia_payment(**operation, **card).send()
71
+ config = client.start_payment(**operation, **card).send()
72
72
  # Optional 3DSMethod: the browser posts threeds.method_data(...) to config.three_ds_method_url.
73
73
 
74
74
  authentication = threeds.authentication_data(
@@ -105,7 +105,7 @@ client.payment(
105
105
  ## Payment methods
106
106
 
107
107
  - **Bizum, redirect:** `pay_methods=pay_methods.BIZUM` on `payment()`.
108
- - **Bizum Request-to-Pay, direct:** the same, plus `bizum_mobile_number` and `endpoint=client.url(environments.RTP_TRATA_PATH)`; read `response.rtp_status` and `response.rtp_response` (`redsys.bizum`).
108
+ - **Bizum Request-to-Pay, direct:** the same, plus `bizum_mobile_number` and `endpoint=client.url(environments.RTP_OPERATION_PATH)`; read `response.rtp_status` and `response.rtp_response` (`redsys.bizum`).
109
109
  - **PayGold link:** `pay_gold(customer_mobile=..., customer_sms_text=f"{paygold.SMS_AMOUNT} {paygold.SMS_URL}")`; the link is `response.url_pago_2_fases`.
110
110
  - **Google Pay and Apple Pay:** `xpay_data` (or `xpay_decoded_data`) with `xpay_type=xpay.GOOGLE` and `xpay_origen=xpay.WEB`.
111
111
  - **inSite:** `idoper=` with the token from RedSys's JavaScript, on a direct `payment()`.
@@ -120,6 +120,7 @@ client.payment(
120
120
  | `signature_version=` | `HMAC_SHA512_V2` (default), `HMAC_SHA512_V1` or legacy `HMAC_SHA256_V1`, from `redsys.clients` |
121
121
  | `module=` | `Ds_Merchant_Module` of every request: `python-redsys/<version>` by default, another text, or `None` to leave it out |
122
122
  | `endpoint=` on an operation | Sends that request to another HTTPS URL; `client.url(path)` builds one |
123
+ | `consumer_language=` on an operation | Payment page language: `languages.from_iso("es-ES")` turns an ISO 639-1 code or a locale tag into its `redsys.languages` value, `languages.DEFAULT` for a language RedSys does not list |
123
124
 
124
125
  Every documented value has a named constant in `redsys` (`transactions`, `currencies`, `languages`, `pay_methods`, `cof`, `sca`, `options`, `emv3ds`, `cards`, `responses`, ...). Use them instead of literals.
125
126
 
@@ -132,11 +133,24 @@ Fields are validated when the operation method is called, before anything is sig
132
133
  | A field with the wrong type or format, a missing required field, a misspelled or 1.x field name, an unknown currency or transaction type | `pydantic.ValidationError`; `.errors()` lists each field |
133
134
  | A transaction type that contradicts the operation or the redirect connection, a non-HTTPS `endpoint`, an invalid API key or environment | `redsys.exceptions.ValidationError` |
134
135
  | A signature that does not match in `parse_response()` | `ValueError` |
136
+ | A payload in `parse_response()` or an answer in `send()` that is not a well-formed RedSys result, for example without a signature or not a Base64-encoded JSON object | `redsys.exceptions.ValidationError` |
135
137
  | RedSys answers with an error code instead of a signed result | `redsys.exceptions.ResponseError`; `.error_code` holds the `SISnnnn` code |
136
138
  | An HTTP error status from RedSys in `send()` | `httpx.HTTPStatusError` |
137
139
 
138
140
  A parameter the library does not model yet can be passed by its wire name (`Ds_Merchant_...`): it is sent as given, with an `UnknownParameterWarning`.
139
141
 
142
+ ## Testing
143
+
144
+ `redsys.testing.signed_response()` builds what RedSys posts to `merchant_url` or answers to a direct call, signed with the client's key, to test the code that receives it. `response` defaults to `"0000"`; other fields go by attribute or wire name, and `amount` in major units.
145
+
146
+ ```python
147
+ from redsys import responses
148
+ from redsys.testing import signed_response
149
+
150
+ payload = signed_response(client, order="1234ABCD", amount=Decimal("10.56"), response=responses.DECLINED)
151
+ assert not client.parse_response(payload).is_paid()
152
+ ```
153
+
140
154
  ## Response codes
141
155
 
142
156
  `response.response_code` is the integer `Ds_Response`; `response.is_paid()` (0 to 99), `is_refunded()` (900), `is_canceled()` (400) and `is_authorized()` (any of them) cover the common outcomes. `response.describe(language)` and `redsys.codes.describe(code, language)` give the meaning of any `Ds_Response`, `SISnnnn` or Bizum `BIZnnnnn` code. Table: [`docs/response-codes.md`](docs/response-codes.md).
@@ -145,7 +159,7 @@ A parameter the library does not model yet can be passed by its wire name (`Ds_M
145
159
 
146
160
  | | |
147
161
  |---|---|
148
- | Version | 2.2.0; 1.x receives fixes until 2026-12-31 ([migration guide](docs/migration-1x-to-2x.md)) |
162
+ | Version | 2.3.0; 1.x receives fixes until 2026-12-31 ([migration guide](docs/migration-1x-to-2x.md)) |
149
163
  | Python | 3.10 to 3.15 |
150
164
  | RedSys documents followed | Redirection guide 4.2, REST guide 4.0.1, Bizum guide 2.6, inSite guide 4.1, PayGold guide 1.8.2, Google Pay guide 1.9, Apple Pay guide 3.2, "Parámetros de entrada y salida" page |
151
165
  | Verified against the RedSys test environment | Redirect in a browser with the 3DS challenge; direct end to end (frictionless and challenged 3DS, 3DSMethod, refund, void, payment cancellation, stored-card merchant-initiated charge), in all three signature versions |
@@ -154,5 +168,5 @@ A parameter the library does not model yet can be passed by its wire name (`Ds_M
154
168
 
155
169
  - [`docs/redirect-connection.md`](docs/redirect-connection.md) and [`docs/direct-connection.md`](docs/direct-connection.md): protocol reference for each connection.
156
170
  - [`docs/response-codes.md`](docs/response-codes.md): response, SIS and Bizum codes.
157
- - [`docs/official-libraries.md`](docs/official-libraries.md): equivalences for integrators of RedSys's PHP and Java libraries.
171
+ - [`docs/official-libraries.md`](docs/official-libraries.md): RedSys's names (operations, endpoints, the libraries' concepts) and their python-redsys equivalents, including the names deprecated until 3.0.
158
172
  - [`CONTRIBUTING.md`](CONTRIBUTING.md): development setup, checks and live tests.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-redsys"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "A simple, lightweight client to handle payments through the RedSys platform."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -63,6 +63,8 @@ quote-style = "single"
63
63
 
64
64
  [tool.coverage.report]
65
65
  fail_under = 95
66
+ # Read by type checkers only.
67
+ exclude_also = ['if _typing\.TYPE_CHECKING:']
66
68
 
67
69
  [tool.mypy]
68
70
  python_version = "3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-redsys
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A simple, lightweight client to handle payments through the RedSys platform.
5
5
  Author-email: David Díaz <d.diazp@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -97,7 +97,7 @@ from redsys import emv3ds, threeds
97
97
  card = dict(pan="4548810000000003", expiry_date="4912", cvv2="123")
98
98
  operation = dict(order=generate_order(), amount=Decimal("10.56"))
99
99
 
100
- config = client.inicia_payment(**operation, **card).send()
100
+ config = client.start_payment(**operation, **card).send()
101
101
  # Optional 3DSMethod: the browser posts threeds.method_data(...) to config.three_ds_method_url.
102
102
 
103
103
  authentication = threeds.authentication_data(
@@ -134,7 +134,7 @@ client.payment(
134
134
  ## Payment methods
135
135
 
136
136
  - **Bizum, redirect:** `pay_methods=pay_methods.BIZUM` on `payment()`.
137
- - **Bizum Request-to-Pay, direct:** the same, plus `bizum_mobile_number` and `endpoint=client.url(environments.RTP_TRATA_PATH)`; read `response.rtp_status` and `response.rtp_response` (`redsys.bizum`).
137
+ - **Bizum Request-to-Pay, direct:** the same, plus `bizum_mobile_number` and `endpoint=client.url(environments.RTP_OPERATION_PATH)`; read `response.rtp_status` and `response.rtp_response` (`redsys.bizum`).
138
138
  - **PayGold link:** `pay_gold(customer_mobile=..., customer_sms_text=f"{paygold.SMS_AMOUNT} {paygold.SMS_URL}")`; the link is `response.url_pago_2_fases`.
139
139
  - **Google Pay and Apple Pay:** `xpay_data` (or `xpay_decoded_data`) with `xpay_type=xpay.GOOGLE` and `xpay_origen=xpay.WEB`.
140
140
  - **inSite:** `idoper=` with the token from RedSys's JavaScript, on a direct `payment()`.
@@ -149,6 +149,7 @@ client.payment(
149
149
  | `signature_version=` | `HMAC_SHA512_V2` (default), `HMAC_SHA512_V1` or legacy `HMAC_SHA256_V1`, from `redsys.clients` |
150
150
  | `module=` | `Ds_Merchant_Module` of every request: `python-redsys/<version>` by default, another text, or `None` to leave it out |
151
151
  | `endpoint=` on an operation | Sends that request to another HTTPS URL; `client.url(path)` builds one |
152
+ | `consumer_language=` on an operation | Payment page language: `languages.from_iso("es-ES")` turns an ISO 639-1 code or a locale tag into its `redsys.languages` value, `languages.DEFAULT` for a language RedSys does not list |
152
153
 
153
154
  Every documented value has a named constant in `redsys` (`transactions`, `currencies`, `languages`, `pay_methods`, `cof`, `sca`, `options`, `emv3ds`, `cards`, `responses`, ...). Use them instead of literals.
154
155
 
@@ -161,11 +162,24 @@ Fields are validated when the operation method is called, before anything is sig
161
162
  | A field with the wrong type or format, a missing required field, a misspelled or 1.x field name, an unknown currency or transaction type | `pydantic.ValidationError`; `.errors()` lists each field |
162
163
  | A transaction type that contradicts the operation or the redirect connection, a non-HTTPS `endpoint`, an invalid API key or environment | `redsys.exceptions.ValidationError` |
163
164
  | A signature that does not match in `parse_response()` | `ValueError` |
165
+ | A payload in `parse_response()` or an answer in `send()` that is not a well-formed RedSys result, for example without a signature or not a Base64-encoded JSON object | `redsys.exceptions.ValidationError` |
164
166
  | RedSys answers with an error code instead of a signed result | `redsys.exceptions.ResponseError`; `.error_code` holds the `SISnnnn` code |
165
167
  | An HTTP error status from RedSys in `send()` | `httpx.HTTPStatusError` |
166
168
 
167
169
  A parameter the library does not model yet can be passed by its wire name (`Ds_Merchant_...`): it is sent as given, with an `UnknownParameterWarning`.
168
170
 
171
+ ## Testing
172
+
173
+ `redsys.testing.signed_response()` builds what RedSys posts to `merchant_url` or answers to a direct call, signed with the client's key, to test the code that receives it. `response` defaults to `"0000"`; other fields go by attribute or wire name, and `amount` in major units.
174
+
175
+ ```python
176
+ from redsys import responses
177
+ from redsys.testing import signed_response
178
+
179
+ payload = signed_response(client, order="1234ABCD", amount=Decimal("10.56"), response=responses.DECLINED)
180
+ assert not client.parse_response(payload).is_paid()
181
+ ```
182
+
169
183
  ## Response codes
170
184
 
171
185
  `response.response_code` is the integer `Ds_Response`; `response.is_paid()` (0 to 99), `is_refunded()` (900), `is_canceled()` (400) and `is_authorized()` (any of them) cover the common outcomes. `response.describe(language)` and `redsys.codes.describe(code, language)` give the meaning of any `Ds_Response`, `SISnnnn` or Bizum `BIZnnnnn` code. Table: [`docs/response-codes.md`](docs/response-codes.md).
@@ -174,7 +188,7 @@ A parameter the library does not model yet can be passed by its wire name (`Ds_M
174
188
 
175
189
  | | |
176
190
  |---|---|
177
- | Version | 2.2.0; 1.x receives fixes until 2026-12-31 ([migration guide](docs/migration-1x-to-2x.md)) |
191
+ | Version | 2.3.0; 1.x receives fixes until 2026-12-31 ([migration guide](docs/migration-1x-to-2x.md)) |
178
192
  | Python | 3.10 to 3.15 |
179
193
  | RedSys documents followed | Redirection guide 4.2, REST guide 4.0.1, Bizum guide 2.6, inSite guide 4.1, PayGold guide 1.8.2, Google Pay guide 1.9, Apple Pay guide 3.2, "Parámetros de entrada y salida" page |
180
194
  | Verified against the RedSys test environment | Redirect in a browser with the 3DS challenge; direct end to end (frictionless and challenged 3DS, 3DSMethod, refund, void, payment cancellation, stored-card merchant-initiated charge), in all three signature versions |
@@ -183,5 +197,5 @@ A parameter the library does not model yet can be passed by its wire name (`Ds_M
183
197
 
184
198
  - [`docs/redirect-connection.md`](docs/redirect-connection.md) and [`docs/direct-connection.md`](docs/direct-connection.md): protocol reference for each connection.
185
199
  - [`docs/response-codes.md`](docs/response-codes.md): response, SIS and Bizum codes.
186
- - [`docs/official-libraries.md`](docs/official-libraries.md): equivalences for integrators of RedSys's PHP and Java libraries.
200
+ - [`docs/official-libraries.md`](docs/official-libraries.md): RedSys's names (operations, endpoints, the libraries' concepts) and their python-redsys equivalents, including the names deprecated until 3.0.
187
201
  - [`CONTRIBUTING.md`](CONTRIBUTING.md): development setup, checks and live tests.
@@ -9,6 +9,7 @@ python_redsys.egg-info/requires.txt
9
9
  python_redsys.egg-info/top_level.txt
10
10
  redsys/__init__.py
11
11
  redsys/_code_texts.py
12
+ redsys/_deprecation.py
12
13
  redsys/clients.py
13
14
  redsys/codes.py
14
15
  redsys/crypto.py
@@ -17,6 +18,7 @@ redsys/models.py
17
18
  redsys/orders.py
18
19
  redsys/py.typed
19
20
  redsys/request.py
21
+ redsys/testing.py
20
22
  redsys/threeds.py
21
23
  redsys/api/__init__.py
22
24
  redsys/api/bizum.py
@@ -40,13 +42,17 @@ tests/test_clients.py
40
42
  tests/test_codes.py
41
43
  tests/test_constants.py
42
44
  tests/test_crypto.py
45
+ tests/test_deprecated_names.py
43
46
  tests/test_direct.py
44
47
  tests/test_environments.py
48
+ tests/test_languages.py
45
49
  tests/test_live.py
46
50
  tests/test_models.py
47
51
  tests/test_operations.py
48
52
  tests/test_orders.py
49
53
  tests/test_parameters.py
54
+ tests/test_parse_response.py
50
55
  tests/test_paygold.py
56
+ tests/test_testing.py
51
57
  tests/test_threeds.py
52
58
  tests/test_xpay.py
@@ -0,0 +1,27 @@
1
+ """Deprecated aliases of renamed public names; each warns and resolves to its replacement."""
2
+
3
+ import sys
4
+ from collections.abc import Callable
5
+ from typing import Any
6
+ from warnings import warn
7
+
8
+
9
+ def deprecated(old: str, new: str, stacklevel: int = 3) -> None:
10
+ """Warn that ``old`` goes away in 3.0; the default level points past the deprecated accessor to its caller."""
11
+ warn(f'{old} is deprecated and goes away in 3.0: use {new}.', DeprecationWarning, stacklevel=stacklevel)
12
+
13
+
14
+ def module_aliases(module: str, aliases: dict[str, str]) -> Callable[[str], Any]:
15
+ """A module ``__getattr__`` that serves each old name in ``aliases`` as its new one.
16
+
17
+ Served names stay out of ``dir()``, so introspection does not warn.
18
+ """
19
+ label = module.rpartition('.')[2]
20
+
21
+ def __getattr__(name: str) -> Any:
22
+ if name not in aliases:
23
+ raise AttributeError(f'module {module!r} has no attribute {name!r}')
24
+ deprecated(f'{label}.{name}', f'{label}.{aliases[name]}')
25
+ return getattr(sys.modules[module], aliases[name])
26
+
27
+ return __getattr__
@@ -1,5 +1,9 @@
1
1
  """RedSys environments and their hosts."""
2
2
 
3
+ import typing as _typing
4
+
5
+ from redsys._deprecation import module_aliases as _module_aliases
6
+
3
7
  DESA = 'DESA'
4
8
  """Development."""
5
9
 
@@ -22,16 +26,16 @@ HOSTS = {
22
26
  REDIRECT_PATH = '/sis/realizarPago'
23
27
  """Redirect connection."""
24
28
 
25
- INICIA_PATH = '/sis/rest/iniciaPeticionREST'
29
+ START_PATH = '/sis/rest/iniciaPeticionREST'
26
30
  """Direct connection: 3-D Secure initialization."""
27
31
 
28
- TRATA_PATH = '/sis/rest/trataPeticionREST'
32
+ OPERATION_PATH = '/sis/rest/trataPeticionREST'
29
33
  """Direct connection: operations."""
30
34
 
31
35
  RTP_CHECK_PATH = '/sis/rest/RTP/checkRtpUsuario'
32
36
  """Bizum Request-to-Pay: whether the customer can receive a payment request."""
33
37
 
34
- RTP_TRATA_PATH = '/sis/rest/RTP/trataPeticionREST'
38
+ RTP_OPERATION_PATH = '/sis/rest/RTP/trataPeticionREST'
35
39
  """Bizum Request-to-Pay: payment (types 0 and 7) and refund without original (type 34)."""
36
40
 
37
41
  RTP_BACKUP_PATH = '/sis/rest/RTP/respaldarUsuarioRTP'
@@ -39,3 +43,13 @@ RTP_BACKUP_PATH = '/sis/rest/RTP/respaldarUsuarioRTP'
39
43
 
40
44
  RTP_BACKUP_VALIDATION_PATH = '/sis/rest/RTP/validarRespaldoUsuarioRTP'
41
45
  """Bizum Request-to-Pay backup: validates the one-time password."""
46
+
47
+ # Type checkers see the deprecated names as plain aliases; at run time they warn.
48
+ if _typing.TYPE_CHECKING:
49
+ INICIA_PATH = START_PATH
50
+ TRATA_PATH = OPERATION_PATH
51
+ RTP_TRATA_PATH = RTP_OPERATION_PATH
52
+ else:
53
+ __getattr__ = _module_aliases(
54
+ __name__, {'INICIA_PATH': 'START_PATH', 'TRATA_PATH': 'OPERATION_PATH', 'RTP_TRATA_PATH': 'RTP_OPERATION_PATH'}
55
+ )
@@ -0,0 +1,138 @@
1
+ """Values of ``Ds_Merchant_ConsumerLanguage``; ``DEFAULT`` leaves the language undetermined."""
2
+
3
+ import typing as _typing
4
+ from re import split as _split
5
+
6
+ from redsys._deprecation import module_aliases as _module_aliases
7
+
8
+ DEFAULT = 0
9
+ SPANISH = 1
10
+ ENGLISH = 2
11
+ CATALAN = 3
12
+ FRENCH = 4
13
+ GERMAN = 5
14
+ DUTCH = 6
15
+ ITALIAN = 7
16
+ SWEDISH = 8
17
+ PORTUGUESE = 9
18
+ VALENCIAN = 10
19
+ POLISH = 11
20
+ GALICIAN = 12
21
+ BASQUE = 13
22
+ BULGARIAN = 100
23
+ CHINESE = 156
24
+ CROATIAN = 191
25
+ CZECH = 203
26
+ DANISH = 208
27
+ ESTONIAN = 233
28
+ FINNISH = 246
29
+ GREEK = 300
30
+ HUNGARIAN = 348
31
+ HINDI = 356
32
+ JAPANESE = 392
33
+ KOREAN = 410
34
+ LATVIAN = 428
35
+ LITHUANIAN = 440
36
+ MALTESE = 470
37
+ ROMANIAN = 642
38
+ RUSSIAN = 643
39
+ ARABIC = 682
40
+ SLOVAK = 703
41
+ SLOVENIAN = 705
42
+ TURKISH = 792
43
+
44
+ LANGUAGES = (
45
+ DEFAULT,
46
+ SPANISH,
47
+ ENGLISH,
48
+ CATALAN,
49
+ FRENCH,
50
+ GERMAN,
51
+ DUTCH,
52
+ ITALIAN,
53
+ SWEDISH,
54
+ PORTUGUESE,
55
+ VALENCIAN,
56
+ POLISH,
57
+ GALICIAN,
58
+ BASQUE,
59
+ BULGARIAN,
60
+ CHINESE,
61
+ CROATIAN,
62
+ CZECH,
63
+ DANISH,
64
+ ESTONIAN,
65
+ FINNISH,
66
+ GREEK,
67
+ HUNGARIAN,
68
+ HINDI,
69
+ JAPANESE,
70
+ KOREAN,
71
+ LATVIAN,
72
+ LITHUANIAN,
73
+ MALTESE,
74
+ ROMANIAN,
75
+ RUSSIAN,
76
+ ARABIC,
77
+ SLOVAK,
78
+ SLOVENIAN,
79
+ TURKISH,
80
+ )
81
+
82
+ _ISO_639_1 = {
83
+ 'es': SPANISH,
84
+ 'en': ENGLISH,
85
+ 'ca': CATALAN,
86
+ 'fr': FRENCH,
87
+ 'de': GERMAN,
88
+ 'nl': DUTCH,
89
+ 'it': ITALIAN,
90
+ 'sv': SWEDISH,
91
+ 'pt': PORTUGUESE,
92
+ 'pl': POLISH,
93
+ 'gl': GALICIAN,
94
+ 'eu': BASQUE,
95
+ 'bg': BULGARIAN,
96
+ 'zh': CHINESE,
97
+ 'hr': CROATIAN,
98
+ 'cs': CZECH,
99
+ 'da': DANISH,
100
+ 'et': ESTONIAN,
101
+ 'fi': FINNISH,
102
+ 'el': GREEK,
103
+ 'hu': HUNGARIAN,
104
+ 'hi': HINDI,
105
+ 'ja': JAPANESE,
106
+ 'ko': KOREAN,
107
+ 'lv': LATVIAN,
108
+ 'lt': LITHUANIAN,
109
+ 'mt': MALTESE,
110
+ 'ro': ROMANIAN,
111
+ 'ru': RUSSIAN,
112
+ 'ar': ARABIC,
113
+ 'sk': SLOVAK,
114
+ 'sl': SLOVENIAN,
115
+ 'tr': TURKISH,
116
+ }
117
+
118
+
119
+ def from_iso(code: str | None) -> int:
120
+ """The value for an ISO 639-1 code or a locale tag: ``'es'``, ``'es-ES'``, ``'pt_BR'``, ``'es_ES.UTF-8'``.
121
+
122
+ The first subtag names the language, in any case. Catalan with the ``valencia`` variant
123
+ (``'ca-ES-valencia'``, ``'ca_ES@valencia'``) gives ``VALENCIAN``. A language RedSys does not
124
+ list, or anything that is not text, gives ``DEFAULT``.
125
+ """
126
+ if not isinstance(code, str):
127
+ return DEFAULT
128
+ subtags = _split(r'[-_.@]', code.lower())
129
+ if subtags[0] == 'ca' and 'valencia' in subtags[1:]:
130
+ return VALENCIAN
131
+ return _ISO_639_1.get(subtags[0], DEFAULT)
132
+
133
+
134
+ # Type checkers see the deprecated names as plain aliases; at run time they warn.
135
+ if _typing.TYPE_CHECKING:
136
+ EUSKERA = BASQUE
137
+ else:
138
+ __getattr__ = _module_aliases(__name__, {'EUSKERA': 'BASQUE'})
@@ -1,5 +1,9 @@
1
1
  """Values of ``Ds_Merchant_TransactionType``."""
2
2
 
3
+ import typing as _typing
4
+
5
+ from redsys._deprecation import module_aliases as _module_aliases
6
+
3
7
  AUTHORIZATION = 0
4
8
  """Authorization."""
5
9
 
@@ -21,9 +25,6 @@ AUTHENTICATION_CONFIRMATION = 8
21
25
  VOID = 9
22
26
  """Void of a preauthorization ("Anulación de preautorización")."""
23
27
 
24
- CANCELLATION = VOID
25
- """Former name of ``VOID``."""
26
-
27
28
  REPLACEMENT_PREAUTHORIZATION = 11
28
29
  """Replacement preauthorization: extends an existing preauthorization."""
29
30
 
@@ -89,3 +90,9 @@ REDIRECT_TRANSACTION_TYPES = (
89
90
  REFUND_WITHOUT_ORIGINAL,
90
91
  )
91
92
  """The types the redirect connection accepts."""
93
+
94
+ # Type checkers see the deprecated names as plain aliases; at run time they warn.
95
+ if _typing.TYPE_CHECKING:
96
+ CANCELLATION = VOID
97
+ else:
98
+ __getattr__ = _module_aliases(__name__, {'CANCELLATION': 'VOID'})