mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Add payment method. PEP8. Refactor.
This commit is contained in:
parent
2d10793686
commit
cf287af549
@ -613,7 +613,8 @@ class TeleBot:
|
|||||||
reply_markup)
|
reply_markup)
|
||||||
return types.Message.de_json(result)
|
return types.Message.de_json(result)
|
||||||
|
|
||||||
def set_game_score(self, user_id, score, force=None,chat_id=None, message_id=None, inline_message_id=None, edit_message=None):
|
def set_game_score(self, user_id, score, force=None, chat_id=None, message_id=None, inline_message_id=None,
|
||||||
|
edit_message=None):
|
||||||
result = apihelper.set_game_score(self.token, user_id, score, force, chat_id, message_id, inline_message_id,
|
result = apihelper.set_game_score(self.token, user_id, score, force, chat_id, message_id, inline_message_id,
|
||||||
edit_message)
|
edit_message)
|
||||||
if type(result) == bool:
|
if type(result) == bool:
|
||||||
@ -627,6 +628,24 @@ class TeleBot:
|
|||||||
ret.append(types.GameHighScore.de_json(r))
|
ret.append(types.GameHighScore.de_json(r))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def send_invoice(self, chat_id, title, description, invoice_payload, provider_token, currency, prices,
|
||||||
|
start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
|
||||||
|
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None,
|
||||||
|
is_flexible=None,
|
||||||
|
disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
result = apihelper.send_invoice(self.token, chat_id, title, description, invoice_payload, provider_token,
|
||||||
|
currency, prices, start_parameter, photo_url, photo_size, photo_width,
|
||||||
|
photo_height,
|
||||||
|
need_name, need_phone_number, need_email, need_shipping_address, is_flexible,
|
||||||
|
disable_notification, reply_to_message_id, reply_markup)
|
||||||
|
return types.Message.de_json(result)
|
||||||
|
|
||||||
|
def answer_shipping_query(self, shipping_query_id, ok, shipping_options=None, error_message=None):
|
||||||
|
return apihelper.answer_shippingQuery(self.token, shipping_query_id, ok, shipping_options, error_message)
|
||||||
|
|
||||||
|
def answer_pre_checkout_query(self, pre_checkout_query_id, ok, error_message=None):
|
||||||
|
return apihelper.answer_pre_checkout_query(self.token, pre_checkout_query_id, ok, error_message)
|
||||||
|
|
||||||
def edit_message_caption(self, caption, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None):
|
def edit_message_caption(self, caption, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None):
|
||||||
result = apihelper.edit_message_caption(self.token, caption, chat_id, message_id, inline_message_id,
|
result = apihelper.edit_message_caption(self.token, caption, chat_id, message_id, inline_message_id,
|
||||||
reply_markup)
|
reply_markup)
|
||||||
@ -1018,6 +1037,18 @@ class AsyncTeleBot(TeleBot):
|
|||||||
def get_game_high_scores(self, *args, **kwargs):
|
def get_game_high_scores(self, *args, **kwargs):
|
||||||
return TeleBot.get_game_high_scores(self, *args, **kwargs)
|
return TeleBot.get_game_high_scores(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def send_invoice(self, *args, **kwargs):
|
||||||
|
return TeleBot.send_invoice(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def answer_shipping_query(self, *args, **kwargs):
|
||||||
|
return TeleBot.answer_shipping_query(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@util.async()
|
||||||
|
def answer_pre_checkout_query(self, *args, **kwargs):
|
||||||
|
return TeleBot.answer_pre_checkout_query(self, *args, **kwargs)
|
||||||
|
|
||||||
@util.async()
|
@util.async()
|
||||||
def edit_message_caption(self, *args, **kwargs):
|
def edit_message_caption(self, *args, **kwargs):
|
||||||
return TeleBot.edit_message_caption(self, *args, **kwargs)
|
return TeleBot.edit_message_caption(self, *args, **kwargs)
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from requests.packages.urllib3 import fields
|
from requests.packages.urllib3 import fields
|
||||||
|
|
||||||
format_header_param = fields.format_header_param
|
format_header_param = fields.format_header_param
|
||||||
except ImportError:
|
except ImportError:
|
||||||
format_header_param = None
|
format_header_param = None
|
||||||
@ -39,7 +41,8 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas
|
|||||||
if params:
|
if params:
|
||||||
if 'timeout' in params: read_timeout = params['timeout'] + 10
|
if 'timeout' in params: read_timeout = params['timeout'] + 10
|
||||||
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
|
if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10
|
||||||
result = req_session.request(method, request_url, params=params, files=files, timeout=(connect_timeout, read_timeout))
|
result = req_session.request(method, request_url, params=params, files=files,
|
||||||
|
timeout=(connect_timeout, read_timeout))
|
||||||
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
|
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
|
||||||
return _check_result(method_name, result)['result']
|
return _check_result(method_name, result)['result']
|
||||||
|
|
||||||
@ -544,11 +547,12 @@ 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)
|
# Payments (https://core.telegram.org/bots/api#payments)
|
||||||
|
|
||||||
def send_invoice(token, chat_id, title, description, invoice_payload, provider_token, currency, prices, start_parameter=None,
|
def send_invoice(token, chat_id, title, description, invoice_payload, provider_token, currency, prices,
|
||||||
photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None,
|
start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None,
|
||||||
need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None,
|
need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None,
|
||||||
disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
"""
|
"""
|
||||||
Use this method to send invoices. On success, the sent Message is returned.
|
Use this method to send invoices. On success, the sent Message is returned.
|
||||||
@ -556,7 +560,7 @@ def send_invoice(token, chat_id, title, description, invoice_payload, provider_t
|
|||||||
:param chat_id: Unique identifier for the target private chat
|
:param chat_id: Unique identifier for the target private chat
|
||||||
:param title: Product name
|
:param title: Product name
|
||||||
:param description: Product description
|
:param description: Product description
|
||||||
:param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
|
:param invoice_payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
|
||||||
:param provider_token: Payments provider token, obtained via @Botfather
|
:param provider_token: Payments provider token, obtained via @Botfather
|
||||||
:param currency: Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
|
:param currency: Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
|
||||||
:param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
|
:param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
|
||||||
@ -576,9 +580,9 @@ def send_invoice(token, chat_id, title, description, invoice_payload, provider_t
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
method_url = r'sendInvoice'
|
method_url = r'sendInvoice'
|
||||||
payload = {'chat_id': chat_id, 'title': title, 'description': description, 'payload': invoice_payload, 'provider_token': provider_token, 'currency': currency, 'prices': prices}
|
payload = {'chat_id': chat_id, 'title': title, 'description': description, 'payload': invoice_payload,
|
||||||
if start_parameter:
|
'provider_token': provider_token, 'start_parameter': start_parameter, 'currency': currency,
|
||||||
payload['start_parameter'] = start_parameter
|
'prices': _convert_list_json_serializable(prices)}
|
||||||
if photo_url:
|
if photo_url:
|
||||||
payload['photo_url'] = photo_url
|
payload['photo_url'] = photo_url
|
||||||
if photo_size:
|
if photo_size:
|
||||||
@ -602,11 +606,11 @@ def send_invoice(token, chat_id, title, description, invoice_payload, provider_t
|
|||||||
if reply_to_message_id:
|
if reply_to_message_id:
|
||||||
payload['reply_to_message_id'] = reply_to_message_id
|
payload['reply_to_message_id'] = reply_to_message_id
|
||||||
if reply_markup:
|
if reply_markup:
|
||||||
payload['reply_markup'] = reply_markup
|
payload['reply_markup'] = _convert_markup(reply_markup)
|
||||||
return _make_request(token, method_url, params=payload)
|
return _make_request(token, method_url, params=payload)
|
||||||
|
|
||||||
|
|
||||||
def answer_shippingQuery(token, shipping_query_id, ok, shipping_options=None, error_message=None):
|
def answer_shipping_query(token, shipping_query_id, ok, shipping_options=None, error_message=None):
|
||||||
"""
|
"""
|
||||||
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
|
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
|
||||||
:param token: Bot's token (you don't need to fill this)
|
:param token: Bot's token (you don't need to fill this)
|
||||||
@ -619,9 +623,9 @@ def answer_shippingQuery(token, shipping_query_id, ok, shipping_options=None, er
|
|||||||
method_url = 'answerShippingQuery'
|
method_url = 'answerShippingQuery'
|
||||||
payload = {'shipping_query_id': shipping_query_id, 'ok': ok}
|
payload = {'shipping_query_id': shipping_query_id, 'ok': ok}
|
||||||
if shipping_options:
|
if shipping_options:
|
||||||
payload['reply_markup'] = shipping_options
|
payload['reply_markup'] = _convert_list_json_serializable(shipping_options)
|
||||||
if error_message:
|
if error_message:
|
||||||
payload['reply_markup'] = error_message
|
payload['error_message'] = error_message
|
||||||
return _make_request(token, method_url, params=payload)
|
return _make_request(token, method_url, params=payload)
|
||||||
|
|
||||||
|
|
||||||
@ -672,7 +676,7 @@ def answer_callback_query(token, callback_query_id, text=None, show_alert=None,
|
|||||||
def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None,
|
def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None,
|
||||||
switch_pm_text=None, switch_pm_parameter=None):
|
switch_pm_text=None, switch_pm_parameter=None):
|
||||||
method_url = 'answerInlineQuery'
|
method_url = 'answerInlineQuery'
|
||||||
payload = {'inline_query_id': inline_query_id, 'results': _convert_inline_results(results)}
|
payload = {'inline_query_id': inline_query_id, 'results': _convert_list_json_serializable(results)}
|
||||||
if cache_time:
|
if cache_time:
|
||||||
payload['cache_time'] = cache_time
|
payload['cache_time'] = cache_time
|
||||||
if is_personal:
|
if is_personal:
|
||||||
@ -686,7 +690,7 @@ def answer_inline_query(token, inline_query_id, results, cache_time=None, is_per
|
|||||||
return _make_request(token, method_url, params=payload, method='post')
|
return _make_request(token, method_url, params=payload, method='post')
|
||||||
|
|
||||||
|
|
||||||
def _convert_inline_results(results):
|
def _convert_list_json_serializable(results):
|
||||||
ret = ''
|
ret = ''
|
||||||
for r in results:
|
for r in results:
|
||||||
if isinstance(r, types.JsonSerializable):
|
if isinstance(r, types.JsonSerializable):
|
||||||
@ -708,6 +712,7 @@ def _no_encode(func):
|
|||||||
return '{0}={1}'.format(key, val)
|
return '{0}={1}'.format(key, val)
|
||||||
else:
|
else:
|
||||||
return func(key, val)
|
return func(key, val)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user