feat: Platega credentials section in the Payments wizard, for parity with YooKassa

The setup wizard added last iteration only covered YooKassa, leaving
Platega (the second provider this panel has always supported) still
.env-only despite everything else in the payments flow treating both
providers symmetrically. Same GET/POST shape as the YooKassa settings
routes. Platega has no documented lightweight credentials-check
endpoint like YooKassa's /v3/me, so this one honestly says so in the
UI instead of saving through a fabricated validation call — it saves
directly and a bad key will surface on the first real payment attempt
instead of at save time.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Savsis? 2026-09-13 19:50:54 +05:00
parent 6311532c45
commit dcfcf8f650
2 changed files with 68 additions and 4 deletions

30
api.py
View file

@ -426,6 +426,36 @@ def admin_set_yookassa_settings(request: Request, body: dict = Body(...)):
return {"ok": True, "restarted_bot": restarted}
@app.get("/admin/api/payments/platega-settings")
def admin_get_platega_settings(request: Request):
require_admin(request)
return {
"enabled": payments.PLATEGA_ENABLED,
"merchant_id": legal.read_env_var("PLATEGA_MERCHANT_ID", ""),
"has_secret": bool(legal.read_env_var("PLATEGA_SECRET", "")),
}
@app.post("/admin/api/payments/platega-settings")
def admin_set_platega_settings(request: Request, body: dict = Body(...)):
require_admin(request)
merchant_id = (body.get("merchant_id") or "").strip()
secret = (body.get("secret") or "").strip()
if not merchant_id or not secret:
raise HTTPException(400, "merchant_id и secret обязательны")
_update_env_var("PLATEGA_MERCHANT_ID", merchant_id)
_update_env_var("PLATEGA_SECRET", secret)
_update_env_var("PLATEGA_ENABLED", "true")
_update_env_var("PAYMENTS_ENABLED", "true")
restarted = False
try:
subprocess.run(["systemctl", "restart", "mbs-bot"], check=True, timeout=15)
restarted = True
except Exception:
restarted = False
return {"ok": True, "restarted_bot": restarted}
@app.post("/payments/webhook/yookassa")
async def yookassa_webhook(request: Request):
body = await request.json()