diff --git a/telegram/http_chat_proxy.py b/telegram/http_chat_proxy.py
index 7ff9025..4f55f4d 100644
--- a/telegram/http_chat_proxy.py
+++ b/telegram/http_chat_proxy.py
@@ -194,7 +194,7 @@ def extract_checkout_qr_url(payload: dict[str, Any] | None) -> str | None:
def extract_checkout_url(payload: dict[str, Any] | None) -> str | None:
- """Return a Telegram-safe Leo checkout URL for an inline payment button."""
+ """Return an explicitly provided Telegram-safe Leo checkout URL for a payment button."""
if not isinstance(payload, dict):
return None
checkout = payload.get("checkout")
@@ -203,8 +203,7 @@ def extract_checkout_url(payload: dict[str, Any] | None) -> str | None:
telegram = checkout.get("telegram")
raw_url = None
if isinstance(telegram, dict):
- raw_url = telegram.get("buttonUrl") or telegram.get("button_url") or telegram.get("checkoutUrl")
- raw_url = raw_url or checkout.get("checkoutUrl") or checkout.get("checkout_url")
+ raw_url = telegram.get("buttonUrl") or telegram.get("button_url")
if not isinstance(raw_url, str):
return None
url = raw_url.strip()
diff --git a/tests/test_telegram_leo_x402_bridge.py b/tests/test_telegram_leo_x402_bridge.py
index 8f6b489..d2e6f28 100644
--- a/tests/test_telegram_leo_x402_bridge.py
+++ b/tests/test_telegram_leo_x402_bridge.py
@@ -322,11 +322,9 @@ def test_extract_checkout_qr_photo_message_prefers_structured_telegram_card():
"captionHtml": (
"Paid Leo research\n"
"0.07 USDC on Solana mainnet.\n"
- "Pay with the button below or scan the QR.\n"
+ "Scan the QR or send exactly 0.07 USDC.\n"
"Recipient: 8EgACpZ16XWEt7YjJPsh1ZheVRZUGmmwQ8nJdmA1o5w4"
),
- "buttonText": "Pay with x402",
- "buttonUrl": checkout_url,
},
}
}
@@ -338,7 +336,7 @@ def test_extract_checkout_qr_photo_message_prefers_structured_telegram_card():
"caption_html": payload["checkout"]["telegram"]["captionHtml"],
"parse_mode": "HTML",
"button_text": "Pay with x402",
- "button_url": checkout_url,
+ "button_url": "",
}
assert checkout_url not in card["caption_html"]
assert "npx agentcash" not in card["caption_html"]
@@ -368,6 +366,29 @@ def test_extract_checkout_url_rejects_non_leo_checkout_url():
assert extract_checkout_url({"checkout": {"checkoutUrl": "https://example.com/pay"}}) is None
+def test_extract_checkout_url_does_not_fallback_to_checkout_url():
+ assert (
+ extract_checkout_url(
+ {
+ "checkout": {
+ "checkoutUrl": "https://leo.livingip.xyz/agents/leo/research/checkout?q=test"
+ }
+ }
+ )
+ is None
+ )
+
+
+def test_extract_checkout_url_accepts_explicit_telegram_button_url():
+ checkout_url = "https://leo.livingip.xyz/agents/leo/research/checkout?q=test"
+ assert (
+ extract_checkout_url(
+ {"checkout": {"telegram": {"buttonUrl": checkout_url}, "checkoutUrl": checkout_url}}
+ )
+ == checkout_url
+ )
+
+
def test_extract_checkout_qr_photo_message_rejects_non_leo_qr_url():
assert (
extract_checkout_qr_photo_message(