tochka-api


Nametochka-api JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/WhiteApfel/tochka_api
SummarySimple Tochka Bank Open API client
upload_time2023-06-09 18:37:12
maintainer
docs_urlNone
authorWhiteApfel
requires_python
licenseMozilla Public License 2.0
keywords tochka openapi api bank
VCS
bugtrack_url
requirements pydantic httpx ujson appdirs
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # πŸŽ‰ Tochka API

**Удобная ΠΎΠ±Ρ‘Ρ€Ρ‚ΠΊΠ° Π½Π°Π΄ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Ρ‹ΠΌ API Π‘Π°Π½ΠΊΠ° Π’ΠΎΡ‡ΠΊΠ°**

## πŸ“₯ Установка

### πŸ“¦ Из pip:

```shell
python -m pip install -u tochka_api
```

### πŸ— Из рСпозитория:

```shell
git clone https://github.com/WhiteApfel/tochka_api.git
cd tochka_api
python setup.py install
```

### 🚧 ΠŸΡ€ΠΎΠ³Ρ€Π΅ΡΡ Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠΈ

* [x] Авторизация
* [x] Балансы
* [x] Π‘Ρ‡Π΅Ρ‚Π°
* [ ] Webhooks
* [ ] Выписки
* [ ] ΠšΠ°Ρ€Ρ‚Ρ‹
* [ ] ΠšΠ»ΠΈΠ΅Π½Ρ‚Ρ‹
* [ ] ΠŸΠ»Π°Ρ‚Π΅ΠΆΠΈ
* [ ] Π Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΡ
* [ ] Π‘ΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ счСта
* [x] Π‘Π‘ΠŸ
  * [x] QR
  * [x] ВБП (Merchant)
  * [x] Компании (Legal)
  * [x] Π’ΠΎΠ·Π²Ρ€Π°Ρ‚Ρ‹

### πŸ§‘β€πŸ« Как ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ

**πŸ’° УточнСния ΠΏΠΎ Ρ‚ΠΈΠΏΡƒ Π΄Π°Π½Π½Ρ‹Ρ… для суммы**

* ``Decimal`` and ``str`` - amount in rubles
* ``int`` - amount in kopecks

**Различия user_code ΠΈ customer_code**

* ``user_code`` это ΠΊΠΎΠ΄ ΠΊΠ»ΠΈΠ΅Π½Ρ‚Π°, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΈΠΌΠ΅Π΅Ρ‚ доступ ΠΊ ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΈ
* ``customer_code`` это ΠΊΠΎΠ΄ ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΈ(ИП), Π½Π° ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚Ρ‹ счСта

```python
import asyncio

from decimal import Decimal

from tochka_api import TochkaAPI, context_user_code
from tochka_api.models import PermissionsEnum

client_id = "<<client_id>>"
client_secret = "<<client_secret>>"
redirect_uri = "https://tochka-api.pfel.cc/"

tochka = TochkaAPI(client_id, client_secret, redirect_uri=redirect_uri)


async def add_user():
  consents_token, consents_expires_in = await tochka.get_consents_token()
  consents_request = await tochka.create_consents(
      consents_token, PermissionsEnum.all()
  )
  auth_url = tochka.generate_auth_url(consent_id=consents_request.consent_id)
  print("Auth:", auth_url)
  
  code = input("Code >>> ")
  token_id = input("Token_id >>> ")
  tokens = await tochka.get_access_token(
      code=code, token_id=token_id
  )
  
  print(f"User {tokens.user_code=} are authorized.")
  context_user_code.set(tokens.user_code)
  
  asyncio.create_task(get_accounts())
  merchant_id = await register_merchant(user_code=tokens.user_code)
  await register_qr(merchant_id=merchant_id)

async def get_accounts():
  # user_code Π±ΡƒΠ΄Π΅Ρ‚ унаслСдован ΠΈΠ· context_user_code
  # Π­Ρ‚ΠΎ thread-safe ΠΈ loop-safe
  for _ in range(25):
    await tochka.get_accounts()
    await asyncio.sleep(2)

async def register_merchant(user_code) -> str:
  # Π‘ΡƒΠ΄Π΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ user_code
  # Π”Π°ΠΆΠ΅ Ссли Π² context_user_code Π±Ρ‹Π»ΠΎ Π·Π°Π΄Π°Π½ΠΎ Π΄Ρ€ΡƒΠ³ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅
  accounts = await tochka.get_accounts(user_code=user_code)
  
  customer_info = await tochka.sbp_get_customer_info(
      customer_code=accounts[0].customer_code
  )
  legal_entity = await tochka.sbp_get_legal_entity(customer_info.legal_id)

  merchant = await tochka.sbp_register_merchant(
      legal_id=legal_entity.legal_id,
      name="TochkaExample",
      mcc="7277",
      address=" 1-ΠΉ Π’Π΅ΡˆΠ½ΡΠΊΠΎΠ²ΡΠΊΠΈΠΉ ΠΏΡ€ΠΎΠ΅Π·Π΄, Π΄. 1, стр. 8, этаТ 1, ΠΏΠΎΠΌΠ΅Ρ‰. 43",
      city="Москва",
      region_code="45",
      zip_code="109456",
      phone_number="+78002000024",
  )
  
  print(f"New merchant {merchant.merchant_id=}")
  print(
    *(await tochka.sbp_get_merchants(legal_id=legal_entity.legal_id)).merchants,
    sep="\n",
  )
  
  return merchant.merchant_id

async def register_qr(merchant_id):
  # user_code Π±ΡƒΠ΄Π΅Ρ‚ унаслСдован ΠΈΠ· context_user_code
  # Π­Ρ‚ΠΎ thread-safe ΠΈ loop-safe
  accounts = await tochka.get_accounts()

  customer_info = await tochka.sbp_get_customer_info(
      customer_code=accounts[0].customer_code
  )
  legal_entity = await tochka.sbp_get_legal_entity(customer_info.legal_id)
  sbp_accounts = await tochka.sbp_get_accounts(legal_entity.legal_id)
    
  qr = await tochka.sbp_register_qr(
    merchant_id=merchant_id,
    account=sbp_accounts[0].account,
    is_static=True,
    purpose="ΠŸΠ΅Ρ€Π΅Ρ‡ΠΈΡΠ»Π΅Π½ΠΈΠ΅ ΠΏΠΎ Π΄ΠΎΠ³ΠΎΠ²ΠΎΡ€Ρƒ ΠΌΠΈΠ½Π΅Ρ‚Π°",
    media_type="image/svg+xml",
  )
  print("Π‘Ρ‚Π°Ρ‚ΠΈΡ‡Π½Ρ‹ΠΉ Π±Π΅Π· суммы:\n",qr.image.content)
  
  qr = await tochka.sbp_register_qr(
    merchant_id=merchant_id,
    account=sbp_accounts[0].account,
    is_static=True,
    amount=Decimal("100.00"),  # ΠΈΠ»ΠΈ Decimal(100), ΠΈΠ»ΠΈ 10000
    purpose="ΠžΠΏΠ»Π°Ρ‚Π° Π°Ρ€Π΅Π½Π΄Ρ‹ бордСля",
    media_type="image/svg+xml",
  )
  print("Π‘Ρ‚Π°Ρ‚ΠΈΡ‡Π½Ρ‹ΠΉ с суммой:\n",qr.image.content)
  
  qr = await tochka.sbp_register_qr(
    merchant_id=merchant_id,
    account=sbp_accounts[0].account,
    is_static=False,
    amount=10000,  # ΠΈΠ»ΠΈ Decimal(100)
    ttl=60,  # 0 - максимально Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΠ΅ ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅, ΠΈΠ½Π°Ρ‡Π΅ Π² ΠΌΠΈΠ½ΡƒΡ‚Π°Ρ…
    purpose="ΠžΠΏΠ»Π°Ρ‚Π° поставки ΠΏΡ€Π΅Π·Π΅Ρ€Π²Π°Ρ‚ΠΈΠ²ΠΎΠ²",
    media_type="image/svg+xml",
  )
  print("ДинамичСский с суммой:\n",qr.image.content)

async def refund():
  accounts = await tochka.get_accounts()

  customer_info = await tochka.sbp_get_customer_info(
      customer_code=accounts[0].customer_code
  )
  sbp_accounts = await tochka.sbp_get_accounts(customer_info.legal_id)
  
  payments = await tochka.sbp_get_payments(
    customer_info.customer_code, from_date=1,
  )
  print(payments)
  
  last_payment = payments.payments[0]
  refund_response = await tochka.sbp_start_refund(
      account=sbp_accounts[0].account,
      amount=Decimal("1.25"),  # ΠΈΠ»ΠΈ 125
      qrc_id=last_payment.qrc_id,
      trx_id=last_payment.trx_id,
  )
  print("Refund: ", refund_response)

async def main():
  # Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Π΄Π²Π° ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ. 
  # Π­Ρ‚ΠΎ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Π±ΡƒΡ…Π³Π°Π»Ρ‚Π΅Ρ€ ΠΈ Π²Π»Π°Π΄Π΅Π»Π΅Ρ† ΠΎΠ΄Π½ΠΎΠΉ ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΈ
  # ΠΈΠ»ΠΈ ΡΠΎΠ²Π΅Ρ€ΡˆΠ΅Π½Π½ΠΎ Ρ€Π°Π·Π½Ρ‹Π΅ люди ΠΈΠ· Ρ€Π°Π·Π½Ρ‹Ρ… ΠΊΠΎΠΌΠΏΠ°Π½ΠΈΠΉ.
  # ΠŸΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ с нСсколькими ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡΠΌΠΈ
  # Π»ΠΈΠ±ΠΎ Π² ΠΎΠ΄Π½ΠΎΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅, Ρ‚ΠΎΠ³Π΄Π° Π½Π°Π΄ΠΎ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ
  # tochka = TochkaAPI(client_id, client_secret, redirect_uri=redirect_uri, one_customer_mode=True)
  # ΠΈ Ρ‚ΠΎΠ³Π΄Π° послС добавлСния ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ, систСма Π΅Π³ΠΎ Π·Π°ΠΏΠΎΠΌΠ½ΠΈΡ‚.
  # Π£ΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ context_user_code Π½Π΅ придётся
  print("Π’Π²Π΅Π΄ΠΈΡ‚Π΅ Ρ‡Ρ‚ΠΎ-Π»ΠΈΠ±ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ")
  print("Для пропуска Π½Π°ΠΆΠΌΠΈΡ‚Π΅ Enter")
  if input(">>> "):
    await add_user()
    await add_user()
  else:
    # ΠΌΠΎΠΆΠ½ΠΎ Π½Π΅ ΡƒΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒ, Ссли one_customer_mode=True
    context_user_code.set("212332030")
      
    await refund()
    

  balances = await tochka.get_balances()
  print(balances[0].amount)


asyncio.run(main())
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/WhiteApfel/tochka_api",
    "name": "tochka-api",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "tochka openapi api bank",
    "author": "WhiteApfel",
    "author_email": "white@pfel.ru",
    "download_url": "https://files.pythonhosted.org/packages/93/7b/824abc0b87453ca5703241e3a34b8f58edf29ef8d5ab6f7415def4606c51/tochka_api-0.1.0.tar.gz",
    "platform": null,
    "description": "# \ud83c\udf89 Tochka API\n\n**\u0423\u0434\u043e\u0431\u043d\u0430\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c API \u0411\u0430\u043d\u043a\u0430 \u0422\u043e\u0447\u043a\u0430**\n\n## \ud83d\udce5 \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\n\n### \ud83d\udce6 \u0418\u0437 pip:\n\n```shell\npython -m pip install -u tochka_api\n```\n\n### \ud83c\udfd7 \u0418\u0437 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f:\n\n```shell\ngit clone https://github.com/WhiteApfel/tochka_api.git\ncd tochka_api\npython setup.py install\n```\n\n### \ud83d\udea7 \u041f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438\n\n* [x] \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f\n* [x] \u0411\u0430\u043b\u0430\u043d\u0441\u044b\n* [x] \u0421\u0447\u0435\u0442\u0430\n* [ ] Webhooks\n* [ ] \u0412\u044b\u043f\u0438\u0441\u043a\u0438\n* [ ] \u041a\u0430\u0440\u0442\u044b\n* [ ] \u041a\u043b\u0438\u0435\u043d\u0442\u044b\n* [ ] \u041f\u043b\u0430\u0442\u0435\u0436\u0438\n* [ ] \u0420\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f\n* [ ] \u0421\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0447\u0435\u0442\u0430\n* [x] \u0421\u0411\u041f\n  * [x] QR\n  * [x] \u0422\u0421\u041f (Merchant)\n  * [x] \u041a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 (Legal)\n  * [x] \u0412\u043e\u0437\u0432\u0440\u0430\u0442\u044b\n\n### \ud83e\uddd1\u200d\ud83c\udfeb \u041a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\n\n**\ud83d\udcb0 \u0423\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u043f\u043e \u0442\u0438\u043f\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0441\u0443\u043c\u043c\u044b**\n\n* ``Decimal`` and ``str`` - amount in rubles\n* ``int`` - amount in kopecks\n\n**\u0420\u0430\u0437\u043b\u0438\u0447\u0438\u044f user_code \u0438 customer_code**\n\n* ``user_code`` \u044d\u0442\u043e \u043a\u043e\u0434 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438\n* ``customer_code`` \u044d\u0442\u043e \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438(\u0418\u041f), \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0442\u043a\u0440\u044b\u0442\u044b \u0441\u0447\u0435\u0442\u0430\n\n```python\nimport asyncio\n\nfrom decimal import Decimal\n\nfrom tochka_api import TochkaAPI, context_user_code\nfrom tochka_api.models import PermissionsEnum\n\nclient_id = \"<<client_id>>\"\nclient_secret = \"<<client_secret>>\"\nredirect_uri = \"https://tochka-api.pfel.cc/\"\n\ntochka = TochkaAPI(client_id, client_secret, redirect_uri=redirect_uri)\n\n\nasync def add_user():\n  consents_token, consents_expires_in = await tochka.get_consents_token()\n  consents_request = await tochka.create_consents(\n      consents_token, PermissionsEnum.all()\n  )\n  auth_url = tochka.generate_auth_url(consent_id=consents_request.consent_id)\n  print(\"Auth:\", auth_url)\n  \n  code = input(\"Code >>> \")\n  token_id = input(\"Token_id >>> \")\n  tokens = await tochka.get_access_token(\n      code=code, token_id=token_id\n  )\n  \n  print(f\"User {tokens.user_code=} are authorized.\")\n  context_user_code.set(tokens.user_code)\n  \n  asyncio.create_task(get_accounts())\n  merchant_id = await register_merchant(user_code=tokens.user_code)\n  await register_qr(merchant_id=merchant_id)\n\nasync def get_accounts():\n  # user_code \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d \u0438\u0437 context_user_code\n  # \u042d\u0442\u043e thread-safe \u0438 loop-safe\n  for _ in range(25):\n    await tochka.get_accounts()\n    await asyncio.sleep(2)\n\nasync def register_merchant(user_code) -> str:\n  # \u0411\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 user_code\n  # \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432 context_user_code \u0431\u044b\u043b\u043e \u0437\u0430\u0434\u0430\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\n  accounts = await tochka.get_accounts(user_code=user_code)\n  \n  customer_info = await tochka.sbp_get_customer_info(\n      customer_code=accounts[0].customer_code\n  )\n  legal_entity = await tochka.sbp_get_legal_entity(customer_info.legal_id)\n\n  merchant = await tochka.sbp_register_merchant(\n      legal_id=legal_entity.legal_id,\n      name=\"TochkaExample\",\n      mcc=\"7277\",\n      address=\" 1-\u0439 \u0412\u0435\u0448\u043d\u044f\u043a\u043e\u0432\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0435\u0437\u0434, \u0434. 1, \u0441\u0442\u0440. 8, \u044d\u0442\u0430\u0436 1, \u043f\u043e\u043c\u0435\u0449. 43\",\n      city=\"\u041c\u043e\u0441\u043a\u0432\u0430\",\n      region_code=\"45\",\n      zip_code=\"109456\",\n      phone_number=\"+78002000024\",\n  )\n  \n  print(f\"New merchant {merchant.merchant_id=}\")\n  print(\n    *(await tochka.sbp_get_merchants(legal_id=legal_entity.legal_id)).merchants,\n    sep=\"\\n\",\n  )\n  \n  return merchant.merchant_id\n\nasync def register_qr(merchant_id):\n  # user_code \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d \u0438\u0437 context_user_code\n  # \u042d\u0442\u043e thread-safe \u0438 loop-safe\n  accounts = await tochka.get_accounts()\n\n  customer_info = await tochka.sbp_get_customer_info(\n      customer_code=accounts[0].customer_code\n  )\n  legal_entity = await tochka.sbp_get_legal_entity(customer_info.legal_id)\n  sbp_accounts = await tochka.sbp_get_accounts(legal_entity.legal_id)\n    \n  qr = await tochka.sbp_register_qr(\n    merchant_id=merchant_id,\n    account=sbp_accounts[0].account,\n    is_static=True,\n    purpose=\"\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u043f\u043e \u0434\u043e\u0433\u043e\u0432\u043e\u0440\u0443 \u043c\u0438\u043d\u0435\u0442\u0430\",\n    media_type=\"image/svg+xml\",\n  )\n  print(\"\u0421\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0431\u0435\u0437 \u0441\u0443\u043c\u043c\u044b:\\n\",qr.image.content)\n  \n  qr = await tochka.sbp_register_qr(\n    merchant_id=merchant_id,\n    account=sbp_accounts[0].account,\n    is_static=True,\n    amount=Decimal(\"100.00\"),  # \u0438\u043b\u0438 Decimal(100), \u0438\u043b\u0438 10000\n    purpose=\"\u041e\u043f\u043b\u0430\u0442\u0430 \u0430\u0440\u0435\u043d\u0434\u044b \u0431\u043e\u0440\u0434\u0435\u043b\u044f\",\n    media_type=\"image/svg+xml\",\n  )\n  print(\"\u0421\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0441 \u0441\u0443\u043c\u043c\u043e\u0439:\\n\",qr.image.content)\n  \n  qr = await tochka.sbp_register_qr(\n    merchant_id=merchant_id,\n    account=sbp_accounts[0].account,\n    is_static=False,\n    amount=10000,  # \u0438\u043b\u0438 Decimal(100)\n    ttl=60,  # 0 - \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0438\u043d\u0430\u0447\u0435 \u0432 \u043c\u0438\u043d\u0443\u0442\u0430\u0445\n    purpose=\"\u041e\u043f\u043b\u0430\u0442\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u043f\u0440\u0435\u0437\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u043e\u0432\",\n    media_type=\"image/svg+xml\",\n  )\n  print(\"\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441 \u0441\u0443\u043c\u043c\u043e\u0439:\\n\",qr.image.content)\n\nasync def refund():\n  accounts = await tochka.get_accounts()\n\n  customer_info = await tochka.sbp_get_customer_info(\n      customer_code=accounts[0].customer_code\n  )\n  sbp_accounts = await tochka.sbp_get_accounts(customer_info.legal_id)\n  \n  payments = await tochka.sbp_get_payments(\n    customer_info.customer_code, from_date=1,\n  )\n  print(payments)\n  \n  last_payment = payments.payments[0]\n  refund_response = await tochka.sbp_start_refund(\n      account=sbp_accounts[0].account,\n      amount=Decimal(\"1.25\"),  # \u0438\u043b\u0438 125\n      qrc_id=last_payment.qrc_id,\n      trx_id=last_payment.trx_id,\n  )\n  print(\"Refund: \", refund_response)\n\nasync def main():\n  # \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \n  # \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u0443\u0445\u0433\u0430\u043b\u0442\u0435\u0440 \u0438 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u043e\u0434\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438\n  # \u0438\u043b\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0440\u0430\u0437\u043d\u044b\u0435 \u043b\u044e\u0434\u0438 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439.\n  # \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438\n  # \u043b\u0438\u0431\u043e \u0432 \u043e\u0434\u043d\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c\n  # tochka = TochkaAPI(client_id, client_secret, redirect_uri=redirect_uri, one_customer_mode=True)\n  # \u0438 \u0442\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0435\u0433\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442.\n  # \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c context_user_code \u043d\u0435 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f\n  print(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0442\u043e-\u043b\u0438\u0431\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\")\n  print(\"\u0414\u043b\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Enter\")\n  if input(\">>> \"):\n    await add_user()\n    await add_user()\n  else:\n    # \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 one_customer_mode=True\n    context_user_code.set(\"212332030\")\n      \n    await refund()\n    \n\n  balances = await tochka.get_balances()\n  print(balances[0].amount)\n\n\nasyncio.run(main())\n```\n",
    "bugtrack_url": null,
    "license": "Mozilla Public License 2.0",
    "summary": "Simple Tochka Bank Open API client",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/WhiteApfel/tochka_api",
        "Source code": "https://github.com/WhiteApfel/tochka-api",
        "Write me": "https://t.me/whiteapfel"
    },
    "split_keywords": [
        "tochka",
        "openapi",
        "api",
        "bank"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "accb9d315b3b646269e81ffe90a39bbfb1fa48a65f3f8347ffde142f5fee8bfe",
                "md5": "73304fd6ba5b83b92acb403c7610699b",
                "sha256": "1d8b2bf08501d64ed636807c5dfa9d53c5478148eb2fab14f78dc88d09fe9055"
            },
            "downloads": -1,
            "filename": "tochka_api-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "73304fd6ba5b83b92acb403c7610699b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21157,
            "upload_time": "2023-06-09T18:37:10",
            "upload_time_iso_8601": "2023-06-09T18:37:10.855369Z",
            "url": "https://files.pythonhosted.org/packages/ac/cb/9d315b3b646269e81ffe90a39bbfb1fa48a65f3f8347ffde142f5fee8bfe/tochka_api-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "937b824abc0b87453ca5703241e3a34b8f58edf29ef8d5ab6f7415def4606c51",
                "md5": "cc16ccf1dad5ab21ad486fcf75075f8b",
                "sha256": "eb93070d9c668fdcd427a95a8186604cd487b9277de5e55fbf2e0085aad4a61d"
            },
            "downloads": -1,
            "filename": "tochka_api-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cc16ccf1dad5ab21ad486fcf75075f8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 18908,
            "upload_time": "2023-06-09T18:37:12",
            "upload_time_iso_8601": "2023-06-09T18:37:12.210935Z",
            "url": "https://files.pythonhosted.org/packages/93/7b/824abc0b87453ca5703241e3a34b8f58edf29ef8d5ab6f7415def4606c51/tochka_api-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-09 18:37:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "WhiteApfel",
    "github_project": "tochka_api",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pydantic",
            "specs": [
                [
                    "~=",
                    "1.10.1"
                ]
            ]
        },
        {
            "name": "httpx",
            "specs": [
                [
                    "~=",
                    "0.23.0"
                ]
            ]
        },
        {
            "name": "ujson",
            "specs": [
                [
                    "~=",
                    "5.4.0"
                ]
            ]
        },
        {
            "name": "appdirs",
            "specs": [
                [
                    "~=",
                    "1.4.4"
                ]
            ]
        }
    ],
    "lcname": "tochka-api"
}
        
Elapsed time: 5.28757s