Skip to content

Instantly share code, notes, and snippets.

@MrCheatEugene
Last active November 3, 2024 01:42
Show Gist options
  • Save MrCheatEugene/d15d07b6abc736f0c2eaad4aed0d92db to your computer and use it in GitHub Desktop.
Save MrCheatEugene/d15d07b6abc736f0c2eaad4aed0d92db to your computer and use it in GitHub Desktop.
Example how you can get QR.NSPK.RU URL with Self-employed PayAnyWay without any API's
import json
import aiohttp
async def pay(amount, redirect, account, currency="RUB", description=""):
"""
amount - Amount in RUB, can be string
account - Your PayAnyWay Business account number
redirect - Redirect to (in any case)
currency - Currency (default RUB)
description - Description, can be empty
Returns a dict with:
url: string, a qr.nspk.ru URL
transaction: int, Moneta.ru transaction ID
id: int, Moneta.ru operation ID
It might throw a random exception if you have issues with PayAnyWay or Moneta.ru fixed this :(
"""
async with aiohttp.ClientSession() as session:
data = await (
await session.post(
"https://moneta.ru/assistant.widget",
data={
"MNT_ID": account,
"MNT_CURRENCY_CODE": "RUB",
"MNT_AMOUNT": str(round(float(amount), 2)),
"MNT_SUCCESS_URL": redirect,
"MNT_FAIL_URL": redirect,
"MNT_RETURN_URL": redirect,
"MNT_INPROGRESS_URL": redirect,
"MNT_DESCRIPTION": description,
"submit": "Pay order",
},
)
).text()
lnk = data.split('const qrPayload = "')[-1].split('";')[0]
return {"url": str(json.loads(f'"{lnk}"')), "transaction": int(data.split('?MNT_TRANSACTION_ID=')[-1].split('&')[0]), "id": int(data.split(';MNT_OPERATION_ID=')[-1].split('"')[0])}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment