diff --git a/pyrogram/methods/payments/send_payment_form.py b/pyrogram/methods/payments/send_payment_form.py index cdce1056d1..23749a838d 100644 --- a/pyrogram/methods/payments/send_payment_form.py +++ b/pyrogram/methods/payments/send_payment_form.py @@ -17,10 +17,10 @@ # along with Pyrogram. If not, see . import re -from typing import Union +from typing import Union, List import pyrogram -from pyrogram import raw +from pyrogram import raw, types class SendPaymentForm: @@ -29,7 +29,7 @@ async def send_payment_form( chat_id: Union[int, str] = None, message_id: int = None, invoice_link: str = None - ) -> bool: + ) -> List[Union["types.Photo", "types.Video"]]: """Pay an invoice. .. note:: @@ -50,7 +50,7 @@ async def send_payment_form( Pass a invoice link in form of a *t.me/$...* link or slug itself to pay this invoice. Returns: - ``bool``: On success, True is returned. + List of :obj:`~pyrogram.types.Photo` | :obj:`~pyrogram.types.Video`: On success, the list of bought photos and videos is returned. Example: .. code-block:: python @@ -87,7 +87,7 @@ async def send_payment_form( form = await self.get_payment_form(chat_id=chat_id, message_id=message_id, invoice_link=invoice_link) # if form.invoice.currency == "XTR": - await self.invoke( + r = await self.invoke( raw.functions.payments.SendStarsForm( form_id=form.id, invoice=invoice @@ -103,4 +103,30 @@ async def send_payment_form( # ) # ) - return True + medias = [] + + if isinstance(r, raw.types.payments.PaymentResult): + for i in r.updates.updates: + if isinstance(i, raw.types.UpdateMessageExtendedMedia): + for ext_media in i.extended_media: + media = ext_media.media + + if isinstance(media, raw.types.MessageMediaPhoto): + medias.append(types.Photo._parse(self, media.photo)) + elif isinstance(media, raw.types.MessageMediaDocument): + doc = media.document + + attributes = {type(i): i for i in doc.attributes} + + file_name = getattr( + attributes.get( + raw.types.DocumentAttributeFilename, None + ), "file_name", None + ) + + video_attributes = attributes[raw.types.DocumentAttributeVideo] + + medias.append(types.Video._parse(self, doc, video_attributes, file_name)) + + return types.List(medias) + # elif isinstance(r, raw.types.payments.PaymentVerificationNeeded): diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 2e58d766bd..4aa02ad17b 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -25,7 +25,7 @@ from pyrogram import raw, enums from pyrogram import types from pyrogram import utils -from pyrogram.errors import ChannelPrivate, MessageIdsEmpty, PeerIdInvalid, ChannelPrivate, BotMethodInvalid, ChannelForumMissing +from pyrogram.errors import ChannelPrivate, MessageIdsEmpty, PeerIdInvalid, ChannelForumMissing from pyrogram.parser import utils as parser_utils, Parser from ..object import Object from ..update import Update @@ -4950,7 +4950,7 @@ async def view(self) -> bool: message_id=self.id ) - async def pay(self) -> bool: + async def pay(self) -> List[Union["types.Photo", "types.Video"]]: """Bound method *pay* of :obj:`~pyrogram.types.Message`. Use as a shortcut for: @@ -4968,7 +4968,7 @@ async def pay(self) -> bool: await message.pay() Returns: - True on success. + List of :obj:`~pyrogram.types.Photo` | :obj:`~pyrogram.types.Video`: On success, the list of bought photos and videos is returned. """ return await self._client.send_payment_form( chat_id=self.chat.id,