# Agent Payment Gate Integration Guide This guide shows how to use Agent Payment Gate Starter in an agent product. ## 1. Start the server ```sh python3 payment_gate_server.py ``` The server reads newline-delimited JSON-RPC messages from stdin and writes JSON-RPC responses to stdout. ## 2. Build 402-style payment metadata Request: ```json {"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"build_payment_required","arguments":{"product_id":"my-agent-tool","amount":"0.001","delivery_url":"https://example.com/delivery"}}} ``` This returns BSC/BEP20 USDT payment metadata with: - amount - recipient - chain ID - transfer URI - delivery URL ## 3. Build a BSC USDT transfer URI Request: ```json {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"build_transfer_uri","arguments":{"amount":"0.001"}}} ``` For 0.001 USDT, the token amount is encoded as `1000000000000000` units because BSC USDT uses 18 decimals. ## 4. Verify a payment by balance delta Record the baseline USDT balance before asking for payment. Later call: ```json {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"verify_balance_delta","arguments":{"baseline_balance":"9.99","required_delta":"0.001"}}} ``` The response includes `paid: true` only when the current balance is at least baseline + required delta. ## 5. Safety notes - Use BSC/BEP20 only. - Do not send TRC20. - Public RPC endpoints can rate-limit; treat errors as retryable. - Balance-delta verification is simple and works for tiny payments, but production systems may also want transaction indexing.