Skip to content

Commit 1278c41

Browse files
authored
Merge pull request #5 from Virtual-Protocol/feat/acp-837
feat: add logs to middleware
2 parents 4086a55 + 23e419f commit 1278c41

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

examples/python/clients/httpx/extensible.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def main():
3131

3232
# Make request with X-Budget header
3333
try:
34-
budget = "$0.01" # ⭐ Your budget
34+
budget = "$0.69" # ⭐ Your budget
3535
print(f"Making request to {endpoint_path} with budget: {budget}")
3636

3737
response = await client.post(

examples/python/servers/fastapi/main.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,31 @@ async def dynamic_price_middleware(request: Request, call_next):
159159

160160
@app.get("/")
161161
async def health_check():
162-
return {"status": "ok"}
162+
"""Health check endpoint that also serves as site metadata"""
163+
from fastapi.responses import HTMLResponse
164+
165+
# Return HTML with meta tags for better x402scan integration
166+
html_content = """
167+
<!DOCTYPE html>
168+
<html>
169+
<head>
170+
<meta charset="UTF-8">
171+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
172+
<title>Virtuals Protocol - ACP Job Payment</title>
173+
<meta name="description" content="Virtuals Protocol ACP Job Budget Payment Service">
174+
<meta property="og:title" content="Virtuals Protocol ACP">
175+
<meta property="og:description" content="Pay for ACP jobs with x402 protocol">
176+
<meta property="og:site_name" content="Virtuals Protocol">
177+
<link rel="icon" href="/favicon.ico">
178+
</head>
179+
<body>
180+
<h1>Virtuals Protocol - ACP Job Payment</h1>
181+
<p>This is an x402 payment service for Virtuals Protocol ACP jobs.</p>
182+
<p>Status: <span style="color: green;">✓ Operational</span></p>
183+
</body>
184+
</html>
185+
"""
186+
return HTMLResponse(content=html_content)
163187

164188

165189
@app.get("/favicon.ico")

python/x402/src/x402/fastapi/middleware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,16 @@ def x402_response(error: str):
201201
if response.status_code < 200 or response.status_code >= 300:
202202
return response
203203

204+
logger.info('payment: %s', payment.model_dump_json(by_alias=True))
205+
logger.info('selected_payment_requirements: %s', selected_payment_requirements.model_dump_json(by_alias=True, exclude_none=True))
206+
204207
# Settle the payment
205208
try:
209+
206210
settle_response = await facilitator.settle(
207211
payment, selected_payment_requirements
208212
)
213+
209214
if settle_response.success:
210215
response.headers["X-PAYMENT-RESPONSE"] = base64.b64encode(
211216
settle_response.model_dump_json(by_alias=True).encode("utf-8")

0 commit comments

Comments
 (0)