django-redsys 1.0.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.
- django_redsys-1.0.0/CHANGELOG.md +43 -0
- django_redsys-1.0.0/CONTRIBUTORS.md +9 -0
- django_redsys-1.0.0/LICENSE +202 -0
- django_redsys-1.0.0/MANIFEST.in +4 -0
- django_redsys-1.0.0/NOTICE +7 -0
- django_redsys-1.0.0/PKG-INFO +239 -0
- django_redsys-1.0.0/README.md +206 -0
- django_redsys-1.0.0/ROADMAP.md +13 -0
- django_redsys-1.0.0/django_redsys/__init__.py +1 -0
- django_redsys-1.0.0/django_redsys/apps.py +9 -0
- django_redsys-1.0.0/django_redsys/checks.py +44 -0
- django_redsys-1.0.0/django_redsys/client.py +20 -0
- django_redsys-1.0.0/django_redsys/conf.py +13 -0
- django_redsys-1.0.0/django_redsys/notifications/__init__.py +1 -0
- django_redsys-1.0.0/django_redsys/notifications/admin.py +17 -0
- django_redsys-1.0.0/django_redsys/notifications/apps.py +9 -0
- django_redsys-1.0.0/django_redsys/notifications/management/__init__.py +1 -0
- django_redsys-1.0.0/django_redsys/notifications/management/commands/__init__.py +1 -0
- django_redsys-1.0.0/django_redsys/notifications/management/commands/purge_redsys_notifications.py +20 -0
- django_redsys-1.0.0/django_redsys/notifications/migrations/0001_initial.py +49 -0
- django_redsys-1.0.0/django_redsys/notifications/migrations/__init__.py +1 -0
- django_redsys-1.0.0/django_redsys/notifications/models.py +84 -0
- django_redsys-1.0.0/django_redsys/signals.py +8 -0
- django_redsys-1.0.0/django_redsys/templates/django_redsys/ko.html +15 -0
- django_redsys-1.0.0/django_redsys/templates/django_redsys/ok.html +15 -0
- django_redsys-1.0.0/django_redsys/templates/django_redsys/redirect.html +20 -0
- django_redsys-1.0.0/django_redsys/urls.py +10 -0
- django_redsys-1.0.0/django_redsys/views.py +169 -0
- django_redsys-1.0.0/django_redsys.egg-info/PKG-INFO +239 -0
- django_redsys-1.0.0/django_redsys.egg-info/SOURCES.txt +43 -0
- django_redsys-1.0.0/django_redsys.egg-info/dependency_links.txt +1 -0
- django_redsys-1.0.0/django_redsys.egg-info/requires.txt +2 -0
- django_redsys-1.0.0/django_redsys.egg-info/top_level.txt +1 -0
- django_redsys-1.0.0/docs/migration-0.4-to-1.0.md +79 -0
- django_redsys-1.0.0/pyproject.toml +66 -0
- django_redsys-1.0.0/setup.cfg +4 -0
- django_redsys-1.0.0/tests/__init__.py +1 -0
- django_redsys-1.0.0/tests/conftest.py +43 -0
- django_redsys-1.0.0/tests/settings.py +44 -0
- django_redsys-1.0.0/tests/templates/pay-form.html +1 -0
- django_redsys-1.0.0/tests/test_checks.py +47 -0
- django_redsys-1.0.0/tests/test_client.py +49 -0
- django_redsys-1.0.0/tests/test_notifications.py +127 -0
- django_redsys-1.0.0/tests/test_views.py +237 -0
- django_redsys-1.0.0/tests/urls.py +57 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) with [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [1.0.0] - 2026-11-08
|
|
8
|
+
|
|
9
|
+
A rewrite on python-redsys 2.2 and Django 5.2 or later, published on PyPI as `django-redsys`. Upgrading from 0.4: [`docs/migration-0.4-to-1.0.md`](docs/migration-0.4-to-1.0.md).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `REDSYS_CLIENT`: the keyword options of python-redsys's `RedirectClient`, or `api_key` for `from_api_key()`.
|
|
14
|
+
- `django_redsys.client.get_client()`, which builds a client from `REDSYS_CLIENT`, the direct-connection clients included.
|
|
15
|
+
- `RedsysPaymentView`, `RedsysPaymentFormView` and `RedsysPaymentMixin`: `get_redsys_fields()` returns the operation fields and `transaction_type` selects any redirect operation (authorization, preauthorization, authentication, refund without original). `RedsysPaymentView` answers GET and POST.
|
|
16
|
+
- A `REDSYS_CLIENT` the client rejects raises `ImproperlyConfigured`; a notification that fails parsing or verification, whatever the exception, answers `400`.
|
|
17
|
+
- `ResultView` for the OK and KO pages, with the verified result as `redsys_response`; it answers `404` without a verified result or when the outcome does not match the page.
|
|
18
|
+
- `get_redsys_client()` on every view, to pay or verify with another account than `REDSYS_CLIENT`; a payment view whose `get_redsys_fields()` returns `None` answers `404`.
|
|
19
|
+
- `REDSYS_NOTIFICATION_IPS`: an optional list of addresses and networks allowed to post notifications; others get `403` before their payload is parsed.
|
|
20
|
+
- System checks: `django_redsys.E001` and `E002` for invalid settings, `W001` on `check --deploy` for a non-production environment with `DEBUG` off.
|
|
21
|
+
- `django_redsys.notifications`, an optional app that records verified notifications (read-only admin, `purge_redsys_notifications` command) and turns a repeated payload into the `notification_repeated` signal, in one transaction with the receivers.
|
|
22
|
+
- The payment page is sent with `Cache-Control: no-store`, has a `<noscript>` submit button, and carries the CSP nonce of Django's CSP middleware.
|
|
23
|
+
- Tests, `pyproject.toml` packaging and a `uv.lock`; the source distribution carries the tests and `docs/`.
|
|
24
|
+
- CI on GitHub Actions: lint, migrations in sync, tests on Python 3.10 to 3.15 and on every supported Django series, the lowest declared dependencies; Dependabot for uv and the actions. A release workflow publishes a `vX.Y.Z` tag to PyPI through trusted publishing.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- The package and app are `django_redsys` (was `redsys_gateway`), with the URL namespace and template directory of the same name.
|
|
29
|
+
- Requires python-redsys 2.2 or later (was 0.2.5), Django 5.2 or later (was 1.10) and Python 3.10 or later.
|
|
30
|
+
- `NotificationView` replaces `response_view`, at `notification/`; the OK and KO pages are at `ok/` and `ko/`.
|
|
31
|
+
- Signals: `request_created`, `notification_received`, `notification_authorized`, `notification_denied` and `notification_invalid` replace `pre_transaction`, `post_transaction`, `transaction_accepted`, `transaction_rejected`, `invalid_response` and `suspicious_response`.
|
|
32
|
+
- Licensed under the Apache License 2.0 (was MIT), as python-redsys; `NOTICE` added.
|
|
33
|
+
- The README is Markdown and documents the whole app; `CONTRIBUTORS.md` replaces `AUTHORS.rst` and `CONTRIBUTORS.rst`.
|
|
34
|
+
|
|
35
|
+
### Removed
|
|
36
|
+
|
|
37
|
+
- The per-field settings (`REDSYS_SECRET_KEY`, `REDSYS_MERCHANT_CODE`, ...), `REDSYS_REDIRECT_VIEW`, `REDSYS_TRANSACTION_ACCEPTED_VIEW` and `REDSYS_TRANSACTION_REJECTED_VIEW`.
|
|
38
|
+
- The `redirect/` URL, `GatewayForm` and `setup.py`.
|
|
39
|
+
- Python 2.7, 3.4 and 3.5, and Django 1.10.
|
|
40
|
+
|
|
41
|
+
## [0.4.2] - 2017-07-21
|
|
42
|
+
|
|
43
|
+
The last 0.x release, on python-redsys 0.2.5 and Django 1.10. Its history is in the git log.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
https://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-redsys
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Django views, URLs and signals for RedSys TPV Virtual payments, on top of python-redsys.
|
|
5
|
+
Author-email: David Díaz <d.diazp@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ddiazpinto/django-redsys
|
|
8
|
+
Project-URL: Source, https://github.com/ddiazpinto/django-redsys
|
|
9
|
+
Keywords: django,redsys,sermepa,tpv,payments
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Framework :: Django
|
|
12
|
+
Classifier: Framework :: Django :: 5.2
|
|
13
|
+
Classifier: Framework :: Django :: 6.0
|
|
14
|
+
Classifier: Framework :: Django :: 6.1
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
25
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
License-File: NOTICE
|
|
30
|
+
Requires-Dist: Django>=5.2
|
|
31
|
+
Requires-Dist: python-redsys>=2.2
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# django-redsys
|
|
35
|
+
|
|
36
|
+
[](https://github.com/ddiazpinto/django-redsys/actions/workflows/ci.yml)   [](https://www.apache.org/licenses/LICENSE-2.0)
|
|
37
|
+
|
|
38
|
+
Django views, URLs and signals for RedSys TPV Virtual payments over the *redirect connection*. Signing, verification, parameters, constants and response codes come from [python-redsys](https://github.com/ddiazpinto/python-redsys); this app adds the Django side: the page that sends the cardholder to RedSys, the endpoint that receives RedSys's notification, the OK and KO pages, and signals.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install django-redsys
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
# settings.py
|
|
48
|
+
INSTALLED_APPS = [..., 'django_redsys']
|
|
49
|
+
|
|
50
|
+
REDSYS_CLIENT = {
|
|
51
|
+
'secret_key': '...',
|
|
52
|
+
'merchant_code': '999008881',
|
|
53
|
+
'terminal': 1,
|
|
54
|
+
'sandbox': True,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# urls.py
|
|
58
|
+
urlpatterns = [..., path('redsys/', include('django_redsys.urls'))]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Settings
|
|
62
|
+
|
|
63
|
+
| Setting | Use |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `REDSYS_CLIENT` | Required. The account: the keyword options of python-redsys's `RedirectClient`. |
|
|
66
|
+
| `REDSYS_NOTIFICATION_IPS` | Optional. Addresses or networks allowed to post notifications; see [Notification senders](#notification-senders). |
|
|
67
|
+
|
|
68
|
+
The keys of `REDSYS_CLIENT`:
|
|
69
|
+
|
|
70
|
+
| Key | Use |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `secret_key` | Merchant secret key. Required unless `api_key` is set. |
|
|
73
|
+
| `merchant_code`, `terminal` | Merchant code (FUC) and terminal number. |
|
|
74
|
+
| `sandbox` or `environment` | `sandbox=True` targets the test environment; `environment=` takes `redsys.environments.TEST`, `PROD`, `INTE` or `DESA`. Production by default. |
|
|
75
|
+
| `currency` | Default currency (`redsys.currencies`); the euro unless set. |
|
|
76
|
+
| `signature_version` | `HMAC_SHA512_V2` by default. |
|
|
77
|
+
| `module` | `Ds_Merchant_Module` of every request. |
|
|
78
|
+
| `api_key` | A RedSys API key, read with `RedirectClient.from_api_key()`; replaces `secret_key`, `merchant_code`, `terminal` and the environment. |
|
|
79
|
+
|
|
80
|
+
The keys go to the constructor unchanged, so an option a later python-redsys adds works without a django-redsys release. An unknown key, an invalid value, or `api_key` together with the values it replaces raises `ImproperlyConfigured`. See the [python-redsys configuration](https://github.com/ddiazpinto/python-redsys#configuration).
|
|
81
|
+
|
|
82
|
+
`manage.py check` validates both settings (`django_redsys.E001`, `django_redsys.E002`). `manage.py check --deploy` warns when `REDSYS_CLIENT` targets an environment other than production while `DEBUG` is off (`django_redsys.W001`); a staging server that uses the test environment on purpose silences it with `SILENCED_SYSTEM_CHECKS`.
|
|
83
|
+
|
|
84
|
+
## Payment view
|
|
85
|
+
|
|
86
|
+
A subclass of `RedsysPaymentView` returns the operation fields; the view signs them and renders a form that posts itself to RedSys. It answers GET and POST. A view that stores state, as the one below, is reached through a POST form (a "Pay" button): browsers and crawlers prefetch GET links, and each prefetch would use up an order number.
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from decimal import Decimal
|
|
90
|
+
|
|
91
|
+
from django.shortcuts import get_object_or_404
|
|
92
|
+
from django_redsys.views import RedsysPaymentView
|
|
93
|
+
from redsys import generate_order
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PayOrderView(RedsysPaymentView):
|
|
97
|
+
def get_redsys_fields(self):
|
|
98
|
+
order = get_object_or_404(Order, pk=self.kwargs['pk'], user=self.request.user)
|
|
99
|
+
order.redsys_order = generate_order()
|
|
100
|
+
order.save(update_fields=['redsys_order'])
|
|
101
|
+
return {
|
|
102
|
+
'order': order.redsys_order,
|
|
103
|
+
'amount': order.total, # Decimal, in euros unless currency= says otherwise
|
|
104
|
+
'merchant_data': str(order.pk),
|
|
105
|
+
'product_description': 'Online order',
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| Attribute or method | Use |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `get_redsys_fields()` | Required. The keyword fields of the operation: `order`, `amount` and any other [redirect parameter](https://github.com/ddiazpinto/python-redsys/blob/master/docs/redirect-connection.md). `None` (or `Http404` raised) when there is no order to pay: the view answers `404`. |
|
|
112
|
+
| `get_redsys_client()` | The client that signs, `get_client()` by default. A view that pays through another terminal or merchant returns its own `RedirectClient`; the notification and result views have the same method. |
|
|
113
|
+
| `transaction_type` | `redsys.transactions.AUTHORIZATION` by default; `PREAUTHORIZATION`, `AUTHENTICATION` or `REFUND_WITHOUT_ORIGINAL` for the other redirect operations. |
|
|
114
|
+
| `redirect_template_name` | `django_redsys/redirect.html` by default. |
|
|
115
|
+
| `get_redsys_request()` | Builds and signs the python-redsys `Request`; sends `request_created`. |
|
|
116
|
+
|
|
117
|
+
`merchant_url`, `url_ok` and `url_ko` default to the app's notification, OK and KO URLs; a value returned by `get_redsys_fields()` replaces them. The URLs are absolute, from `request.build_absolute_uri()`; behind a proxy that terminates TLS, `SECURE_PROXY_SSL_HEADER` makes them `https`.
|
|
118
|
+
|
|
119
|
+
The page is sent with `Cache-Control: no-store`: a cached copy would post an order number RedSys already received, which it rejects (SIS0051).
|
|
120
|
+
|
|
121
|
+
`RedsysPaymentFormView` is the same on top of `FormView`: after `form_valid()`, `self.form` holds the validated form for `get_redsys_fields()`. `RedsysPaymentMixin` holds the behavior for other view classes; `redirect_to_redsys()` returns the response.
|
|
122
|
+
|
|
123
|
+
Invalid fields raise python-redsys's `ValueError` subclasses before anything is signed ([errors](https://github.com/ddiazpinto/python-redsys#errors)).
|
|
124
|
+
|
|
125
|
+
## Notification and signals
|
|
126
|
+
|
|
127
|
+
RedSys posts the result of every operation to `merchant_url`. `NotificationView` (`django_redsys:notification`) verifies the signature, parses the result into a python-redsys `Response` and sends the signals; it answers `200` with an empty body. A payload that fails parsing or verification, whatever the exception, raises `SuspiciousOperation` chained to it: Django answers `400` and logs it on the `django.security` logger.
|
|
128
|
+
|
|
129
|
+
| Signal (`django_redsys.signals`) | Sent | Arguments |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| `request_created` | A payment view signed a request. | `request`, `redsys_request`, `fields` |
|
|
132
|
+
| `notification_received` | A notification passed verification. | `request`, `response` |
|
|
133
|
+
| `notification_authorized` | After `notification_received`, when `response.is_authorized()`. | `request`, `response` |
|
|
134
|
+
| `notification_denied` | After `notification_received`, otherwise. | `request`, `response` |
|
|
135
|
+
| `notification_invalid` | A notification failed verification or parsing, or came from an address outside `REDSYS_NOTIFICATION_IPS`. | `request`, `error` |
|
|
136
|
+
| `notification_repeated` | With [the notification record](#notification-record), a verified notification whose payload already arrived; sent instead of the three above. | `request`, `response` |
|
|
137
|
+
|
|
138
|
+
`sender` is the view class. The notification is the source of truth for an operation's outcome; the OK and KO pages are not, since the cardholder may never reach them.
|
|
139
|
+
|
|
140
|
+
A valid notification can arrive more than once. The signed result also reaches the cardholder's browser on the redirect to `url_ok` or `url_ko` (when the portal sends it, see below), and a copy posted to the notification URL verifies like the original. Receivers are idempotent: they act on the state of the order, not on the arrival of the signal, and check that the result matches what was asked for.
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from django.db import transaction
|
|
144
|
+
from django.dispatch import receiver
|
|
145
|
+
from django_redsys.signals import notification_authorized
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@receiver(notification_authorized)
|
|
149
|
+
def mark_paid(sender, request, response, **kwargs):
|
|
150
|
+
with transaction.atomic():
|
|
151
|
+
order = Order.objects.select_for_update().filter(redsys_order=response.order).first()
|
|
152
|
+
if order is None or order.is_paid or order.total != response.amount:
|
|
153
|
+
return
|
|
154
|
+
order.mark_paid(authorization_code=response.authorization_code)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`response` carries every result field (`order`, `amount`, `response_code`, `authorization_code`, `merchant_data`, `card_country`, ...) and `response.describe(language)` gives the meaning of the code; see the [response parameters](https://github.com/ddiazpinto/python-redsys/blob/master/docs/redirect-connection.md#response-parameters) and [response codes](https://github.com/ddiazpinto/python-redsys/blob/master/docs/response-codes.md). An exception in a receiver propagates, and the notification gets a `500`.
|
|
158
|
+
|
|
159
|
+
## Notification senders
|
|
160
|
+
|
|
161
|
+
`REDSYS_NOTIFICATION_IPS`, off by default, limits who may post to the notification URL. A request from any other address gets `403` before its payload is parsed, and `notification_invalid` is sent with a `PermissionDenied` error.
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
REDSYS_NOTIFICATION_IPS = ['192.0.2.10', '198.51.100.0/24'] # RedSys's addresses, as the bank or RedSys gives them
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The address compared is `REMOTE_ADDR`. Behind a proxy or load balancer, `REMOTE_ADDR` is the proxy's unless the server sets it from the forwarded header; a subclass of `NotificationView` can override `is_allowed_sender()` to read it another way. The signature check stays: the list only saves the work of parsing what does not come from RedSys.
|
|
168
|
+
|
|
169
|
+
## Notification record
|
|
170
|
+
|
|
171
|
+
`django_redsys.notifications`, an optional app, records every verified notification and turns a repeat into `notification_repeated`:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
INSTALLED_APPS = [..., 'django_redsys', 'django_redsys.notifications']
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
python manage.py migrate
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- A notification is a repeat when its `Ds_MerchantParameters` is identical to one already recorded (SHA-256 digest, unique). A new result for the same order is not a repeat. Idempotency per order stays with the receivers.
|
|
182
|
+
- The record and the signals commit in one transaction on the database the model is routed to: a receiver that raises leaves nothing recorded, and the next arrival of the same notification is processed as new.
|
|
183
|
+
- Each record keeps the order, the response code and `SISnnnn` error code, whether it was authorized, the amount and currency, the transaction type, the authorization code, the merchant code, terminal and environment (`TEST`, `PROD`, ...), whether the payment was 3-D Secure authenticated (`Ds_SecurePayment`), the payment method that processed it (`Ds_ProcessedPayMethod`), RedSys's date and hour as sent (`Ds_Date`, `Ds_Hour`), the sender address, the first and last arrival, and the number of arrivals. Card data, stored-card tokens (`Ds_Merchant_Identifier`, `Ds_Merchant_Cof_Txnid`) and `merchant_data` are not stored: a token charges the card again, and `merchant_data` is free text. Invalid notifications are not recorded.
|
|
184
|
+
- The admin lists the records read-only (`django.contrib.admin` installed). `python manage.py purge_redsys_notifications --older-than DAYS` deletes the records first received more than `DAYS` days ago, for a retention period run from cron or a scheduler.
|
|
185
|
+
- The app label is `django_redsys_notifications`.
|
|
186
|
+
|
|
187
|
+
## OK and KO pages
|
|
188
|
+
|
|
189
|
+
`django_redsys:ok` and `django_redsys:ko` render `django_redsys/ok.html` and `django_redsys/ko.html` through `ResultView`, with the verified result as `redsys_response`. RedSys appends the signed result to the redirect only when the option "Enviar Parámetros en las URLs" is on in its portal. Without a result that verifies, or with an outcome that does not match the page (an authorized result on the KO page, or the reverse), the page answers `404`. With the option off, `url_ok` and `url_ko` point to the project's own views. A template with the same name in the project replaces the app's.
|
|
190
|
+
|
|
191
|
+
## Templates and Content Security Policy
|
|
192
|
+
|
|
193
|
+
`django_redsys/redirect.html` receives `endpoint` and `fields` (the three `Ds_*` fields) and submits the form with an inline script, with a `<noscript>` button as fallback. With Django's CSP middleware (Django 6.0 and later) and the `django.template.context_processors.csp` context processor, the script carries the request's nonce; the policy then needs `CSP.NONCE` in `script-src` and the RedSys host in `form-action`:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from django.utils.csp import CSP
|
|
197
|
+
|
|
198
|
+
SECURE_CSP = {
|
|
199
|
+
'script-src': [CSP.SELF, CSP.NONCE],
|
|
200
|
+
'form-action': [CSP.SELF, 'https://sis.redsys.es', 'https://sis-t.redsys.es:25443'],
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Every template defines a `title` and a `content` block; `redirect.html` also defines `head`.
|
|
205
|
+
|
|
206
|
+
## Direct operations
|
|
207
|
+
|
|
208
|
+
`django_redsys.client.get_client()` builds the client from `REDSYS_CLIENT`; it takes another client class for the direct connection (`pip install "python-redsys[http]"`):
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from django_redsys.client import get_client
|
|
212
|
+
from redsys.clients import DirectClient
|
|
213
|
+
|
|
214
|
+
response = get_client(DirectClient).refund(order=order.redsys_order, amount=order.total).send()
|
|
215
|
+
response.is_refunded()
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Compatibility
|
|
219
|
+
|
|
220
|
+
| | |
|
|
221
|
+
|---|---|
|
|
222
|
+
| Version | 1.0.0 |
|
|
223
|
+
| Django | 5.2 LTS, 6.0 and 6.1 |
|
|
224
|
+
| Python | 3.10 to 3.15 (Django 6.0 and later need 3.12) |
|
|
225
|
+
| python-redsys | 2.2 and later |
|
|
226
|
+
|
|
227
|
+
Upgrading from 0.4: [`docs/migration-0.4-to-1.0.md`](docs/migration-0.4-to-1.0.md).
|
|
228
|
+
|
|
229
|
+
## Development
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
uv sync
|
|
233
|
+
uv run pytest
|
|
234
|
+
uv run ruff check django_redsys tests && uv run ruff format --check django_redsys tests
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
Apache License 2.0, as python-redsys. See [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE). Releases up to 0.4.2 were published under the MIT License.
|