Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/
37 changes: 33 additions & 4 deletions rest/python/client/flower_shop/simple_happy_path_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,33 @@ def log_interaction(
f.write("```\n\n")


def log_cart_snapshot(logger, step_label: str, checkout_data: dict) -> None:
"""Log 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."""
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -349,9 +376,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 +469,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 +575,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