-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from GLEF1X/synchronous
0.2.13 pre_release
- Loading branch information
Showing
43 changed files
with
1,591 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ Qiwi usage examples | |
p2p | ||
basic_methods | ||
usage_without_context | ||
cache | ||
cache | ||
sync_support | ||
usage_with_aiogram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
================= | ||
Synchronous usage | ||
================= | ||
|
||
*glQiwiApi* also coverage synchronous usage, you can use it like in the example | ||
|
||
.. literalinclude:: ./../../examples/sync_usage.py | ||
:caption: sync_usage.py | ||
:language: python | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
================== | ||
Usage with aiogram | ||
================== | ||
|
||
|
||
.. literalinclude:: ./../../examples/usage_in_bots.py | ||
:caption: usage_in_bots.py | ||
:language: python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import datetime | ||
|
||
from glQiwiApi import QiwiWrapper, sync | ||
|
||
TOKEN = 'Api token from https://qiwi.com/api' | ||
WALLET = '+phone_number' | ||
|
||
# As always, we create an instance of the class, | ||
# but pass on "without_context" as True | ||
wallet = QiwiWrapper( | ||
api_access_token=TOKEN, | ||
phone_number=WALLET, | ||
without_context=True # add this param to use sync connector soon | ||
) | ||
|
||
|
||
def sync_function() -> None: | ||
start_date = datetime.datetime.now() - datetime.timedelta(days=5) | ||
# Use the sync () function and pass the function we want to execute | ||
# without calling it, that is, pass it as a regular variable | ||
result = sync(wallet.transactions, rows_num=50, start_date=start_date, | ||
end_date=datetime.datetime.now()) | ||
print(result) | ||
|
||
|
||
sync_function() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Union | ||
|
||
from aiogram import Bot, Dispatcher, types | ||
from aiogram.contrib.fsm_storage.memory import MemoryStorage | ||
from aiogram.dispatcher import FSMContext | ||
from aiogram.utils import executor | ||
|
||
from glQiwiApi import QiwiWrapper, types as qiwi_types | ||
|
||
wallet = QiwiWrapper( | ||
secret_p2p='YOUR_SECRET_P2P_TOKEN', | ||
without_context=True | ||
) | ||
|
||
BOT_TOKEN = 'BOT_TOKEN' | ||
|
||
bot = Bot(token=BOT_TOKEN, parse_mode=types.ParseMode.HTML) | ||
storage = MemoryStorage() | ||
dp = Dispatcher(bot, storage=storage) | ||
|
||
|
||
async def create_payment(amount: Union[float, int] = 1) -> qiwi_types.Bill: | ||
async with wallet: | ||
return await wallet.create_p2p_bill(amount=amount) | ||
|
||
|
||
@dp.message_handler(text='Хочу оплатить') | ||
async def payment(message: types.Message, state: FSMContext): | ||
bill = await create_payment() | ||
await message.answer( | ||
text=f'Хорошо, вот ваш счёт для оплаты:\n {bill.pay_url}' | ||
) | ||
await state.set_state('payment') | ||
await state.update_data(bill=bill) | ||
|
||
|
||
@dp.message_handler(state='payment', text='Оплатил') | ||
async def successful_payment(message: types.Message, state: FSMContext): | ||
async with state.proxy() as data: | ||
bill: qiwi_types.Bill = data.get('bill') | ||
status = await bill.check() | ||
if status: | ||
await message.answer('Вы успешно оплатили счет') | ||
await state.finish() | ||
else: | ||
await message.answer('Счет не оплачен') | ||
|
||
|
||
if __name__ == '__main__': | ||
executor.start_polling(dp, skip_updates=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import sys | ||
|
||
from glQiwiApi.qiwi import QiwiWrapper | ||
from glQiwiApi.utils.exceptions import RequestError, VersionError | ||
from glQiwiApi.yoo_money import YooMoneyAPI | ||
from glQiwiApi.utils import exceptions | ||
from .qiwi import QiwiWrapper, QiwiMaps # NOQA | ||
from .utils.basics import sync, to_datetime # NOQA | ||
from .utils.exceptions import * # NOQA | ||
from .yoo_money import YooMoneyAPI # NOQA | ||
|
||
__all__ = ( | ||
( | ||
'QiwiWrapper', | ||
'YooMoneyAPI', | ||
'QiwiMaps', | ||
'RequestError', | ||
'to_datetime', | ||
'sync' | ||
) + exceptions.__all__ # NOQA | ||
) | ||
|
||
|
||
class VersionError(Exception): | ||
""" | ||
Ошибка возникает, если ваша версия python не поддерживается библиотекой | ||
""" | ||
|
||
__all__ = [ | ||
'QiwiWrapper', | ||
'YooMoneyAPI', | ||
'RequestError' | ||
] | ||
|
||
if not sys.version_info[:2] >= (3, 7): | ||
raise VersionError( | ||
"Ваша версия python не поддерживается библиотекой glQiwiApi." | ||
"Минимальная версия для использования python 3.7" | ||
) | ||
|
||
__version__ = '0.2.12' | ||
__version__ = '0.2.13' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from .abstracts import ( | ||
AbstractParser, | ||
AbstractCacheController, | ||
AbstractPaymentWrapper, | ||
AioTestCase | ||
) | ||
from .aiohttp_custom_api import CustomParser | ||
from .basic_requests_api import HttpXParser, SimpleCache | ||
from .mixins import BillMixin, ToolsMixin | ||
|
||
__all__ = ( | ||
'HttpXParser', | ||
'SimpleCache', | ||
'AbstractParser', | ||
'AbstractPaymentWrapper', | ||
'AbstractCacheController', | ||
'AioTestCase', | ||
'BillMixin', | ||
'ToolsMixin', | ||
'CustomParser' | ||
) |
Oops, something went wrong.