Skip to main content
Glama

process_payment

Process payment transactions for movie bookings by submitting booking ID, payment method, and amount to complete ticket purchases.

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
NameRequiredDescriptionDefault
booking_idYes
payment_methodYes
amountYes

Implementation Reference

  • Handler for process_payment tool in the standard MCP server. Validates booking ID, status, and amount; simulates successful payment; updates booking to confirmed; returns detailed confirmation JSON.
    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))] )
  • Input schema definition for the process_payment tool, specifying required parameters: booking_id (string), payment_method (string), amount (number).
    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"] } )
  • FastMCP tool handler for process_payment, decorated with @mcp.tool(), delegates to internal _process_payment function.
    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)
  • Core logic for processing payment in FastMCP server, identical to standard server handler: validation, simulation, update, JSON return.
    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)
  • Dispatch logic in call_tool handler that routes process_payment requests to the _process_payment method.
    elif request.name == "process_payment": return await self._process_payment(request.arguments)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hi5d/amc-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server