Skip to content

Commit

Permalink
pyrofork: Add support for non-iterable prices in create_invoice_link …
Browse files Browse the repository at this point in the history
…method

Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Aug 7, 2024
1 parent ce382c2 commit d0a70e2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyrogram/methods/business/create_invoice_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def create_invoice_link(
description: str,
payload: Union[str, bytes],
currency: str,
prices: List["types.LabeledPrice"],
prices: Union["types.LabeledPrice", List["types.LabeledPrice"]],
provider_token: str = None,
start_parameter: str = None,
provider_data: str = None,
Expand Down Expand Up @@ -65,8 +65,10 @@ async def create_invoice_link(
currency (``str``):
Three-letter ISO 4217 currency code, see `more on currencies <https://core.telegram.org/bots/payments#supported-currencies>`_. Pass ``XTR`` for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
prices (List of :obj:`~pyrogram.types.LabeledPrice`):
prices (:obj:`~pyrogram.types.LabeledPrice` | List of :obj:`~pyrogram.types.LabeledPrice`):
Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
If you add multiple prices, the prices will be added up.
For stars invoice you can only have one item.
provider_token (``str``, *optional*):
Payment provider token, obtained via `@BotFather <https://t.me/botfather>`_. Pass an empty string for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
Expand Down Expand Up @@ -115,6 +117,8 @@ async def create_invoice_link(
"""

is_iterable = not isinstance(prices, types.LabeledPrice)

rpc = raw.functions.payments.ExportInvoice(
invoice_media=raw.types.InputMediaInvoice(
title=title,
Expand All @@ -132,7 +136,7 @@ async def create_invoice_link(
) if photo_url else None,
invoice=raw.types.Invoice(
currency=currency,
prices=[i.write() for i in prices],
prices=[i.write() for i in prices] if is_iterable else [prices.write()],
test=self.test_mode,
name_requested=need_name,
phone_requested=need_phone_number,
Expand Down

0 comments on commit d0a70e2

Please sign in to comment.