From 1bc3233823930a0ebc25a8ee8d35c4c96047c8c0 Mon Sep 17 00:00:00 2001 From: shriMADhav U k Date: Sun, 8 Sep 2024 18:05:22 +0200 Subject: [PATCH] Return list of photos and videos instead of bool in send_payment_form Co-authored-by: KurimuzonAkuma --- compiler/errors/source/400_BAD_REQUEST.tsv | 1 + .../methods/business/send_payment_from.py | 31 ++++++++++++++----- pyrogram/types/messages_and_media/message.py | 9 ++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index b3b8b4e33e..578fc663fc 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -241,6 +241,7 @@ MAX_DATE_INVALID The specified maximum date is invalid. MAX_ID_INVALID The provided max ID is invalid. MAX_QTS_INVALID The specified max_qts is invalid. MD5_CHECKSUM_INVALID The MD5 checksums do not match. +MEDIA_ALREADY_PAID The specified paid media is already paid. MEDIA_CAPTION_TOO_LONG The caption is too long. MEDIA_EMPTY The provided media object is invalid. MEDIA_FILE_INVALID The specified media file is invalid. diff --git a/pyrogram/methods/business/send_payment_from.py b/pyrogram/methods/business/send_payment_from.py index 6a59bccc99..1131b3558a 100644 --- a/pyrogram/methods/business/send_payment_from.py +++ b/pyrogram/methods/business/send_payment_from.py @@ -16,19 +16,24 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Union +from typing import List, Union import pyrogram -from pyrogram import raw +from pyrogram import raw, types class SendPaymentForm: async def send_payment_form( - self: "pyrogram.Client", *, + self: "pyrogram.Client", + *, chat_id: Union[int, str] = None, message_id: int = None, invoice_link: str = None - ) -> bool: + ) -> Union[ + bool, + List["types.PaidMediaPhoto"], + List["types.PaidMediaVideo"] + ]: """Pay an invoice. .. note:: @@ -49,7 +54,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. + ``bool`` | List of :obj:`~pyrogram.types.PaidMediaPhoto` | List of :obj:`~pyrogram.types.PaidMediaVideo`: On success, the list of bought photos and videos is returned. Example: .. code-block:: python @@ -85,7 +90,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 @@ -101,4 +106,16 @@ 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: + paid_media = types.PaidMedia._parse( + self, + ext_media + ) + if paid_media: + medias.append(paid_media) + + return types.List(medias) if medias else True diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 3ff290a8d0..b823622346 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -5235,7 +5235,11 @@ async def translate( ) - async def pay(self) -> bool: + async def pay(self) -> Union[ + bool, + List["types.PaidMediaPhoto"], + List["types.PaidMediaVideo"] + ]: """Bound method *pay* of :obj:`~pyrogram.types.Message`. Use as a shortcut for: @@ -5253,7 +5257,8 @@ async def pay(self) -> bool: await message.pay() Returns: - True on success. + ``bool`` | List of :obj:`~pyrogram.types.PaidMediaPhoto` | List of :obj:`~pyrogram.types.PaidMediaVideo`: On success, the list of bought photos and videos is returned. + """ return await self._client.send_payment_form( chat_id=self.chat.id,