Skip to main content
Glama
hi5d
by hi5d

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

Implementation Reference

  • 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)
  • 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)
  • 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"]
        }
    )
  • 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"]
        }
    )
  • 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))]
        )

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