Skip to content

Commit 3a10c90

Browse files
committed
Payments methods
1 parent f8fed5c commit 3a10c90

File tree

1 file changed

+93
-10
lines changed

1 file changed

+93
-10
lines changed

telebot/apihelper.py

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def edit_message_reply_markup(token, chat_id=None, message_id=None, inline_messa
472472
return _make_request(token, method_url, params=payload)
473473

474474

475-
def delete_message(token, chat_id=None, message_id=None):
475+
def delete_message(token, chat_id, message_id):
476476
method_url = r'deleteMessage'
477477
payload = {'chat_id': chat_id, 'message_id': message_id}
478478
return _make_request(token, method_url, params=payload)
@@ -546,17 +546,100 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m
546546

547547
# Payments (https://core.telegram.org/bots/api#payments)
548548

549-
def send_invoice():
550-
# TODO
551-
pass
549+
def send_invoice(token, chat_id, title, description, invoice_payload, provider_token, currency, prices, start_parameter=None,
550+
photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None,
551+
need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None,
552+
disable_notification=None, reply_to_message_id=None, reply_markup=None):
553+
"""
554+
Use this method to send invoices. On success, the sent Message is returned.
555+
:param token: Bot's token (you don't need to fill this)
556+
:param chat_id: Unique identifier for the target private chat
557+
:param title: Product name
558+
:param description: Product description
559+
:param payload: Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
560+
:param provider_token: Payments provider token, obtained via @Botfather
561+
:param currency: Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies
562+
:param prices: Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
563+
:param start_parameter: Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
564+
:param photo_url: URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
565+
:param photo_size: Photo size
566+
:param photo_width: Photo width
567+
:param photo_height: Photo height
568+
:param need_name: Pass True, if you require the user's full name to complete the order
569+
:param need_phone_number: Pass True, if you require the user's phone number to complete the order
570+
:param need_email: Pass True, if you require the user's email to complete the order
571+
:param need_shipping_address: Pass True, if you require the user's shipping address to complete the order
572+
:param is_flexible: Pass True, if the final price depends on the shipping method
573+
:param disable_notification: Sends the message silently. Users will receive a notification with no sound.
574+
:param reply_to_message_id: If the message is a reply, ID of the original message
575+
:param reply_markup: A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button
576+
:return:
577+
"""
578+
method_url = r'sendInvoice'
579+
payload = {'chat_id': chat_id, 'title': title, 'description': description, 'payload': invoice_payload, 'provider_token': provider_token, 'currency': currency, 'prices': prices}
580+
if start_parameter:
581+
payload['start_parameter'] = start_parameter
582+
if photo_url:
583+
payload['photo_url'] = photo_url
584+
if photo_size:
585+
payload['photo_size'] = photo_size
586+
if photo_width:
587+
payload['photo_width'] = photo_width
588+
if photo_height:
589+
payload['photo_height'] = photo_height
590+
if need_name:
591+
payload['need_name'] = need_name
592+
if need_phone_number:
593+
payload['need_phone_number'] = need_phone_number
594+
if need_email:
595+
payload['need_email'] = need_email
596+
if need_shipping_address:
597+
payload['need_shipping_address'] = need_shipping_address
598+
if is_flexible:
599+
payload['is_flexible'] = is_flexible
600+
if disable_notification:
601+
payload['disable_notification'] = disable_notification
602+
if reply_to_message_id:
603+
payload['reply_to_message_id'] = reply_to_message_id
604+
if reply_markup:
605+
payload['reply_markup'] = reply_markup
606+
return _make_request(token, method_url, params=payload)
607+
552608

553-
def answer_shippingQuery():
554-
# TODO
555-
pass
609+
def answer_shippingQuery(token, shipping_query_id, ok, shipping_options=None, error_message=None):
610+
"""
611+
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.
612+
:param token: Bot's token (you don't need to fill this)
613+
:param shipping_query_id: Unique identifier for the query to be answered
614+
:param ok: Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
615+
:param shipping_options: Required if ok is True. A JSON-serialized array of available shipping options.
616+
:param error_message: Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
617+
:return:
618+
"""
619+
method_url = 'answerShippingQuery'
620+
payload = {'shipping_query_id': shipping_query_id, 'ok': ok}
621+
if shipping_options:
622+
payload['reply_markup'] = shipping_options
623+
if error_message:
624+
payload['reply_markup'] = error_message
625+
return _make_request(token, method_url, params=payload)
626+
627+
628+
def answer_pre_checkout_query(token, pre_checkout_query_id, ok, error_message=None):
629+
"""
630+
Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
631+
:param token: Bot's token (you don't need to fill this)
632+
:param pre_checkout_query_id: Unique identifier for the query to be answered
633+
:param ok: Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
634+
:param error_message: Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
635+
:return:
636+
"""
637+
method_url = 'answerPreCheckoutQuery'
638+
payload = {'pre_checkout_query_id': pre_checkout_query_id, 'ok': ok}
639+
if error_message:
640+
payload['error_message'] = error_message
641+
return _make_request(token, method_url, params=payload)
556642

557-
def answer_pre_checkout_query():
558-
# TODO
559-
pass
560643

561644
# InlineQuery
562645

0 commit comments

Comments
 (0)