Skip to content

Commit 8fd732b

Browse files
DAdjadjclaude
andcommitted
Add per-connection account type selection (personal/business)
Move psu_type from global setup to the connect form so each bank connection can use a different account type. Also clean up the Enable Banking account fetching — remove broken /sessions endpoint call that was always 404ing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f409381 commit 8fd732b

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

app/enablebanking.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@ def _make_headers():
5050
token = jwt.encode(payload, key, algorithm="RS256", headers={"kid": _get_app_id()})
5151
return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
5252

53-
def start_auth(bank_name: str, bank_country: str) -> dict:
53+
def start_auth(bank_name: str, bank_country: str, psu_type: str = "") -> dict:
5454
valid_until = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(time.time() + 180 * 24 * 3600))
5555
state_val = str(uuid.uuid4())
5656
body = {
5757
"access": {"valid_until": valid_until},
5858
"aspsp": {"name": bank_name, "country": bank_country},
5959
"state": f"bridge-bank-auth|{config.BRIDGE_BANK_URL or "http://localhost:3002"}|{state_val}",
6060
"redirect_url": "https://bridgebank.app/callback",
61-
"psu_type": config.EB_PSU_TYPE,
61+
"psu_type": psu_type or config.EB_PSU_TYPE,
6262
}
6363
db.set_setting("pending_session_state", state_val)
6464
db.set_setting("pending_session_valid_until", valid_until)
65+
logger.info("Starting auth for %s (%s) with psu_type=%s", bank_name, bank_country, body["psu_type"])
6566
r = requests.post(f"{EB_API}/auth", json=body, headers=_make_headers())
6667
r.raise_for_status()
6768
return {"url": r.json()["url"]}
@@ -75,18 +76,7 @@ def complete_auth(code: str, state: str) -> dict:
7576
data = r.json()
7677
session_id = data["session_id"]
7778
accounts = data.get("accounts", [])
78-
logger.info("Enable Banking session response returned %d account(s): %s", len(accounts), accounts)
79-
# The session response may only include a subset of consented accounts.
80-
# Fetch the full list from the dedicated accounts endpoint.
81-
try:
82-
acct_resp = requests.get(f"{EB_API}/sessions/{session_id}/accounts", headers=_make_headers())
83-
acct_resp.raise_for_status()
84-
full_accounts = acct_resp.json().get("accounts", [])
85-
if len(full_accounts) > len(accounts):
86-
logger.info("Accounts endpoint returned %d account(s): %s", len(full_accounts), full_accounts)
87-
accounts = full_accounts
88-
except Exception as e:
89-
logger.warning("Could not fetch full account list: %s", e)
79+
logger.info("Bank returned %d account(s) via Enable Banking", len(accounts))
9080
if not accounts:
9181
return None
9282
valid_until = db.get_setting("pending_session_valid_until")

app/web/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def connect():
291291
bank_country = request.form.get("bank_country", "").strip()
292292
actual_account = request.form.get("actual_account", "").strip()
293293
start_sync_date = request.form.get("start_sync_date", "").strip()
294+
psu_type = request.form.get("psu_type", "personal").strip()
294295
if not bank_name or not bank_country:
295296
error = "Please select a bank."
296297
elif not actual_account:
@@ -323,7 +324,7 @@ def connect():
323324
host = request.headers.get("X-Forwarded-Host", request.host)
324325
config.set("BRIDGE_BANK_URL", f"{scheme}://{host}")
325326
from .. import enablebanking
326-
result = enablebanking.start_auth(bank_name, bank_country)
327+
result = enablebanking.start_auth(bank_name, bank_country, psu_type=psu_type)
327328
auth_url = result["url"]
328329
except Exception as e:
329330
error = f"Could not start bank connection: {e}"

app/web/templates/connect.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
<label>Actual Budget account</label>
107107
<input type="text" name="actual_account" id="actual-account-input" placeholder="e.g. Revolut" required oninput="checkReady()">
108108
<div class="field-hint">The name of the account in Actual Budget where transactions will be synced.</div>
109+
<label>Account type</label>
110+
<select name="psu_type" id="psu-type" style="width:100%;">
111+
<option value="personal" selected>Personal</option>
112+
<option value="business">Business / Pro</option>
113+
</select>
114+
<div class="field-hint">Choose Business / Pro if connecting a Revolut Pro or business bank account.</div>
109115
<label>Search your bank</label>
110116
<div style="position:relative;">
111117
<input type="text" id="bank-search" placeholder="Type to search 2,500+ European banks..." autocomplete="off" oninput="filterBanks(this.value)" onfocus="showDropdown()">
@@ -115,7 +121,7 @@
115121
<span id="selected-label" style="font-weight:600;color:#e8edf5;"></span>
116122
<button type="button" onclick="clearBank()" style="background:none;border:none;color:#4a5568;cursor:pointer;font-size:11px;padding:0;">clear</button>
117123
</div>
118-
<div class="field-hint">Personal accounts only. 2,500+ banks across 29 European countries.</div>
124+
<div class="field-hint">2,500+ banks across 29 European countries.</div>
119125
<button class="btn btn-primary" type="submit" id="connect-btn" disabled style="background:var(--surface2); opacity:0.5;">Add bank &rarr;</button>
120126
</form>
121127
{% endif %}

app/web/templates/setup_bank.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727
{% endif %}
2828
<input type="file" id="pem_file" name="pem_file" accept=".pem" {% if not pem_uploaded %}required{% endif %}>
2929
<div class="field-hint">Your private.pem file from the Enable Banking dashboard. It stays on your server and is never shared.</div>
30-
<label for="eb_psu_type">Account type</label>
31-
<select id="eb_psu_type" name="eb_psu_type">
32-
<option value="personal" {% if eb_psu_type == "personal" %}selected{% endif %}>Personal</option>
33-
<option value="business" {% if eb_psu_type == "business" %}selected{% endif %}>Business</option>
34-
</select>
3530
<button class="btn btn-primary" type="submit">Continue &rarr;</button>
3631
</form>
3732
</div>

0 commit comments

Comments
 (0)