mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
All payment type done.
This commit is contained in:
parent
9134e8dd1a
commit
5ed333492b
@ -544,6 +544,19 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m
|
|||||||
payload['inline_message_id'] = inline_message_id
|
payload['inline_message_id'] = inline_message_id
|
||||||
return _make_request(token, method_url, params=payload)
|
return _make_request(token, method_url, params=payload)
|
||||||
|
|
||||||
|
# Payments (https://core.telegram.org/bots/api#payments)
|
||||||
|
|
||||||
|
def send_invoice():
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
def answer_shippingQuery():
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
def answer_pre_checkout_query():
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
# InlineQuery
|
# InlineQuery
|
||||||
|
|
||||||
|
170
telebot/types.py
170
telebot/types.py
@ -148,9 +148,11 @@ class WebhookInfo(JsonDeserializable):
|
|||||||
max_connections = obj['max_connections']
|
max_connections = obj['max_connections']
|
||||||
if 'allowed_updates' in obj:
|
if 'allowed_updates' in obj:
|
||||||
allowed_updates = obj['allowed_updates']
|
allowed_updates = obj['allowed_updates']
|
||||||
return cls(url, has_custom_certificate, pending_update_count, last_error_date, last_error_message, max_connections, allowed_updates)
|
return cls(url, has_custom_certificate, pending_update_count, last_error_date, last_error_message,
|
||||||
|
max_connections, allowed_updates)
|
||||||
|
|
||||||
def __init__(self, url, has_custom_certificate, pending_update_count, last_error_date, last_error_message, max_connections, allowed_updates):
|
def __init__(self, url, has_custom_certificate, pending_update_count, last_error_date, last_error_message,
|
||||||
|
max_connections, allowed_updates):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.has_custom_certificate = has_custom_certificate
|
self.has_custom_certificate = has_custom_certificate
|
||||||
self.pending_update_count = pending_update_count
|
self.pending_update_count = pending_update_count
|
||||||
@ -1608,3 +1610,167 @@ class GameHighScore(JsonDeserializable):
|
|||||||
self.position = position
|
self.position = position
|
||||||
self.user = user
|
self.user = user
|
||||||
self.score = score
|
self.score = score
|
||||||
|
|
||||||
|
|
||||||
|
# Payments
|
||||||
|
|
||||||
|
class LabeledPrice(JsonSerializable):
|
||||||
|
def __init__(self, label, amount):
|
||||||
|
self.label = label
|
||||||
|
self.amount = amount
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return json.dumps(self.to_dic())
|
||||||
|
|
||||||
|
def to_dic(self):
|
||||||
|
return {'label': self.label, 'amount': self.amount}
|
||||||
|
|
||||||
|
|
||||||
|
class Invoice(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
title = obj['title']
|
||||||
|
description = obj['description']
|
||||||
|
start_parameter = obj['start_parameter']
|
||||||
|
currency = obj['currency']
|
||||||
|
total_amount = obj['total_amount']
|
||||||
|
return cls(title, description, start_parameter, currency, total_amount)
|
||||||
|
|
||||||
|
def __init__(self, title, description, start_parameter, currency, total_amount):
|
||||||
|
self.title = title
|
||||||
|
self.description = description
|
||||||
|
self.start_parameter = start_parameter
|
||||||
|
self.currency = currency
|
||||||
|
self.total_amount = total_amount
|
||||||
|
|
||||||
|
|
||||||
|
class ShippingAddress(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
country_code = obj['country_code']
|
||||||
|
state = obj['state']
|
||||||
|
city = obj['city']
|
||||||
|
street_line1 = obj['street_line1']
|
||||||
|
street_line2 = obj['street_line2']
|
||||||
|
post_code = obj['post_code']
|
||||||
|
return cls(country_code, state, city, street_line1, street_line2, post_code)
|
||||||
|
|
||||||
|
def __init__(self, country_code, state, city, street_line1, street_line2, post_code):
|
||||||
|
self.country_code = country_code
|
||||||
|
self.state = state
|
||||||
|
self.city = city
|
||||||
|
self.street_line1 = street_line1
|
||||||
|
self.street_line2 = street_line2
|
||||||
|
self.post_code = post_code
|
||||||
|
|
||||||
|
|
||||||
|
class OrderInfo(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
name = obj.get('name')
|
||||||
|
phone_number = obj.get('phone_number')
|
||||||
|
email = obj.get('email')
|
||||||
|
shipping_address = None
|
||||||
|
if 'shipping_address' in obj:
|
||||||
|
shipping_address = ShippingAddress.de_json(obj['shipping_address'])
|
||||||
|
return cls(name, phone_number, email, shipping_address)
|
||||||
|
|
||||||
|
def __init__(self, name, phone_number, email, shipping_address):
|
||||||
|
self.name = name
|
||||||
|
self.phone_number = phone_number
|
||||||
|
self.email = email
|
||||||
|
self.shipping_address = shipping_address
|
||||||
|
|
||||||
|
|
||||||
|
class ShippingOption(JsonSerializable):
|
||||||
|
def __init__(self, id, title):
|
||||||
|
self.id = id
|
||||||
|
self.title = title
|
||||||
|
self.prices = []
|
||||||
|
|
||||||
|
def add_price(self, *args):
|
||||||
|
"""
|
||||||
|
Add LabeledPrice to ShippingOption
|
||||||
|
:param args: LabeledPrices
|
||||||
|
"""
|
||||||
|
for price in args:
|
||||||
|
self.prices.append(price)
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
price_list = []
|
||||||
|
for p in self.prices:
|
||||||
|
price_list.append(p.to_dic())
|
||||||
|
json_dict = {'id': self.id, 'title': self.title, 'prices': price_list}
|
||||||
|
return json_dict
|
||||||
|
|
||||||
|
|
||||||
|
class SuccessfulPayment(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
currency = obj['currency']
|
||||||
|
total_amount = obj['total_amount']
|
||||||
|
invoice_payload = obj['invoice_payload']
|
||||||
|
shipping_option_id = obj.get('shipping_option_id')
|
||||||
|
order_info = None
|
||||||
|
if 'order_info' in obj:
|
||||||
|
order_info = OrderInfo.de_json(obj['order_info'])
|
||||||
|
telegram_payment_charge_id = obj['telegram_payment_charge_id']
|
||||||
|
provider_payment_charge_id = obj['provider_payment_charge_id']
|
||||||
|
return cls(currency, total_amount, invoice_payload, shipping_option_id, order_info,
|
||||||
|
telegram_payment_charge_id, provider_payment_charge_id)
|
||||||
|
|
||||||
|
def __init__(self, currency, total_amount, invoice_payload, shipping_option_id, order_info,
|
||||||
|
telegram_payment_charge_id, provider_payment_charge_id):
|
||||||
|
self.currency = currency
|
||||||
|
self.total_amount = total_amount
|
||||||
|
self.invoice_payload = invoice_payload
|
||||||
|
self.shipping_option_id = shipping_option_id
|
||||||
|
self.order_info = order_info
|
||||||
|
self.telegram_payment_charge_id = telegram_payment_charge_id
|
||||||
|
self.provider_payment_charge_id = provider_payment_charge_id
|
||||||
|
|
||||||
|
|
||||||
|
class ShippingQuery(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
id = obj['id']
|
||||||
|
from_user = User.de_json(obj['from'])
|
||||||
|
invoice_payload = obj['invoice_payload']
|
||||||
|
shipping_address = ShippingAddress.de_json(obj['shipping_address'])
|
||||||
|
return cls(id, from_user, invoice_payload, shipping_address)
|
||||||
|
|
||||||
|
def __init__(self, id, from_user, invoice_payload, shipping_address):
|
||||||
|
self.id = id
|
||||||
|
self.from_user = from_user
|
||||||
|
self.invoice_payload = invoice_payload
|
||||||
|
self.shipping_address = shipping_address
|
||||||
|
|
||||||
|
|
||||||
|
class PreCheckoutQuery(JsonDeserializable):
|
||||||
|
@classmethod
|
||||||
|
def de_json(cls, json_string):
|
||||||
|
obj = cls.check_json(json_string)
|
||||||
|
id = obj['id']
|
||||||
|
from_user = User.de_json(obj['from'])
|
||||||
|
currency = obj['currency']
|
||||||
|
total_amount = obj['total_amount']
|
||||||
|
invoice_payload = obj['invoice_payload']
|
||||||
|
shipping_option_id = obj.get('shipping_option_id')
|
||||||
|
order_info = None
|
||||||
|
if 'order_info' in obj:
|
||||||
|
order_info = OrderInfo.de_json(obj['order_info'])
|
||||||
|
return cls(id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info)
|
||||||
|
|
||||||
|
def __init__(self, id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info):
|
||||||
|
self.id = id
|
||||||
|
self.from_user = from_user
|
||||||
|
self.currency = currency
|
||||||
|
self.total_amount = total_amount
|
||||||
|
self.invoice_payload = invoice_payload
|
||||||
|
self.shipping_option_id = shipping_option_id
|
||||||
|
self.order_info = order_info
|
||||||
|
Loading…
Reference in New Issue
Block a user