The inter-service data layer (fetch_data/call_action) was the least structured part of the codebase — Python _handlers dicts with ad-hoc param extraction scattered across 16 route files. This replaces them with declarative .sx query/action definitions that make the entire inter-service protocol self-describing and greppable. Infrastructure: - defquery/defaction special forms in the sx evaluator - Query/action registry with load, lookup, and schema introspection - Query executor using async_eval with I/O primitives - Blueprint factories (create_data_blueprint/create_action_blueprint) with sx-first dispatch and Python fallback - /internal/schema endpoint on every service - parse-datetime and split-ids primitives for type coercion Service extractions: - LikesService (toggle, is_liked, liked_slugs, liked_ids) - PageConfigService (ensure, get_by_container, get_by_id, get_batch, update) - RelationsService (wraps module-level functions) - AccountDataService (user_by_email, newsletters) - CartItemsService, MarketDataService (raw SQLAlchemy lookups) 50 of 54 handlers converted to sx, 4 Python fallbacks remain (ghost-sync/push-member, clear-cart-for-order, create-order). Net: -1,383 lines Python, +251 lines modified. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
86 lines
3.0 KiB
Python
86 lines
3.0 KiB
Python
"""Orders app action endpoints.
|
|
|
|
create-order remains as a Python fallback (complex multi-step SumUp checkout).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from quart import Blueprint, g, request
|
|
|
|
from shared.infrastructure.query_blueprint import create_action_blueprint
|
|
|
|
|
|
def register() -> Blueprint:
|
|
bp, _handlers = create_action_blueprint("orders")
|
|
|
|
async def _create_order():
|
|
from shared.browser.app.payments.sumup import create_checkout as sumup_create_checkout
|
|
from shared.infrastructure.urls import orders_url
|
|
from services.checkout import (
|
|
create_order,
|
|
resolve_page_config_from_post_id,
|
|
build_sumup_description,
|
|
build_sumup_reference,
|
|
build_webhook_url,
|
|
)
|
|
|
|
data = await request.get_json(force=True)
|
|
|
|
cart_items = data.get("cart_items", [])
|
|
calendar_entries = data.get("calendar_entries", [])
|
|
tickets = data.get("tickets", [])
|
|
user_id = data.get("user_id")
|
|
session_id = data.get("session_id")
|
|
product_total = data.get("product_total", 0)
|
|
calendar_total = data.get("calendar_total", 0)
|
|
ticket_total = data.get("ticket_total", 0)
|
|
page_post_id = data.get("page_post_id")
|
|
|
|
order = await create_order(
|
|
g.s, cart_items, calendar_entries,
|
|
user_id, session_id,
|
|
product_total, calendar_total,
|
|
ticket_total=ticket_total,
|
|
page_post_id=page_post_id,
|
|
)
|
|
|
|
page_config = None
|
|
if page_post_id:
|
|
page_config = await resolve_page_config_from_post_id(page_post_id)
|
|
|
|
if page_config:
|
|
order.page_config_id = page_config.id
|
|
|
|
order.sumup_reference = build_sumup_reference(order.id, page_config=page_config)
|
|
description = build_sumup_description(cart_items, order.id, ticket_count=len(tickets))
|
|
|
|
redirect_url = orders_url(f"/checkout/return/{order.id}/")
|
|
webhook_base_url = orders_url(f"/checkout/webhook/{order.id}/")
|
|
webhook_url = build_webhook_url(webhook_base_url)
|
|
|
|
checkout_data = await sumup_create_checkout(
|
|
order,
|
|
redirect_url=redirect_url,
|
|
webhook_url=webhook_url,
|
|
description=description,
|
|
page_config=page_config,
|
|
)
|
|
order.sumup_checkout_id = checkout_data.get("id")
|
|
order.sumup_status = checkout_data.get("status")
|
|
order.description = checkout_data.get("description")
|
|
hosted_cfg = checkout_data.get("hosted_checkout") or {}
|
|
hosted_url = hosted_cfg.get("hosted_checkout_url") or checkout_data.get("hosted_checkout_url")
|
|
order.sumup_hosted_url = hosted_url
|
|
await g.s.flush()
|
|
|
|
return {
|
|
"order_id": order.id,
|
|
"sumup_hosted_url": hosted_url,
|
|
"page_config_id": order.page_config_id,
|
|
"sumup_reference": order.sumup_reference,
|
|
"description": order.description,
|
|
}
|
|
|
|
_handlers["create-order"] = _create_order
|
|
|
|
return bp
|