Stop exposing Leo checkout URL buttons by default
This commit is contained in:
parent
5bdd62d312
commit
6114750555
2 changed files with 27 additions and 7 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -322,11 +322,9 @@ 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"
|
||||
"Pay with the button below or scan the QR.\n"
|
||||
"Scan the QR or send exactly 0.07 USDC.\n"
|
||||
"Recipient: <code>8EgACpZ16XWEt7YjJPsh1ZheVRZUGmmwQ8nJdmA1o5w4</code>"
|
||||
),
|
||||
"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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue