From d0a70e2929bf813eeec1cc423038a47e3c3f2e37 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Wed, 7 Aug 2024 19:54:08 +0700 Subject: [PATCH] pyrofork: Add support for non-iterable prices in create_invoice_link method Signed-off-by: wulan17 --- pyrogram/methods/business/create_invoice_link.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pyrogram/methods/business/create_invoice_link.py b/pyrogram/methods/business/create_invoice_link.py index 9b5b15ede..16beba5b6 100644 --- a/pyrogram/methods/business/create_invoice_link.py +++ b/pyrogram/methods/business/create_invoice_link.py @@ -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, @@ -65,8 +65,10 @@ async def create_invoice_link( currency (``str``): Three-letter ISO 4217 currency code, see `more on currencies `_. Pass ``XTR`` for payments in `Telegram Stars `_. - 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 `_. + 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 `_. Pass an empty string for payments in `Telegram Stars `_. @@ -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, @@ -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,