pyrofork: Update send_invoice doc

also add support for non-iterable prices

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2024-08-03 01:12:37 +07:00
parent f030f00e9d
commit e0e5bdb2cd
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5

View file

@ -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,