PageConfig (db_blog) decoupling: - Blog: add page-config, page-config-by-id, page-configs-batch data endpoints - Blog: add update-page-config action endpoint for events payment admin - Cart: hydrate_page, resolve_page_config, get_cart_grouped_by_page all fetch PageConfig from blog via HTTP instead of direct DB query - Cart: check_sumup_status auto-fetches page_config from blog when needed - Events: payment routes read/write PageConfig via blog HTTP endpoints - Order model: remove cross-domain page_config ORM relationship (keep column) Cart + Market DB merge: - Cart tables (cart_items, orders, order_items) moved into db_market - Cart app DATABASE_URL now points to db_market (same bounded context) - CartItem.product / CartItem.market_place relationships work again (same database, no cross-domain join issues) - Updated split-databases.sh, init-databases.sql, docker-compose.yml Ghost sync fix: - Wrap PostAuthor/PostTag delete+re-add in no_autoflush block - Use synchronize_session="fetch" to keep identity map consistent - Prevents query-invoked autoflush IntegrityError on composite PK Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from quart import (
|
|
render_template, make_response, Blueprint, g, request
|
|
)
|
|
|
|
from shared.infrastructure.data_client import fetch_data
|
|
from shared.infrastructure.actions import call_action
|
|
from shared.browser.app.authz import require_admin
|
|
from shared.browser.app.utils.htmx import is_htmx_request
|
|
|
|
|
|
def register():
|
|
bp = Blueprint("payments", __name__, url_prefix='/payments')
|
|
|
|
@bp.context_processor
|
|
async def inject_root():
|
|
return {}
|
|
|
|
async def _load_payment_ctx():
|
|
"""Load PageConfig SumUp data for the current page (from blog)."""
|
|
post = (getattr(g, "post_data", None) or {}).get("post", {})
|
|
post_id = post.get("id")
|
|
if not post_id:
|
|
return {}
|
|
|
|
raw_pc = await fetch_data(
|
|
"blog", "page-config",
|
|
params={"container_type": "page", "container_id": post_id},
|
|
required=False,
|
|
)
|
|
pc = SimpleNamespace(**raw_pc) if raw_pc else None
|
|
|
|
return {
|
|
"sumup_configured": bool(pc and getattr(pc, "sumup_api_key", None)),
|
|
"sumup_merchant_code": (getattr(pc, "sumup_merchant_code", None) or "") if pc else "",
|
|
"sumup_checkout_prefix": (getattr(pc, "sumup_checkout_prefix", None) or "") if pc else "",
|
|
}
|
|
|
|
@bp.get("/")
|
|
@require_admin
|
|
async def home(**kwargs):
|
|
ctx = await _load_payment_ctx()
|
|
if not is_htmx_request():
|
|
html = await render_template("_types/payments/index.html", **ctx)
|
|
else:
|
|
html = await render_template("_types/payments/_oob_elements.html", **ctx)
|
|
return await make_response(html)
|
|
|
|
@bp.put("/")
|
|
@require_admin
|
|
async def update_sumup(**kwargs):
|
|
"""Update SumUp credentials for this page (writes to blog's db_blog)."""
|
|
post = (getattr(g, "post_data", None) or {}).get("post", {})
|
|
post_id = post.get("id")
|
|
if not post_id:
|
|
return await make_response("Post not found", 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()
|
|
|
|
payload = {
|
|
"container_type": "page",
|
|
"container_id": post_id,
|
|
"sumup_merchant_code": merchant_code,
|
|
"sumup_checkout_prefix": checkout_prefix,
|
|
}
|
|
if api_key:
|
|
payload["sumup_api_key"] = api_key
|
|
|
|
await call_action("blog", "update-page-config", payload=payload)
|
|
|
|
ctx = await _load_payment_ctx()
|
|
html = await render_template("_types/payments/_main_panel.html", **ctx)
|
|
return await make_response(html)
|
|
|
|
return bp
|