process_payment
Process simulated payment transactions for AMC movie bookings using booking ID, payment method, and amount to generate confirmation receipts.
Instructions
Handles simulated payment transaction.
Args: booking_id: Booking ID from book_seats payment_method: Payment method (e.g., "card", "cash") amount: Payment amount in USD
Returns: JSON string with payment confirmation and receipt
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| booking_id | Yes | ||
| payment_method | Yes | ||
| amount | Yes |
Implementation Reference
- src/amc_mcp/fastmcp_server.py:413-464 (handler)Core handler logic for the process_payment tool in FastMCP implementation. Validates booking, simulates payment, updates booking status to confirmed, and returns confirmation details.def _process_payment(booking_id: str, payment_method: str, amount: float) -> str: """Internal implementation of process_payment""" if not booking_id or booking_id not in bookings: return json.dumps({"error": "Invalid booking ID"}) booking = bookings[booking_id] if booking.status != "pending": return json.dumps({"error": f"Booking status is {booking.status}, expected pending"}) if abs(amount - booking.total_price) > 0.01: return json.dumps({"error": f"Amount mismatch. Expected ${booking.total_price:.2f}, got ${amount:.2f}"}) # Simulate payment processing (always succeeds in mock) payment_id = str(uuid.uuid4()) receipt_url = f"https://amc.com/receipts/{payment_id}" payment = Payment( payment_id=payment_id, booking_id=booking_id, amount=amount, payment_method=payment_method, status="success", receipt_url=receipt_url ) payments[payment_id] = payment # Update booking status booking.status = "confirmed" showtime = showtimes[booking.showtime_id] theater = theaters.get(showtime.theater_id) movie = movies.get(showtime.movie_id) result = { "payment_id": payment_id, "payment_status": "success", "booking_id": booking_id, "receipt_url": receipt_url, "confirmation": { "movie": movie.title if movie else "Unknown", "theater": theater.name if theater else "Unknown Theater", "date": showtime.date, "time": showtime.time, "seats": booking.seats, "total_paid": amount } } return json.dumps(result, indent=2)
- src/amc_mcp/fastmcp_server.py:466-479 (registration)FastMCP tool registration for process_payment using @mcp.tool() decorator, which defines the entry point and delegates to internal handler.@mcp.tool() def process_payment(booking_id: str, payment_method: str, amount: float) -> str: """ Handles simulated payment transaction. Args: booking_id: Booking ID from book_seats payment_method: Payment method (e.g., "card", "cash") amount: Payment amount in USD Returns: JSON string with payment confirmation and receipt """ return _process_payment(booking_id, payment_method, amount)
- src/amc_mcp/server.py:184-196 (registration)Registration of process_payment tool in list_tools() handler, including name, description, and explicit input schema.Tool( name="process_payment", description="Handles simulated payment transaction", inputSchema={ "type": "object", "properties": { "booking_id": {"type": "string", "description": "Booking ID"}, "payment_method": {"type": "string", "description": "Payment method (card, cash, etc.)"}, "amount": {"type": "number", "description": "Payment amount"} }, "required": ["booking_id", "payment_method", "amount"] } )
- src/amc_mcp/server.py:187-196 (schema)Input schema definition for process_payment tool, specifying parameters, types, descriptions, and required fields.inputSchema={ "type": "object", "properties": { "booking_id": {"type": "string", "description": "Booking ID"}, "payment_method": {"type": "string", "description": "Payment method (card, cash, etc.)"}, "amount": {"type": "number", "description": "Payment amount"} }, "required": ["booking_id", "payment_method", "amount"] } )
- src/amc_mcp/server.py:465-527 (handler)Core handler logic for process_payment in standard MCP server implementation. Extracts args, validates, processes payment, and returns CallToolResult.async def _process_payment(self, args: Dict[str, Any]) -> CallToolResult: """Process payment for a booking""" booking_id = args.get("booking_id") payment_method = args.get("payment_method") amount = args.get("amount") if not booking_id or booking_id not in self.bookings: return CallToolResult( content=[TextContent(type="text", text=json.dumps({"error": "Invalid booking ID"}))] ) booking = self.bookings[booking_id] if booking.status != "pending": return CallToolResult( content=[TextContent(type="text", text=json.dumps({"error": f"Booking status is {booking.status}, expected pending"}))] ) if abs(amount - booking.total_price) > 0.01: # Allow for small rounding differences return CallToolResult( content=[TextContent(type="text", text=json.dumps({"error": f"Amount mismatch. Expected ${booking.total_price:.2f}, got ${amount:.2f}"}))] ) # Simulate payment processing (always succeeds in mock) payment_id = str(uuid.uuid4()) receipt_url = f"https://amc.com/receipts/{payment_id}" payment = Payment( payment_id=payment_id, booking_id=booking_id, amount=amount, payment_method=payment_method, status="success", receipt_url=receipt_url ) self.payments[payment_id] = payment # Update booking status booking.status = "confirmed" showtime = self.showtimes[booking.showtime_id] theater = self.theaters.get(showtime.theater_id) movie = self.movies.get(showtime.movie_id) result = { "payment_id": payment_id, "payment_status": "success", "booking_id": booking_id, "receipt_url": receipt_url, "confirmation": { "movie": movie.title if movie else "Unknown", "theater": theater.name if theater else "Unknown Theater", "date": showtime.date, "time": showtime.time, "seats": booking.seats, "total_paid": amount } } return CallToolResult( content=[TextContent(type="text", text=json.dumps(result, indent=2))] )