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
Co-authored-by: KurimuzonAkuma <[email protected]>
  • Loading branch information
SpEcHiDe and KurimuzonAkuma committed Sep 8, 2024
1 parent b2b5cb0 commit 1bc3233
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions compiler/errors/source/400_BAD_REQUEST.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 24 additions & 7 deletions pyrogram/methods/business/send_payment_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

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

0 comments on commit 1bc3233

Please sign in to comment.