Skip to content

Commit

Permalink
Return list of photos and videos instead of bool in send_payment_form
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Sep 8, 2024
1 parent 95546f8 commit 6684eaf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
38 changes: 32 additions & 6 deletions pyrogram/methods/payments/send_payment_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import re
from typing import Union
from typing import Union, List

import pyrogram
from pyrogram import raw
from pyrogram import raw, types


class SendPaymentForm:
Expand All @@ -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::
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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):
6 changes: 3 additions & 3 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down

0 comments on commit 6684eaf

Please sign in to comment.