mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Refactor examples/payments.py
This commit is contained in:
parent
95fcaaeed7
commit
68aa7dbf1a
2 changed files with 10 additions and 11 deletions
|
|
@ -7,7 +7,7 @@ from aiogram.dispatcher.handler import CancelHandler, current_handler
|
||||||
from aiogram.dispatcher.middlewares import BaseMiddleware
|
from aiogram.dispatcher.middlewares import BaseMiddleware
|
||||||
from aiogram.utils.exceptions import Throttled
|
from aiogram.utils.exceptions import Throttled
|
||||||
|
|
||||||
TOKEN = 'BOT TOKEN HERE'
|
TOKEN = 'BOT_TOKEN_HERE'
|
||||||
|
|
||||||
# In this example Redis storage is used
|
# In this example Redis storage is used
|
||||||
storage = RedisStorage2(db=5)
|
storage = RedisStorage2(db=5)
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from aiogram import Bot
|
from aiogram import Bot
|
||||||
from aiogram import types
|
from aiogram import types
|
||||||
from aiogram.dispatcher import Dispatcher
|
from aiogram.dispatcher import Dispatcher
|
||||||
from aiogram.types.message import ContentTypes
|
from aiogram.types.message import ContentTypes
|
||||||
from aiogram.utils import executor
|
from aiogram.utils import executor
|
||||||
|
|
||||||
BOT_TOKEN = 'BOT TOKEN HERE'
|
|
||||||
PAYMENTS_PROVIDER_TOKEN = '123456789:TEST:1234567890abcdef1234567890abcdef'
|
BOT_TOKEN = 'BOT_TOKEN_HERE'
|
||||||
|
PAYMENTS_PROVIDER_TOKEN = '123456789:TEST:1422'
|
||||||
|
|
||||||
bot = Bot(BOT_TOKEN)
|
bot = Bot(BOT_TOKEN)
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
|
|
@ -15,13 +14,13 @@ dp = Dispatcher(bot)
|
||||||
# Setup prices
|
# Setup prices
|
||||||
prices = [
|
prices = [
|
||||||
types.LabeledPrice(label='Working Time Machine', amount=5750),
|
types.LabeledPrice(label='Working Time Machine', amount=5750),
|
||||||
types.LabeledPrice(label='Gift wrapping', amount=500)
|
types.LabeledPrice(label='Gift wrapping', amount=500),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Setup shipping options
|
# Setup shipping options
|
||||||
shipping_options = [
|
shipping_options = [
|
||||||
types.ShippingOption(id='instant', title='WorldWide Teleporter').add(types.LabeledPrice('Teleporter', 1000)),
|
types.ShippingOption(id='instant', title='WorldWide Teleporter').add(types.LabeledPrice('Teleporter', 1000)),
|
||||||
types.ShippingOption(id='pickup', title='Local pickup').add(types.LabeledPrice('Pickup', 300))
|
types.ShippingOption(id='pickup', title='Local pickup').add(types.LabeledPrice('Pickup', 300)),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,7 +58,7 @@ async def cmd_buy(message: types.Message):
|
||||||
' Order our Working Time Machine today!',
|
' Order our Working Time Machine today!',
|
||||||
provider_token=PAYMENTS_PROVIDER_TOKEN,
|
provider_token=PAYMENTS_PROVIDER_TOKEN,
|
||||||
currency='usd',
|
currency='usd',
|
||||||
photo_url='https://images.fineartamerica.com/images-medium-large/2-the-time-machine-dmitriy-khristenko.jpg',
|
photo_url='https://telegra.ph/file/d08ff863531f10bf2ea4b.jpg',
|
||||||
photo_height=512, # !=0/None or picture won't be shown
|
photo_height=512, # !=0/None or picture won't be shown
|
||||||
photo_width=512,
|
photo_width=512,
|
||||||
photo_size=512,
|
photo_size=512,
|
||||||
|
|
@ -69,14 +68,14 @@ async def cmd_buy(message: types.Message):
|
||||||
payload='HAPPY FRIDAYS COUPON')
|
payload='HAPPY FRIDAYS COUPON')
|
||||||
|
|
||||||
|
|
||||||
@dp.shipping_query_handler(func=lambda query: True)
|
@dp.shipping_query_handler(lambda query: True)
|
||||||
async def shipping(shipping_query: types.ShippingQuery):
|
async def shipping(shipping_query: types.ShippingQuery):
|
||||||
await bot.answer_shipping_query(shipping_query.id, ok=True, shipping_options=shipping_options,
|
await bot.answer_shipping_query(shipping_query.id, ok=True, shipping_options=shipping_options,
|
||||||
error_message='Oh, seems like our Dog couriers are having a lunch right now.'
|
error_message='Oh, seems like our Dog couriers are having a lunch right now.'
|
||||||
' Try again later!')
|
' Try again later!')
|
||||||
|
|
||||||
|
|
||||||
@dp.pre_checkout_query_handler(func=lambda query: True)
|
@dp.pre_checkout_query_handler(lambda query: True)
|
||||||
async def checkout(pre_checkout_query: types.PreCheckoutQuery):
|
async def checkout(pre_checkout_query: types.PreCheckoutQuery):
|
||||||
await bot.answer_pre_checkout_query(pre_checkout_query.id, ok=True,
|
await bot.answer_pre_checkout_query(pre_checkout_query.id, ok=True,
|
||||||
error_message="Aliens tried to steal your card's CVV,"
|
error_message="Aliens tried to steal your card's CVV,"
|
||||||
|
|
@ -95,4 +94,4 @@ async def got_payment(message: types.Message):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
executor.start_polling(dp)
|
executor.start_polling(dp, skip_updates=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue