-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpayment.py
84 lines (66 loc) · 2.66 KB
/
payment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sys
import time
from pprint import pprint
import telepot
from telepot.loop import MessageLoop
from telepot.namedtuple import LabeledPrice, ShippingOption
from telepot.delegate import (
per_invoice_payload, pave_event_space, create_open, per_message, call)
"""
Default payment bot script
"""
class OrderProcessor(telepot.helper.InvoiceHandler):
def __init__(self, *args, **kwargs):
super(OrderProcessor, self).__init__(*args, **kwargs)
def on_shipping_query(self, msg):
query_id, from_id, invoice_payload = telepot.glance(msg, flavor="shipping_query")
print("Shipping query:")
pprint(msg)
bot.answerShippingQuery(
query_id, True,
shipping_options=[
ShippingOption(id='fedex', title='FedEx', prices=[
LabeledPrice(label='Local', amount=345),
LabeledPrice(label='International', amount=2345)]),
ShippingOption(id='dhl', title="DHL", prices=[
LabeledPrice(label='Local', amount=345),
LabeledPrice(label='International', amount=2345)])
])
def on_pre_checkout_query(self, msg):
query_id, from_id, invoice_payload = telepot.glance(msg, flavor='pre_checkout_query')
print('Pre-Checkout query:')
pprint(msg)
bot.answerPreCheckoutQuery(query_id, True)
def on_chat_message(self, msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'successful_payment':
print('Successful payment has been received.')
else:
print('Chat message:')
pprint(msg)
def send_invoice(seed_tuple):
msg = seed_tuple[1]
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'text':
sent = bot.sendInvoice(
chat_id, "Nick's Hand Cream", "Manly hands with a feminine touch",
payload='something',
provider_token=PAYMENT_PROVIDER_TOKEN,
start_parameter='abcdefg',
currency='USD', prices=[
LabeledPrice(label='One Case', amount=456),
LabeledPrice(label='Multiple', amount=667)],
need_shipping_address=True, is_flexible=True)
print("Invoice sent:")
pprint(sent)
TOKEN = ""
PAYMENT_PROVIDER_TOKEN = ""
bot = telepot.DelegatorBot(TOKEN, [
(per_message(flavors=['chat']), call(send_invoice)),
pave_event_space()(
per_invoice_payload(), create_open, OrderProcessor, timeout=30
)
])
MessageLoop(bot).run_as_thread()
while 1:
time.sleep(10)