Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.ruff_cache
uv.lock
.venv
.idea/
36 changes: 31 additions & 5 deletions rest/python/client/flower_shop/simple_happy_path_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from ucp_sdk.models.schemas.shopping.types.token_credential_resp import (
TokenCredentialResponse,
)

from typing import Dict

def get_headers() -> dict[str, str]:
"""Generate necessary headers for UCP requests."""
Expand Down Expand Up @@ -148,6 +148,30 @@ def log_interaction(
f.write(f"export {var_name}=$(echo $RESPONSE | jq -r '{jq_expr}')\n")
f.write("```\n\n")

def log_cart_snapshot(logger, step_label: str, checkout_data: Dict) -> None:
"""
Logs a compact snapshot of the cart contents.
Safe for samples: no PII, no payment data.
"""
items = []
for li in checkout_data.get("line_items", []) or []:
item = li.get("item", {}) or {}
title = item.get("title") or item.get("name") or item.get("id") or "unknown-item"
qty = li.get("quantity")
items.append(f"{title} x{qty}")

total = None
totals = checkout_data.get("totals") or []
if totals:
total = totals[-1].get("amount")

logger.info(
"%s | total_cents=%s items=%s",
step_label,
total,
items,
)


def main() -> None:
"""Run the happy path client."""
Expand Down Expand Up @@ -349,9 +373,7 @@ def main() -> None:

logger.info("Successfully created checkout session: %s", checkout_id)

logger.info(
"Current Total: %s cents", checkout_data["totals"][-1]["amount"]
)
log_cart_snapshot(logger, "STEP 1 snapshot (created)", checkout_data)

# ==========================================================================

Expand Down Expand Up @@ -444,7 +466,7 @@ def main() -> None:

logger.info("New Total: %s cents", checkout_data["totals"][-1]["amount"])

logger.info("Item Count: %d", len(checkout_data["line_items"]))
log_cart_snapshot(logger, "STEP 2 snapshot (items added)", checkout_data)

# ==========================================================================

Expand Down Expand Up @@ -550,6 +572,10 @@ def main() -> None:
else:
logger.warning("No discounts applied!")

log_cart_snapshot(
logger, "STEP 3 snapshot (discount applied)", checkout_data
)

# ==========================================================================

# STEP 4: Select Fulfillment Option
Expand Down