diff --git a/.gitignore b/.gitignore index e10ddfd..97d23f8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .ruff_cache uv.lock .venv +.idea/ diff --git a/rest/python/client/flower_shop/simple_happy_path_client.py b/rest/python/client/flower_shop/simple_happy_path_client.py index c8a11b2..b927cd7 100644 --- a/rest/python/client/flower_shop/simple_happy_path_client.py +++ b/rest/python/client/flower_shop/simple_happy_path_client.py @@ -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() @@ -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) # ========================================================================== @@ -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) # ========================================================================== @@ -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