place_order
Verify USDC payment on Base and create an order for hats from The Investor Hat Store using transaction hash and shipping details.
Instructions
Place an order after sending USDC payment on Base. Verifies the on-chain transaction and creates the order.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| quote_id | Yes | Quote ID from get_quote | |
| tx_hash | Yes | Transaction hash of USDC payment on Base | |
| variant_id | Yes | Shopify variant ID | |
| shipping_name | Yes | ||
| shipping_address1 | Yes | ||
| shipping_city | Yes | ||
| shipping_state | Yes | ||
| shipping_zip | Yes | ||
| shipping_country | No |
Implementation Reference
- main.py:354-428 (handler)The `place_order` tool is implemented as a FastAPI route that handles order creation, including quote verification, on-chain payment verification, and order placement via Shopify API.
@app.post("/tools/place_order") async def place_order(request: Request): body = await request.json() quote_id = body.get("quote_id") tx_hash = body.get("tx_hash") variant_id = body.get("variant_id") quantity = body.get("quantity", 1) address = body.get("shipping_address", {}) email = body.get("email", "") # Validate quote quote = _quotes.get(quote_id) if not quote: raise HTTPException(400, "Quote not found. Call get_quote first.") if time.time() > quote["expires_at"]: raise HTTPException(400, "Quote expired. Call get_quote again.") expected_usdc = quote["total_usdc"] # Verify payment on Base verification = await verify_usdc_payment(tx_hash, expected_usdc, PAYMENT_WALLET) if not verification["verified"]: raise HTTPException(402, f"Payment not verified: {verification['reason']}") # Build Shopify order (already paid) name_parts = address.get("name", "Agent Buyer").split(" ", 1) order_payload = { "order": { "line_items": [{"variant_id": int(variant_id), "quantity": quantity}], "financial_status": "paid", "fulfillment_status": None, "send_receipt": bool(email), "send_fulfillment_receipt": True, "note": f"Paid via USDC on Base | tx: {tx_hash} | quote: {quote_id}", "shipping_address": { "first_name": name_parts[0], "last_name": name_parts[1] if len(name_parts) > 1 else "", "address1": address.get("address1", ""), "address2": address.get("address2", ""), "city": address.get("city", ""), "province": address.get("province", ""), "zip": address.get("zip", ""), "country_code": address.get("country_code", "US"), "phone": address.get("phone", ""), }, "transactions": [ { "kind": "sale", "status": "success", "amount": str(expected_usdc), "gateway": "USDC on Base", } ], } } if email: order_payload["order"]["email"] = email result = await shopify_post("orders.json", order_payload) order = result["order"] # Remove used quote _quotes.pop(quote_id, None) return { "success": True, "order_id": str(order["id"]), "order_number": order.get("order_number"), "status": order.get("fulfillment_status") or "unfulfilled", "payment_verified": True, "tx_hash": tx_hash, "amount_paid_usdc": verification.get("amount_usdc", expected_usdc), "shipping_to": address.get("name"), "message": "Order created. Printful will produce and ship your item. Use get_order_status to track.", } - main.py:508-525 (schema)The `place_order` tool input schema is defined within the `MCP_TOOLS` list for protocol communication.
"name": "place_order", "description": "Place an order after sending USDC payment on Base. Verifies the on-chain transaction and creates the order.", "inputSchema": { "type": "object", "properties": { "quote_id": {"type": "string", "description": "Quote ID from get_quote"}, "tx_hash": {"type": "string", "description": "Transaction hash of USDC payment on Base"}, "variant_id": {"type": "integer", "description": "Shopify variant ID"}, "shipping_name": {"type": "string"}, "shipping_address1": {"type": "string"}, "shipping_city": {"type": "string"}, "shipping_state": {"type": "string"}, "shipping_zip": {"type": "string"}, "shipping_country": {"type": "string"} }, "required": ["quote_id", "tx_hash", "variant_id", "shipping_name", "shipping_address1", "shipping_city", "shipping_state", "shipping_zip"] } },