|
4 | 4 | from dotenv import load_dotenv |
5 | 5 | from fastapi import FastAPI, Request |
6 | 6 | from x402.fastapi.middleware import require_payment |
7 | | -from x402.types import EIP712Domain, TokenAmount, TokenAsset |
| 7 | +from x402.types import EIP712Domain, TokenAmount, TokenAsset, HTTPInputSchema |
8 | 8 | from cdp.auth import generate_jwt, JwtOptions |
9 | 9 |
|
10 | 10 | # Configure logging |
@@ -114,6 +114,17 @@ async def dynamic_price_middleware(request: Request, call_next): |
114 | 114 | facilitator_config=facilitator_config, |
115 | 115 | description=f"acp job budget ({budget})", |
116 | 116 | mime_type="application/json", |
| 117 | + # ⭐ Define input schema for x402scan registration |
| 118 | + input_schema=HTTPInputSchema( |
| 119 | + header_fields={ |
| 120 | + "X-Budget": { |
| 121 | + "type": "string", |
| 122 | + "required": False, |
| 123 | + "description": "Optional budget amount in USD (e.g., $0.01). If not provided, defaults to $0.001", |
| 124 | + "example": "$0.01" |
| 125 | + } |
| 126 | + } |
| 127 | + ), |
117 | 128 | ) |
118 | 129 |
|
119 | 130 | return await payment_middleware(request, call_next) |
@@ -144,15 +155,20 @@ async def health_check(): |
144 | 155 | return {"status": "ok"} |
145 | 156 |
|
146 | 157 |
|
147 | | -@app.get("/acp-budget") |
148 | | -async def acp_budget() -> Dict[str, Any]: |
| 158 | +@app.api_route("/acp-budget", methods=["GET", "POST"]) |
| 159 | +async def acp_budget(request: Request) -> Dict[str, Any]: |
| 160 | + """ |
| 161 | + Handle both GET and POST requests for ACP budget payment. |
| 162 | + x402scan may use either method depending on the request. |
| 163 | + """ |
149 | 164 | return { |
150 | 165 | "message": "pay acp job budget", |
151 | 166 | "token": "acp job payment token", |
152 | 167 | "protocol": "x402", |
153 | 168 | "utility": "none", |
154 | 169 | "vibes": "acp early adopter", |
155 | | - "advice": "not financial advice" |
| 170 | + "advice": "not financial advice", |
| 171 | + "method": request.method # Show which method was used |
156 | 172 | } |
157 | 173 |
|
158 | 174 |
|
|
0 commit comments