Skip to content

codacy-badger/aioqiwi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🥝 aioqiwi

aioqiwi-code-style Python-version

Qiwi payments for humans(for healthy humans)

Supports most of qiwi apis: qiwi-maps, bills, wallet

Installation

pip install "https://github.com/uwinx/aioqiwi/archive/master.zip"

🔸 Dependencies

aioqiwi uses only aiohttp and that's enough, but in case you want increase perfomance of serialization and deserialization, you can install ujson or rapidjson

🔹 Dive-in Example

aioqiwi is a convenient tool with one-night solved architecture and its models generated from API-docs

import asyncio

from aioqiwi import Wallet
from aioqiwi.utils import BeautifulSum

async def qiwi():
    async with Wallet("TOKEN from https://qiwi.com/api") as wallet:
        wallet.phone_number = '+7878787878'  # phone number is not required by default, but some methods need it
        balance = await wallet.balance()
        print("ACCOUNTS:")
        for acc in balance.Accounts:
            print(acc.alias, BeautifulSum(acc.Balance).pretty)

asyncio.run(qiwi())

📣 Handling updates

aioqiwi provides user-friendly webhooks handler

from aioqiwi.wallet import QiwiUpdate, Wallet
from aioqiwi.utils import BeautifulSum

wallet = Wallet("...")

@wallet.on_update(incoming=True)
async def payments_handler(event: QiwiUpdate):
    print(f"{event.Payment.account} sent you {BeautifulSum(event.Payment).pretty}")

@wallet.on_update(incoming=True, comment_regex=r"^(special_code|another_special_code)+$")
async def secret_payments_handler(event: QiwiUpdate):
    print("*tovarish mayor suspiciously*",
          f"- WHO THE HECK IS `{event.Payment.account}`, HOW DID HE GET OUR CODE?",
          sep="\n",)

wallet.idle(port=6969)

💸 Making transactions

import asyncio
from aioqiwi import Wallet
from aioqiwi.utils import BeautifulSum

async def txn():
    async with Wallet('...') as wallet:
        payment = await wallet.transaction(14.88, '+7899966669')
        print(BeautifulSum(payment.Sum).pretty)

asyncio.run(txn())

🔥 Qiwi new API p2p transactions(bill-payments)

Cool qiwi bills!

import asyncio
from aioqiwi import QiwiKassa

async def kassa():
    async with QiwiKassa("SECRET KEY from p2p.qiwi.com or kassa.qiwi.com") as kassa:
        sent_invoice = await kassa.new_bill(14.88, lifetime=44)
        # setting lifetime to 44 ahead today [default is 10] 45 - is max
        print("Url to pay:", sent_invoice.pay_url)

asyncio.run(kassa())

sent_invoice.pay_url will redirect us to something like:

https://imbt.ga/gO8EzaFItB

💳 Handling bill payments

from aioqiwi.kassa import QiwiKassa, BillUpdate

kassa = QiwiKassa('PRIVATE_KEY')

@kassa.on_update(lambda bill: bill.Bill.Amount.currency == 'RUB')
async def my_shiny_rubles_handler(bill_update: BillUpdate):
    # do something
    pass

kassa.idle()

🗺 QIWI terminals

aioqiwi covers qiwi's MAPS api in aioqiwi.terminals module

🍼 Non-model returns(json)

import asyncio
from aioqiwi import Wallet

async def json():
    async with Wallet('...') as wallet:
        wallet.as_model = False
        print(await wallet.balance())

asyncio.run(json())

❓ HOW-TOs

You can find examples in examples/ directory in github repository. For start examples above should be enough.

👥 Contributing

It'd great if you issue some design components. Meantime api-designs are awful, I know.

🔧 TODOs

  • Error handling 🔥
  • Tests 🔥
  • Documentation

👨‍👨‍👦‍👦 Community

My group ✈️ Telegram

About

Convenient lib qiwi.com api-wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages