diff --git a/pyrogram/methods/messages/send_invoice.py b/pyrogram/methods/messages/send_invoice.py index 0dde16d9..ce72bdcf 100644 --- a/pyrogram/methods/messages/send_invoice.py +++ b/pyrogram/methods/messages/send_invoice.py @@ -39,6 +39,7 @@ class SendInvoice: message_thread_id: int = None, quote_text: str = None, quote_entities: List["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None ): """Use this method to send invoices. @@ -96,6 +97,9 @@ class SendInvoice: List of special entities that appear in quote_text, which can be specified instead of *parse_mode*. for reply_to_message only. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An inline keyboard. If empty, one 'Buy' button will be shown. + Returns: :obj:`~pyrogram.types.Message`: On success, the sent message is returned. @@ -112,6 +116,21 @@ class SendInvoice: )) """ + if reply_markup is not None: + has_buy_button = False + for i in reply_markup.inline_keyboard: + for j in i: + if isinstance(j, types.InlineKeyboardButtonBuy): + has_buy_button = True + if not has_buy_button: + text = "Pay" + if currency == "XTR": + prices_total = 0 + for price in prices: + prices_total += price.amount + text = f"Pay ⭐️{prices_total}" + reply_markup.inline_keyboard.insert(0, [types.InlineKeyboardButtonBuy(text=text)]) + reply_to = await utils.get_reply_to( client=self, chat_id=chat_id, @@ -145,7 +164,8 @@ class SendInvoice: ), random_id=self.rnd_id(), reply_to=reply_to, - message="" + message="", + reply_markup=await reply_markup.write(self) if reply_markup is not None else None ) ) diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py index 3f74f2a1..1ac3effe 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py @@ -15,9 +15,12 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . +import pyrogram from ..object import Object +from pyrogram import raw + class InlineKeyboardButtonBuy(Object): """One button of the inline keyboard. For simple invoice buttons. @@ -42,4 +45,7 @@ class InlineKeyboardButtonBuy(Object): text=b.text ) - # TODO: Implement write method + async def write(self, _: "pyrogram.Client"): + return raw.types.KeyboardButtonBuy( + text=self.text + ) diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py index e91d1e0d..7ddcb69e 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py @@ -29,8 +29,10 @@ class InlineKeyboardMarkup(Object): """An inline keyboard that appears right next to the message it belongs to. Parameters: - inline_keyboard (List of List of :obj:`~pyrogram.types.InlineKeyboardButton`): + inline_keyboard (List of List of :obj:`~pyrogram.types.InlineKeyboardButton` | :obj:`~pyrogram.types.InlineKeyboardButtonBuy`): List of button rows, each represented by a List of InlineKeyboardButton objects. + :obj:`~pyrogram.types.InlineKeyboardButtonBuy` objects is only for :meth:`~pyrogram.Client.send_invoice`. + and only one needed in the first row. """ def __init__(self, inline_keyboard: List[List[Union["types.InlineKeyboardButton", "types.InlineKeyboardButtonBuy"]]]):