Compare commits

..

No commits in common. "1872e57e26fe89ad351d40975a367c2d15cd53be" and "5bdd62d312695943494b63618a93e7d53f762c36" have entirely different histories.

2 changed files with 7 additions and 27 deletions

View file

@ -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 an explicitly provided Telegram-safe Leo checkout URL for a payment button."""
"""Return a Telegram-safe Leo checkout URL for an inline payment button."""
if not isinstance(payload, dict):
return None
checkout = payload.get("checkout")
@ -203,7 +203,8 @@ 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")
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")
if not isinstance(raw_url, str):
return None
url = raw_url.strip()

View file

@ -322,9 +322,11 @@ def test_extract_checkout_qr_photo_message_prefers_structured_telegram_card():
"captionHtml": (
"<b>Paid Leo research</b>\n"
"0.07 USDC on Solana mainnet.\n"
"Scan the QR or send exactly 0.07 USDC.\n"
"Pay with the button below or scan the QR.\n"
"Recipient: <code>8EgACpZ16XWEt7YjJPsh1ZheVRZUGmmwQ8nJdmA1o5w4</code>"
),
"buttonText": "Pay with x402",
"buttonUrl": checkout_url,
},
}
}
@ -336,7 +338,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": "",
"button_url": checkout_url,
}
assert checkout_url not in card["caption_html"]
assert "npx agentcash" not in card["caption_html"]
@ -366,29 +368,6 @@ 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(