Split cart into 4 microservices: relations, likes, orders, page-config→blog
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled

Phase 1 - Relations service (internal): owns ContainerRelation, exposes
get-children data + attach/detach-child actions. Retargeted events, blog,
market callers from cart to relations.

Phase 2 - Likes service (internal): unified Like model replaces ProductLike
and PostLike with generic target_type/target_slug/target_id. Exposes
is-liked, liked-slugs, liked-ids data + toggle action.

Phase 3 - PageConfig → blog: moved ownership to blog with direct DB queries,
removed proxy endpoints from cart.

Phase 4 - Orders service (public): owns Order/OrderItem + SumUp checkout
flow. Cart checkout now delegates to orders via create-order action.
Webhook/return routes and reconciliation moved to orders.

Phase 5 - Infrastructure: docker-compose, deploy.sh, Dockerfiles updated
for all 3 new services. Added orders_url helper and factory model imports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 09:03:33 +00:00
parent 76a9436ea1
commit fa431ee13e
125 changed files with 3459 additions and 860 deletions

View File

@@ -5,8 +5,7 @@ from __future__ import annotations
from quart import Blueprint, g, render_template, redirect, make_response, url_for
from shared.browser.app.utils.htmx import is_htmx_request
from shared.browser.app.payments.sumup import create_checkout as sumup_create_checkout
from shared.config import config
from shared.infrastructure.actions import call_action
from .services import (
total,
calendar_total,
@@ -14,12 +13,6 @@ from .services import (
)
from .services.page_cart import get_cart_for_page, get_calendar_entries_for_page, get_tickets_for_page
from .services.ticket_groups import group_tickets
from .services.checkout import (
create_order_from_cart,
build_sumup_description,
build_sumup_reference,
build_webhook_url,
)
from .services import current_cart_identity
@@ -56,7 +49,6 @@ def register(url_prefix: str) -> Blueprint:
@bp.post("/checkout/")
async def page_checkout():
post = g.page_post
page_config = getattr(g, "page_config", None)
cart = await get_cart_for_page(g.s, post.id)
cal_entries = await get_calendar_entries_for_page(g.s, post.id)
@@ -65,61 +57,51 @@ def register(url_prefix: str) -> Blueprint:
if not cart and not cal_entries and not page_tickets:
return redirect(url_for("page_cart.page_view"))
product_total = total(cart) or 0
product_total_val = total(cart) or 0
calendar_amount = calendar_total(cal_entries) or 0
ticket_amount = ticket_total(page_tickets) or 0
cart_total = product_total + calendar_amount + ticket_amount
cart_total = product_total_val + calendar_amount + ticket_amount
if cart_total <= 0:
return redirect(url_for("page_cart.page_view"))
# Create order scoped to this page
ident = current_cart_identity()
order = await create_order_from_cart(
g.s,
cart,
cal_entries,
ident.get("user_id"),
ident.get("session_id"),
product_total,
calendar_amount,
ticket_total=ticket_amount,
page_post_id=post.id,
)
# Set page_config on order
if page_config:
order.page_config_id = page_config.id
# Serialize cart items for the orders service
cart_items_data = []
for ci in cart:
cart_items_data.append({
"product_id": ci.product_id,
"product_title": ci.product_title,
"product_slug": ci.product_slug,
"product_image": ci.product_image,
"product_regular_price": float(ci.product_regular_price) if ci.product_regular_price else None,
"product_special_price": float(ci.product_special_price) if ci.product_special_price else None,
"product_price_currency": ci.product_price_currency,
"quantity": ci.quantity,
})
# Build SumUp checkout details — webhook/return use global routes
redirect_url = url_for("cart_global.checkout_return", order_id=order.id, _external=True)
order.sumup_reference = build_sumup_reference(order.id, page_config=page_config)
description = build_sumup_description(cart, order.id, ticket_count=len(page_tickets))
cal_data = [{"id": e.id, "calendar_container_id": getattr(e, "calendar_container_id", None)} for e in cal_entries]
ticket_data = [{"id": t.id, "calendar_container_id": getattr(t, "calendar_container_id", None)} for t in page_tickets]
webhook_base_url = url_for("cart_global.checkout_webhook", order_id=order.id, _external=True)
webhook_url = build_webhook_url(webhook_base_url)
result = await call_action("orders", "create-order", payload={
"cart_items": cart_items_data,
"calendar_entries": cal_data,
"tickets": ticket_data,
"user_id": ident.get("user_id"),
"session_id": ident.get("session_id"),
"product_total": float(product_total_val),
"calendar_total": float(calendar_amount),
"ticket_total": float(ticket_amount),
"page_post_id": post.id,
})
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()
hosted_url = result.get("sumup_hosted_url")
if not hosted_url:
html = await render_template(
"_types/cart/checkout_error.html",
order=order,
order=None,
error="No hosted checkout URL returned from SumUp.",
)
return await make_response(html, 500)