pretix-enablebanking 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.
- pretix_enablebanking-1.0.0/.gitignore +28 -0
- pretix_enablebanking-1.0.0/LICENSE +21 -0
- pretix_enablebanking-1.0.0/Makefile +11 -0
- pretix_enablebanking-1.0.0/PKG-INFO +124 -0
- pretix_enablebanking-1.0.0/README.md +110 -0
- pretix_enablebanking-1.0.0/docs/images/import.png +0 -0
- pretix_enablebanking-1.0.0/docs/images/settings.png +0 -0
- pretix_enablebanking-1.0.0/pretixplugin.toml +4 -0
- pretix_enablebanking-1.0.0/pyproject.toml +33 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/__init__.py +1 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/apps.py +38 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/enablebanking_client.py +125 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/forms.py +69 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/locale/de/LC_MESSAGES/django.po +478 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/locale/de_Informal/.gitkeep +0 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/locale/de_Informal/LC_MESSAGES/django.po +478 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/migrations/0001_initial.py +68 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/migrations/__init__.py +0 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/models.py +59 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/signals.py +77 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/static/pretix_enablebanking/pretix_enablebanking.js +17 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/tasks.py +113 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/templates/pretix_enablebanking/import.html +200 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/templates/pretix_enablebanking/settings.html +183 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/urls.py +12 -0
- pretix_enablebanking-1.0.0/src/pretix_enablebanking/views.py +312 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
env/
|
|
2
|
+
build/
|
|
3
|
+
dist/
|
|
4
|
+
.coverage
|
|
5
|
+
htmlcov/
|
|
6
|
+
.ropeproject
|
|
7
|
+
*.sqlite3
|
|
8
|
+
*.db
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*.swp
|
|
11
|
+
*.aux
|
|
12
|
+
*.log
|
|
13
|
+
*.toc
|
|
14
|
+
*.mo
|
|
15
|
+
*~
|
|
16
|
+
.ropeproject
|
|
17
|
+
__pycache__/
|
|
18
|
+
_static/
|
|
19
|
+
.idea
|
|
20
|
+
.secret
|
|
21
|
+
atlassian-ide-plugin.xml
|
|
22
|
+
pretixeu/
|
|
23
|
+
local/
|
|
24
|
+
.project
|
|
25
|
+
.pydevproject
|
|
26
|
+
.DS_Store
|
|
27
|
+
.venv
|
|
28
|
+
.claude
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nico Knoll
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
all: localecompile
|
|
2
|
+
|
|
3
|
+
LNGS := $(shell find src/pretix_enablebanking/locale/ -mindepth 1 -maxdepth 1 -type d -printf "-l %f ")
|
|
4
|
+
|
|
5
|
+
localecompile:
|
|
6
|
+
django-admin compilemessages
|
|
7
|
+
|
|
8
|
+
localegen:
|
|
9
|
+
django-admin makemessages --keep-pot -i build -i dist -i "*egg*" $(LNGS)
|
|
10
|
+
|
|
11
|
+
.PHONY: all localecompile localegen
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pretix-enablebanking
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Automatically import bank transactions via Enable Banking (PSD2/Open Banking) into pretix
|
|
5
|
+
Project-URL: Homepage, https://github.com/nicoknoll/pretix-enablebanking
|
|
6
|
+
Project-URL: Repository, https://github.com/nicoknoll/pretix-enablebanking
|
|
7
|
+
Author-email: Nico Knoll <mail@nico.is>
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: pretix
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: pretix>=2.7.0
|
|
12
|
+
Requires-Dist: requests
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# pretix-enablebanking
|
|
16
|
+
|
|
17
|
+
Connects pretix to your bank via [Enable Banking](https://enablebanking.com) (PSD2/Open Banking). Once configured, it periodically fetches bank transactions and feeds them into pretix's bank transfer pipeline — automatically matching incoming payments to orders.
|
|
18
|
+
|
|
19
|
+
**Key capabilities:**
|
|
20
|
+
- OAuth-based bank connection via 400+ European banks (PSD2)
|
|
21
|
+
- Automatic and on-demand transaction import
|
|
22
|
+
- Multi-account support with per-account activation toggle
|
|
23
|
+
- Configurable auto-fetch interval (every 1h, 4h, 12h, or 24h)
|
|
24
|
+
- Works at organizer level (one connection per organizer)
|
|
25
|
+
|
|
26
|
+
## Screenshots
|
|
27
|
+
|
|
28
|
+
**Import — manual fetch & job history**
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
**Settings — bank connection & API credentials**
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
## How it works
|
|
37
|
+
|
|
38
|
+
1. You register an app at Enable Banking and get an App ID + RSA private key.
|
|
39
|
+
2. You enter those credentials in the plugin settings and initiate an OAuth flow to connect your bank account.
|
|
40
|
+
3. After authorization, Enable Banking provides access to your bank accounts. You activate the ones you want to import from.
|
|
41
|
+
4. The plugin fetches transactions (automatically or on demand) and creates `BankImportJob` records, which pretix then processes to match payments against open orders.
|
|
42
|
+
|
|
43
|
+
The transaction import runs as a Celery task and uses Enable Banking's paginated transactions API. The last-fetched date per account is tracked to avoid re-importing.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install pretix-enablebanking
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Then run migrations and restart the server:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python -m pretix migrate
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The plugin registers itself automatically via the `pretix.plugin` entry point — no manual `INSTALLED_APPS` edit needed.
|
|
58
|
+
|
|
59
|
+
### Development installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/nicoknoll/pretix-enablebanking.git
|
|
63
|
+
cd pretix-enablebanking
|
|
64
|
+
pip install -e .
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Setup in pretix
|
|
68
|
+
|
|
69
|
+
### 1. Get Enable Banking credentials
|
|
70
|
+
|
|
71
|
+
1. Sign up at [developers.enablebanking.com](https://developers.enablebanking.com) and create an application.
|
|
72
|
+
2. Generate an RSA key pair. Register the public key with Enable Banking and keep the private key (PEM format).
|
|
73
|
+
3. Note your **Application ID**.
|
|
74
|
+
|
|
75
|
+
### 2. Configure the plugin
|
|
76
|
+
|
|
77
|
+
In the pretix backend, go to your organizer → **Bank transfer** → **Enable Banking settings**:
|
|
78
|
+
|
|
79
|
+
- **Application ID** — the App ID from Enable Banking
|
|
80
|
+
- **Private key (PEM)** — your RSA private key (`-----BEGIN PRIVATE KEY-----` format)
|
|
81
|
+
- **Country** — used to filter the list of available banks (ASPSPs)
|
|
82
|
+
- **Auto-fetch interval** — how often transactions should be fetched automatically (set to "disabled" to import manually only)
|
|
83
|
+
|
|
84
|
+
Save, then select your bank from the dropdown and click **Connect with bank**. You'll be redirected to Enable Banking's hosted authorization page where you log into your bank and grant consent.
|
|
85
|
+
|
|
86
|
+
After authorization, you're redirected back and your accounts appear in the settings. Activate the accounts you want to import from and save.
|
|
87
|
+
|
|
88
|
+
### 3. Import transactions
|
|
89
|
+
|
|
90
|
+
Go to **Bank transfer** → **Automatic import** to:
|
|
91
|
+
|
|
92
|
+
- Trigger a manual import (optionally specify a start date)
|
|
93
|
+
- View recent import jobs and their status
|
|
94
|
+
- See when your bank connection expires (Enable Banking consent is typically valid for 90 days — renew before it expires)
|
|
95
|
+
|
|
96
|
+
## Testing with the sandbox
|
|
97
|
+
|
|
98
|
+
Enable Banking provides a sandbox environment with a mock bank. Use these credentials when connecting **Aachener Bank** (country: **DE**):
|
|
99
|
+
|
|
100
|
+
| Field | Value |
|
|
101
|
+
|---|---|
|
|
102
|
+
| VR NetKey | `VRK1234567890ALL` |
|
|
103
|
+
| PIN | `password` |
|
|
104
|
+
| OTP | `123456` |
|
|
105
|
+
|
|
106
|
+
The import view shows a **Sandbox mode** warning when a mock bank is connected.
|
|
107
|
+
|
|
108
|
+
## Dependencies
|
|
109
|
+
|
|
110
|
+
| Package | Purpose |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `pretix >= 2.7.0` | Host platform |
|
|
113
|
+
| `requests` | HTTP calls to Enable Banking API |
|
|
114
|
+
| `PyJWT` | RS256-signed JWT for API authentication (transitive via pretix) |
|
|
115
|
+
|
|
116
|
+
Python 3.10+ required.
|
|
117
|
+
|
|
118
|
+
## Permissions
|
|
119
|
+
|
|
120
|
+
The plugin operates at organizer level. Users need **can_change_organizer_settings** to access settings and trigger imports.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# pretix-enablebanking
|
|
2
|
+
|
|
3
|
+
Connects pretix to your bank via [Enable Banking](https://enablebanking.com) (PSD2/Open Banking). Once configured, it periodically fetches bank transactions and feeds them into pretix's bank transfer pipeline — automatically matching incoming payments to orders.
|
|
4
|
+
|
|
5
|
+
**Key capabilities:**
|
|
6
|
+
- OAuth-based bank connection via 400+ European banks (PSD2)
|
|
7
|
+
- Automatic and on-demand transaction import
|
|
8
|
+
- Multi-account support with per-account activation toggle
|
|
9
|
+
- Configurable auto-fetch interval (every 1h, 4h, 12h, or 24h)
|
|
10
|
+
- Works at organizer level (one connection per organizer)
|
|
11
|
+
|
|
12
|
+
## Screenshots
|
|
13
|
+
|
|
14
|
+
**Import — manual fetch & job history**
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
**Settings — bank connection & API credentials**
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
## How it works
|
|
23
|
+
|
|
24
|
+
1. You register an app at Enable Banking and get an App ID + RSA private key.
|
|
25
|
+
2. You enter those credentials in the plugin settings and initiate an OAuth flow to connect your bank account.
|
|
26
|
+
3. After authorization, Enable Banking provides access to your bank accounts. You activate the ones you want to import from.
|
|
27
|
+
4. The plugin fetches transactions (automatically or on demand) and creates `BankImportJob` records, which pretix then processes to match payments against open orders.
|
|
28
|
+
|
|
29
|
+
The transaction import runs as a Celery task and uses Enable Banking's paginated transactions API. The last-fetched date per account is tracked to avoid re-importing.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install pretix-enablebanking
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then run migrations and restart the server:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python -m pretix migrate
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The plugin registers itself automatically via the `pretix.plugin` entry point — no manual `INSTALLED_APPS` edit needed.
|
|
44
|
+
|
|
45
|
+
### Development installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/nicoknoll/pretix-enablebanking.git
|
|
49
|
+
cd pretix-enablebanking
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Setup in pretix
|
|
54
|
+
|
|
55
|
+
### 1. Get Enable Banking credentials
|
|
56
|
+
|
|
57
|
+
1. Sign up at [developers.enablebanking.com](https://developers.enablebanking.com) and create an application.
|
|
58
|
+
2. Generate an RSA key pair. Register the public key with Enable Banking and keep the private key (PEM format).
|
|
59
|
+
3. Note your **Application ID**.
|
|
60
|
+
|
|
61
|
+
### 2. Configure the plugin
|
|
62
|
+
|
|
63
|
+
In the pretix backend, go to your organizer → **Bank transfer** → **Enable Banking settings**:
|
|
64
|
+
|
|
65
|
+
- **Application ID** — the App ID from Enable Banking
|
|
66
|
+
- **Private key (PEM)** — your RSA private key (`-----BEGIN PRIVATE KEY-----` format)
|
|
67
|
+
- **Country** — used to filter the list of available banks (ASPSPs)
|
|
68
|
+
- **Auto-fetch interval** — how often transactions should be fetched automatically (set to "disabled" to import manually only)
|
|
69
|
+
|
|
70
|
+
Save, then select your bank from the dropdown and click **Connect with bank**. You'll be redirected to Enable Banking's hosted authorization page where you log into your bank and grant consent.
|
|
71
|
+
|
|
72
|
+
After authorization, you're redirected back and your accounts appear in the settings. Activate the accounts you want to import from and save.
|
|
73
|
+
|
|
74
|
+
### 3. Import transactions
|
|
75
|
+
|
|
76
|
+
Go to **Bank transfer** → **Automatic import** to:
|
|
77
|
+
|
|
78
|
+
- Trigger a manual import (optionally specify a start date)
|
|
79
|
+
- View recent import jobs and their status
|
|
80
|
+
- See when your bank connection expires (Enable Banking consent is typically valid for 90 days — renew before it expires)
|
|
81
|
+
|
|
82
|
+
## Testing with the sandbox
|
|
83
|
+
|
|
84
|
+
Enable Banking provides a sandbox environment with a mock bank. Use these credentials when connecting **Aachener Bank** (country: **DE**):
|
|
85
|
+
|
|
86
|
+
| Field | Value |
|
|
87
|
+
|---|---|
|
|
88
|
+
| VR NetKey | `VRK1234567890ALL` |
|
|
89
|
+
| PIN | `password` |
|
|
90
|
+
| OTP | `123456` |
|
|
91
|
+
|
|
92
|
+
The import view shows a **Sandbox mode** warning when a mock bank is connected.
|
|
93
|
+
|
|
94
|
+
## Dependencies
|
|
95
|
+
|
|
96
|
+
| Package | Purpose |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `pretix >= 2.7.0` | Host platform |
|
|
99
|
+
| `requests` | HTTP calls to Enable Banking API |
|
|
100
|
+
| `PyJWT` | RS256-signed JWT for API authentication (transitive via pretix) |
|
|
101
|
+
|
|
102
|
+
Python 3.10+ required.
|
|
103
|
+
|
|
104
|
+
## Permissions
|
|
105
|
+
|
|
106
|
+
The plugin operates at organizer level. Users need **can_change_organizer_settings** to access settings and trigger imports.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT — see [LICENSE](LICENSE).
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pretix-enablebanking"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Automatically import bank transactions via Enable Banking (PSD2/Open Banking) into pretix"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
keywords = ["pretix"]
|
|
13
|
+
authors = [
|
|
14
|
+
{name = "Nico Knoll", email = "mail@nico.is"},
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"pretix>=2.7.0",
|
|
18
|
+
"requests",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/nicoknoll/pretix-enablebanking"
|
|
23
|
+
Repository = "https://github.com/nicoknoll/pretix-enablebanking"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.wheel]
|
|
26
|
+
packages = ["src/pretix_enablebanking"]
|
|
27
|
+
core-metadata-version = "2.3"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.sdist]
|
|
30
|
+
core-metadata-version = "2.3"
|
|
31
|
+
|
|
32
|
+
[project.entry-points."pretix.plugin"]
|
|
33
|
+
pretix_enablebanking = "pretix_enablebanking.apps:PluginApp"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from django.utils.translation import gettext_lazy
|
|
2
|
+
from . import __version__
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from pretix.base.plugins import PluginConfig, PLUGIN_LEVEL_ORGANIZER
|
|
6
|
+
except ImportError:
|
|
7
|
+
raise RuntimeError("Please use pretix 2.7 or above to run this plugin!")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PluginApp(PluginConfig):
|
|
11
|
+
default = True
|
|
12
|
+
name = "pretix_enablebanking"
|
|
13
|
+
verbose_name = "Enable Banking"
|
|
14
|
+
|
|
15
|
+
class PretixPluginMeta:
|
|
16
|
+
name = gettext_lazy("Enable Banking")
|
|
17
|
+
author = "Nico Knoll"
|
|
18
|
+
description = gettext_lazy(
|
|
19
|
+
"Automatically import bank transactions via Enable Banking (PSD2/Open Banking) "
|
|
20
|
+
"into the pretix bank transfer pipeline."
|
|
21
|
+
)
|
|
22
|
+
visible = True
|
|
23
|
+
version = __version__
|
|
24
|
+
category = "PAYMENT"
|
|
25
|
+
compatibility = "pretix>=2.7.0"
|
|
26
|
+
level = PLUGIN_LEVEL_ORGANIZER
|
|
27
|
+
|
|
28
|
+
def uninstalled(self, organizer):
|
|
29
|
+
from .models import EnableBankingConnection
|
|
30
|
+
|
|
31
|
+
for key in ('enablebanking_app_id', 'enablebanking_private_key',
|
|
32
|
+
'enablebanking_fetch_interval', 'enablebanking_country'):
|
|
33
|
+
organizer.settings.delete(key)
|
|
34
|
+
|
|
35
|
+
EnableBankingConnection.objects.filter(organizer=organizer).delete()
|
|
36
|
+
|
|
37
|
+
def ready(self):
|
|
38
|
+
from . import signals # NOQA
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import uuid
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
|
+
|
|
5
|
+
import jwt as pyjwt
|
|
6
|
+
import requests
|
|
7
|
+
from django.core.exceptions import ImproperlyConfigured
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class EnableBankingClient:
|
|
13
|
+
BASE_URL = 'https://api.enablebanking.com'
|
|
14
|
+
|
|
15
|
+
def __init__(self, app_id, private_key_pem):
|
|
16
|
+
self.app_id = app_id
|
|
17
|
+
self.private_key_pem = private_key_pem
|
|
18
|
+
|
|
19
|
+
def _create_jwt(self):
|
|
20
|
+
iat = int(datetime.now(tz=timezone.utc).timestamp())
|
|
21
|
+
payload = {
|
|
22
|
+
"iss": "enablebanking.com",
|
|
23
|
+
"aud": "api.enablebanking.com",
|
|
24
|
+
"iat": iat,
|
|
25
|
+
"exp": iat + 3600,
|
|
26
|
+
}
|
|
27
|
+
return pyjwt.encode(
|
|
28
|
+
payload,
|
|
29
|
+
self.private_key_pem,
|
|
30
|
+
algorithm="RS256",
|
|
31
|
+
headers={"kid": self.app_id},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def _headers(self):
|
|
35
|
+
return {"Authorization": f"Bearer {self._create_jwt()}"}
|
|
36
|
+
|
|
37
|
+
def list_aspsps(self, country=None):
|
|
38
|
+
params = {}
|
|
39
|
+
if country:
|
|
40
|
+
params["country"] = country
|
|
41
|
+
|
|
42
|
+
resp = requests.get(
|
|
43
|
+
f"{self.BASE_URL}/aspsps",
|
|
44
|
+
params=params,
|
|
45
|
+
headers=self._headers(),
|
|
46
|
+
timeout=30,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if not resp.ok:
|
|
50
|
+
logger.error('Enable Banking GET /aspsps failed %s: %s', resp.status_code, resp.text)
|
|
51
|
+
|
|
52
|
+
resp.raise_for_status()
|
|
53
|
+
return resp.json().get("aspsps", [])
|
|
54
|
+
|
|
55
|
+
def create_auth(self, aspsp_name, aspsp_country, redirect_url, maximum_consent_validity=None):
|
|
56
|
+
# Use the ASPSP's maximum_consent_validity (seconds) if provided, else fall back to 90 days
|
|
57
|
+
seconds = maximum_consent_validity if maximum_consent_validity else 90 * 24 * 3600
|
|
58
|
+
valid_until = (
|
|
59
|
+
datetime.now(tz=timezone.utc) + timedelta(seconds=seconds)
|
|
60
|
+
).strftime("%Y-%m-%dT%H:%M:%S.000000+00:00")
|
|
61
|
+
|
|
62
|
+
body = {
|
|
63
|
+
"access": {"valid_until": valid_until},
|
|
64
|
+
"aspsp": {"name": aspsp_name, "country": aspsp_country},
|
|
65
|
+
"state": str(uuid.uuid4()),
|
|
66
|
+
"redirect_url": redirect_url,
|
|
67
|
+
"psu_type": "personal",
|
|
68
|
+
}
|
|
69
|
+
resp = requests.post(
|
|
70
|
+
f"{self.BASE_URL}/auth",
|
|
71
|
+
json=body,
|
|
72
|
+
headers=self._headers(),
|
|
73
|
+
timeout=30,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if not resp.ok:
|
|
77
|
+
logger.error('Enable Banking POST /auth failed %s: %s', resp.status_code, resp.text)
|
|
78
|
+
|
|
79
|
+
resp.raise_for_status()
|
|
80
|
+
return resp.json()
|
|
81
|
+
|
|
82
|
+
def create_session(self, code):
|
|
83
|
+
resp = requests.post(
|
|
84
|
+
f"{self.BASE_URL}/sessions",
|
|
85
|
+
json={"code": code},
|
|
86
|
+
headers=self._headers(),
|
|
87
|
+
timeout=30,
|
|
88
|
+
)
|
|
89
|
+
resp.raise_for_status()
|
|
90
|
+
return resp.json()
|
|
91
|
+
|
|
92
|
+
def get_transactions(self, account_uid, date_from=None):
|
|
93
|
+
params = {}
|
|
94
|
+
if date_from:
|
|
95
|
+
params["date_from"] = str(date_from)
|
|
96
|
+
|
|
97
|
+
transactions = []
|
|
98
|
+
while True:
|
|
99
|
+
resp = requests.get(
|
|
100
|
+
f"{self.BASE_URL}/accounts/{account_uid}/transactions",
|
|
101
|
+
params=params,
|
|
102
|
+
headers=self._headers(),
|
|
103
|
+
timeout=60,
|
|
104
|
+
)
|
|
105
|
+
resp.raise_for_status()
|
|
106
|
+
data = resp.json()
|
|
107
|
+
transactions.extend(data.get("transactions", []))
|
|
108
|
+
continuation_key = data.get("continuation_key")
|
|
109
|
+
|
|
110
|
+
if not continuation_key:
|
|
111
|
+
break
|
|
112
|
+
|
|
113
|
+
params["continuation_key"] = continuation_key
|
|
114
|
+
|
|
115
|
+
return {"booked": transactions, "pending": []}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def get_enablebanking_client(organizer):
|
|
119
|
+
app_id = organizer.settings.get('enablebanking_app_id', default='')
|
|
120
|
+
private_key = organizer.settings.get('enablebanking_private_key', default='')
|
|
121
|
+
|
|
122
|
+
if not app_id or not private_key:
|
|
123
|
+
raise ImproperlyConfigured('Enable Banking app_id and private_key must be configured.')
|
|
124
|
+
|
|
125
|
+
return EnableBankingClient(app_id, private_key)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from django import forms
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
|
|
4
|
+
from pretix.base.forms import SettingsForm
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class EnableBankingSettingsForm(SettingsForm):
|
|
8
|
+
enablebanking_app_id = forms.CharField(
|
|
9
|
+
label=_('Application ID'),
|
|
10
|
+
required=False,
|
|
11
|
+
help_text=_('Your Enable Banking application ID.'),
|
|
12
|
+
)
|
|
13
|
+
enablebanking_private_key = forms.CharField(
|
|
14
|
+
label=_('Private Key (PEM)'),
|
|
15
|
+
required=False,
|
|
16
|
+
widget=forms.Textarea(attrs={'rows': 10, 'style': 'font-family: monospace;'}),
|
|
17
|
+
help_text=_('Your RSA private key in PEM format for Enable Banking API authentication.'),
|
|
18
|
+
)
|
|
19
|
+
enablebanking_fetch_interval = forms.ChoiceField(
|
|
20
|
+
label=_('Automatic fetch interval'),
|
|
21
|
+
choices=(
|
|
22
|
+
('0', _('Disabled')),
|
|
23
|
+
('60', _('Every hour')),
|
|
24
|
+
('240', _('Every 4 hours')),
|
|
25
|
+
('720', _('Every 12 hours')),
|
|
26
|
+
('1440', _('Every 24 hours')),
|
|
27
|
+
),
|
|
28
|
+
initial='0',
|
|
29
|
+
required=False,
|
|
30
|
+
help_text=_('How often to automatically fetch new transactions.'),
|
|
31
|
+
)
|
|
32
|
+
enablebanking_country = forms.ChoiceField(
|
|
33
|
+
label=_('Country'),
|
|
34
|
+
required=False,
|
|
35
|
+
initial='DE',
|
|
36
|
+
choices=[
|
|
37
|
+
('AT', _('Austria')),
|
|
38
|
+
('BE', _('Belgium')),
|
|
39
|
+
('BG', _('Bulgaria')),
|
|
40
|
+
('HR', _('Croatia')),
|
|
41
|
+
('CY', _('Cyprus')),
|
|
42
|
+
('CZ', _('Czech Republic')),
|
|
43
|
+
('DK', _('Denmark')),
|
|
44
|
+
('EE', _('Estonia')),
|
|
45
|
+
('FI', _('Finland')),
|
|
46
|
+
('FR', _('France')),
|
|
47
|
+
('DE', _('Germany')),
|
|
48
|
+
('GR', _('Greece')),
|
|
49
|
+
('HU', _('Hungary')),
|
|
50
|
+
('IS', _('Iceland')),
|
|
51
|
+
('IE', _('Ireland')),
|
|
52
|
+
('IT', _('Italy')),
|
|
53
|
+
('LV', _('Latvia')),
|
|
54
|
+
('LI', _('Liechtenstein')),
|
|
55
|
+
('LT', _('Lithuania')),
|
|
56
|
+
('LU', _('Luxembourg')),
|
|
57
|
+
('MT', _('Malta')),
|
|
58
|
+
('NL', _('Netherlands')),
|
|
59
|
+
('NO', _('Norway')),
|
|
60
|
+
('PL', _('Poland')),
|
|
61
|
+
('PT', _('Portugal')),
|
|
62
|
+
('RO', _('Romania')),
|
|
63
|
+
('SK', _('Slovakia')),
|
|
64
|
+
('SI', _('Slovenia')),
|
|
65
|
+
('ES', _('Spain')),
|
|
66
|
+
('SE', _('Sweden')),
|
|
67
|
+
],
|
|
68
|
+
help_text=_('Country to filter available banks.'),
|
|
69
|
+
)
|