From d859be217a6777ca68373f31463fad2721db74f6 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 10 Feb 2026 20:49:30 +0000 Subject: [PATCH] feat: per-page SumUp admin UI and update_sumup route (Phase 3) - Replace SumUp placeholder with real form for merchant code, API key, prefix - Add PUT /admin/sumup/ route to save per-page SumUp credentials - Pass sumup_configured/merchant_code/checkout_prefix to template context - SumUp form only shown when calendar or market feature is enabled Co-Authored-By: Claude Opus 4.6 --- bp/post/admin/routes.py | 60 +++++++++++++++- .../_types/post/admin/_features_panel.html | 69 ++++++++++++++++++- 2 files changed, 125 insertions(+), 4 deletions(-) diff --git a/bp/post/admin/routes.py b/bp/post/admin/routes.py index 96a45a4..5e1accd 100644 --- a/bp/post/admin/routes.py +++ b/bp/post/admin/routes.py @@ -28,14 +28,25 @@ def register(): # Load features for page admin post = (g.post_data or {}).get("post", {}) features = {} + sumup_configured = False + sumup_merchant_code = "" + sumup_checkout_prefix = "" if post.get("is_page"): pc = (await g.s.execute( sa_select(PageConfig).where(PageConfig.post_id == post["id"]) )).scalar_one_or_none() if pc: features = pc.features or {} + sumup_configured = bool(pc.sumup_api_key) + sumup_merchant_code = pc.sumup_merchant_code or "" + sumup_checkout_prefix = pc.sumup_checkout_prefix or "" - ctx = {"features": features} + ctx = { + "features": features, + "sumup_configured": sumup_configured, + "sumup_merchant_code": sumup_merchant_code, + "sumup_checkout_prefix": sumup_checkout_prefix, + } # Determine which template to use based on request type if not is_htmx_request(): @@ -104,6 +115,53 @@ def register(): "_types/post/admin/_features_panel.html", features=features, post=post, + sumup_configured=bool(pc.sumup_api_key), + sumup_merchant_code=pc.sumup_merchant_code or "", + sumup_checkout_prefix=pc.sumup_checkout_prefix or "", + ) + return await make_response(html) + + @bp.put("/admin/sumup/") + @require_admin + async def update_sumup(slug: str): + """Update PageConfig SumUp credentials for a page.""" + from models.page_config import PageConfig + from sqlalchemy import select as sa_select + from quart import jsonify + + post = g.post_data.get("post") + if not post or not post.get("is_page"): + return jsonify({"error": "This is not a page."}), 400 + + post_id = post["id"] + + pc = (await g.s.execute( + sa_select(PageConfig).where(PageConfig.post_id == post_id) + )).scalar_one_or_none() + if pc is None: + return jsonify({"error": "PageConfig not found for this page."}), 404 + + form = await request.form + merchant_code = (form.get("merchant_code") or "").strip() + api_key = (form.get("api_key") or "").strip() + checkout_prefix = (form.get("checkout_prefix") or "").strip() + + pc.sumup_merchant_code = merchant_code or None + pc.sumup_checkout_prefix = checkout_prefix or None + # Only update API key if non-empty (allows updating other fields without re-entering key) + if api_key: + pc.sumup_api_key = api_key + + await g.s.flush() + + features = pc.features or {} + html = await render_template( + "_types/post/admin/_features_panel.html", + features=features, + post=post, + sumup_configured=bool(pc.sumup_api_key), + sumup_merchant_code=pc.sumup_merchant_code or "", + sumup_checkout_prefix=pc.sumup_checkout_prefix or "", ) return await make_response(html) diff --git a/templates/_types/post/admin/_features_panel.html b/templates/_types/post/admin/_features_panel.html index ae2ad6f..19f9296 100644 --- a/templates/_types/post/admin/_features_panel.html +++ b/templates/_types/post/admin/_features_panel.html @@ -41,9 +41,72 @@ - {# Phase 3: SumUp connection placeholder #} + {# SumUp credentials — shown when calendar or market is enabled #} + {% if features.get('calendar') or features.get('market') %}
-

SumUp Payment

-

Payment connection coming soon.

+

+ + SumUp Payment +

+

+ Configure per-page SumUp credentials. Leave blank to use the global merchant account. +

+ +
+
+ + +
+ +
+ + + {% if sumup_configured %} +

Key is set. Leave blank to keep current key.

+ {% endif %} +
+ +
+ + +
+ + + + {% if sumup_configured %} + + Connected + + {% endif %} +
+ {% endif %}