Add New Parameters to create_invoice_link

This commit is contained in:
Hinrich Mahler 2024-11-17 21:04:22 +01:00
parent 8192822405
commit 87391ea028
4 changed files with 37 additions and 4 deletions

View file

@ -24,7 +24,7 @@ import contextlib
import copy import copy
import pickle import pickle
from collections.abc import Sequence from collections.abc import Sequence
from datetime import datetime from datetime import datetime, timedelta
from types import TracebackType from types import TracebackType
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
@ -8024,6 +8024,8 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
send_phone_number_to_provider: Optional[bool] = None, send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None, send_email_to_provider: Optional[bool] = None,
is_flexible: Optional[bool] = None, is_flexible: Optional[bool] = None,
subscription_period: Optional[Union[int, timedelta]] = None,
business_connection_id: Optional[str] = None,
*, *,
read_timeout: ODVInput[float] = DEFAULT_NONE, read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -8036,6 +8038,9 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
.. versionadded:: 20.0 .. versionadded:: 20.0
Args: Args:
business_connection_id (:obj:`str`, optional): |business_id_str|
.. versionadded:: NEXT.VERSION
title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`- title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`-
:tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters. :tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters.
description (:obj:`str`): Product description. description (:obj:`str`): Product description.
@ -8062,6 +8067,13 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
.. versionchanged:: 20.0 .. versionchanged:: 20.0
|sequenceargs| |sequenceargs|
subscription_period (:obj:`int` | :class:`datetime.timedelta`, optional): The time the
subscription will be active for before the next payment, either as number of
seconds or as :class:`datetime.timedelta` object. The currency must be set to
``XTR`` (Telegram Stars) if the parameter is used. Currently, it must always be
:tg-const:`telegram.constants.InvoiceLimit.SUBSCRIPTION_PERIOD` if specified.
.. versionadded:: NEXT.VERSION
max_tip_amount (:obj:`int`, optional): The maximum accepted amount for tips in the max_tip_amount (:obj:`int`, optional): The maximum accepted amount for tips in the
*smallest units* of the currency (integer, **not** float/double). For example, for *smallest units* of the currency (integer, **not** float/double). For example, for
a maximum tip of ``US$ 1.45`` pass ``max_tip_amount = 145``. See the ``exp`` a maximum tip of ``US$ 1.45`` pass ``max_tip_amount = 145``. See the ``exp``
@ -8127,6 +8139,12 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
"is_flexible": is_flexible, "is_flexible": is_flexible,
"send_phone_number_to_provider": send_phone_number_to_provider, "send_phone_number_to_provider": send_phone_number_to_provider,
"send_email_to_provider": send_email_to_provider, "send_email_to_provider": send_email_to_provider,
"subscription_period": (
subscription_period.total_seconds()
if isinstance(subscription_period, timedelta)
else subscription_period
),
"business_connection_id": business_connection_id,
} }
return await self._post( return await self._post(

View file

@ -2902,6 +2902,10 @@ class InvoiceLimit(IntEnum):
.. versionadded:: 21.6 .. versionadded:: 21.6
""" """
SUBSCRIPTION_PERIOD = datetime.timedelta(days=30).total_seconds()
""":obj:`int`: The period of time for which the subscription is active before
the next payment, passed as :paramref:`~telegram.Bot.create_invoice_link.subscription_period`
parameter of :meth:`telegram.Bot.create_invoice_link`."""
class UserProfilePhotosLimit(IntEnum): class UserProfilePhotosLimit(IntEnum):

View file

@ -20,7 +20,7 @@
"""This module contains an object that represents a Telegram Bot with convenience extensions.""" """This module contains an object that represents a Telegram Bot with convenience extensions."""
from collections.abc import Sequence from collections.abc import Sequence
from copy import copy from copy import copy
from datetime import datetime from datetime import datetime, timedelta
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
@ -1171,6 +1171,8 @@ class ExtBot(Bot, Generic[RLARGS]):
send_phone_number_to_provider: Optional[bool] = None, send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None, send_email_to_provider: Optional[bool] = None,
is_flexible: Optional[bool] = None, is_flexible: Optional[bool] = None,
subscription_period: Optional[Union[int, timedelta]] = None,
business_connection_id: Optional[str] = None,
*, *,
read_timeout: ODVInput[float] = DEFAULT_NONE, read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE, write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1204,6 +1206,8 @@ class ExtBot(Bot, Generic[RLARGS]):
write_timeout=write_timeout, write_timeout=write_timeout,
connect_timeout=connect_timeout, connect_timeout=connect_timeout,
pool_timeout=pool_timeout, pool_timeout=pool_timeout,
subscription_period=subscription_period,
business_connection_id=business_connection_id,
api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args), api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args),
) )

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License # You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/]. # along with this program. If not, see [http://www.gnu.org/licenses/].
import asyncio import asyncio
import datetime as dtm
import pytest import pytest
@ -122,10 +123,14 @@ class TestInvoiceWithoutRequest(InvoiceTestBase):
protect_content=True, protect_content=True,
) )
async def test_send_all_args_create_invoice_link(self, offline_bot, monkeypatch): @pytest.mark.parametrize("subscription_period", [42, dtm.timedelta(seconds=42)])
async def test_send_all_args_create_invoice_link(
self, offline_bot, monkeypatch, subscription_period
):
async def make_assertion(*args, **_): async def make_assertion(*args, **_):
kwargs = args[1] kwargs = args[1]
return all(kwargs[i] == i for i in kwargs) sp = kwargs.pop("subscription_period") == 42
return all(kwargs[i] == i for i in kwargs) and sp
monkeypatch.setattr(offline_bot, "_post", make_assertion) monkeypatch.setattr(offline_bot, "_post", make_assertion)
assert await offline_bot.create_invoice_link( assert await offline_bot.create_invoice_link(
@ -149,6 +154,8 @@ class TestInvoiceWithoutRequest(InvoiceTestBase):
send_phone_number_to_provider="send_phone_number_to_provider", send_phone_number_to_provider="send_phone_number_to_provider",
send_email_to_provider="send_email_to_provider", send_email_to_provider="send_email_to_provider",
is_flexible="is_flexible", is_flexible="is_flexible",
business_connection_id="business_connection_id",
subscription_period=subscription_period,
) )
async def test_send_object_as_provider_data( async def test_send_object_as_provider_data(