import datetime, threading, time
from pyqiwip2p import QiwiP2P
from pyqiwip2p.types import QiwiCustomer, QiwiDatetime
from datetime import timedelta
from aiogram.types import ParseMode
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram import Bot, Dispatcher, types, executor
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.dispatcher import FSMContext
p2p = QiwiP2P(auth_key="приватныйключ")
bot = Bot("токен")
dp = Dispatcher(bot, storage=MemoryStorage())
now = datetime.datetime.now()
@dp.message_handler(commands=['start', 'help'])
async def welcome(message: types.Message):
try:
p2p.reject(bill_id=new_bill.bill_id)
except:
pass
await message.answer('привет...')
@dp.message_handler(commands=['pay_qiwi_1'])
async def buy(message: types.Message):
global bill
price = 15
lifetime = 150
comment = 'Услуга'
bill = p2p.bill(amount=price, lifetime=lifetime, comment=comment)
link_oplata = bill.pay_url
await message.answer(f'<a href="{link_oplata}">Ссылка на оплату Qiwi {price} р.</a>', parse_mode="HTML")
x = threading.Thread(target=functionoplata, args=(message,))
x.start() #Запуск потока
def functionoplata(message):
oplata_time = datetime.datetime.now()
datetime_delta = oplata_time + timedelta(minutes=7)
while True:
status = p2p.check(bill_id=bill.bill_id).status
if status == 'PAID':
text = "оплата прошла!"
break
return text
elif datetime.datetime.now() > datetime_delta:
text = "ссылка недействительна"
break
return text
time.sleep(0.1)
if __name__ == '__main__':
executor.start_polling(dp)