From e0e5bdb2cd839235099ee2795f01513afb26cc5b Mon Sep 17 00:00:00 2001 From: wulan17 Date: Sat, 3 Aug 2024 01:12:37 +0700 Subject: [PATCH] pyrofork: Update send_invoice doc also add support for non-iterable prices Signed-off-by: wulan17 --- pyrogram/methods/business/send_invoice.py | 30 ++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pyrogram/methods/business/send_invoice.py b/pyrogram/methods/business/send_invoice.py index 2ae44c75..1b2afa92 100644 --- a/pyrogram/methods/business/send_invoice.py +++ b/pyrogram/methods/business/send_invoice.py @@ -27,7 +27,7 @@ class SendInvoice: title: str, description: str, currency: str, - prices: List["types.LabeledPrice"], + prices: Union["types.LabeledPrice", List["types.LabeledPrice"]], provider: str = None, provider_data: str = None, payload: str = None, @@ -60,8 +60,10 @@ class SendInvoice: Three-letter ISO 4217 currency code. `XTR` for Telegram Stars. - prices (List of :obj:`~pyrogram.types.LabeledPrice`): + prices (:obj:`~pyrogram.types.LabeledPrice` | List of :obj:`~pyrogram.types.LabeledPrice`): Price with label. + If you add multiple prices, the prices will be added up. + For stars invoice you can only have one item. provider (``str``, *optional*): Payment provider. @@ -113,13 +115,27 @@ class SendInvoice: Example: .. code-block:: python - # USD + # USD (single prices) app.send_invoice( chat_id, title="Product Name", description="Product Description", currency="USD", - prices=[types.LabeledPrice("Product", 1000)], + prices=types.LabeledPrice("Product", 1000), + provider="Stripe_provider_codes", + provider_data="{}" + ) + + # USD (multiple prices) + app.send_invoice( + chat_id, + title="Product Name", + description="Product Description", + currency="USD", + prices=[ + types.LabeledPrice("Product 1", 1000), + types.LabeledPrice("Product 2", 2000) + ], provider="Stripe_provider_codes", provider_data="{}" ) @@ -130,10 +146,12 @@ class SendInvoice: title="Product Name", description="Product Description", currency="XTR", - prices=[types.LabeledPrice("Product", 1000)] + prices=types.LabeledPrice("Product", 1000) ) """ + is_iterable = not isinstance(prices, types.LabeledPrice) + if reply_markup is not None: has_buy_button = False for i in reply_markup.inline_keyboard: @@ -170,7 +188,7 @@ class SendInvoice: description=description, invoice=raw.types.Invoice( currency=currency, - prices=[price.write() for price in prices] + prices=[price.write() for price in prices] if is_iterable else [prices.write()] ), payload=encoded_payload, provider=provider,