payments/license.py · дословно
def issue_license(plugin, categories, note):
"""POST на лиценз-сервер -> строка ключа. Бросает при ошибке/отсутствии конфига."""
url = getattr(settings, "LICENSE_ISSUE_URL", "") or ""
token = getattr(settings, "ISSUE_TOKEN", "") or ""
if not url or not token:
raise RuntimeError("license not configured (нет LICENSE_ISSUE_URL / ISSUE_TOKEN в .env)")
body = json.dumps({
"plugin": plugin,
"categories": categories or [],
"note": note,
}).encode("utf-8")
headers = {"X-Issue-Token": token, "Content-Type": "application/json"}
# …
req = urllib.request.Request(url, data=body, method="POST", headers=headers)
with urllib.request.urlopen(req, timeout=20) as resp:
data = json.loads(resp.read().decode("utf-8"))
key = data.get("key")
if not key:
raise RuntimeError("лиценз-сервер не вернул key")
return key