Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bot API 8.0: Add New Parameters tocreate_invoice_link#4568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Bibo-Joshi merged 1 commit intoapi-8.0fromapi-8.0-createinvoicelink
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletiontelegram/_bot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@
import copy
import pickle
from collections.abc import Sequence
from datetime import datetime
from datetime import datetime, timedelta
from types import TracebackType
from typing import (
TYPE_CHECKING,
Expand DownExpand Up@@ -8024,6 +8024,8 @@ async def create_invoice_link(
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: 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,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand All@@ -8036,6 +8038,9 @@ async def create_invoice_link(
.. versionadded:: 20.0

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`-
:tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters.
description (:obj:`str`): Product description.
Expand All@@ -8062,6 +8067,13 @@ async def create_invoice_link(

.. versionchanged:: 20.0
|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
*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``
Expand DownExpand Up@@ -8127,6 +8139,12 @@ async def create_invoice_link(
"is_flexible": is_flexible,
"send_phone_number_to_provider": send_phone_number_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(
Expand Down
4 changes: 4 additions & 0 deletionstelegram/constants.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2902,6 +2902,10 @@ class InvoiceLimit(IntEnum):

.. 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):
Expand Down
6 changes: 5 additions & 1 deletiontelegram/ext/_extbot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@
"""This module contains an object that represents a Telegram Bot with convenience extensions."""
from collections.abc import Sequence
from copy import copy
from datetime import datetime
from datetime import datetime, timedelta
from typing import (
TYPE_CHECKING,
Any,
Expand DownExpand Up@@ -1171,6 +1171,8 @@ async def create_invoice_link(
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: 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,
write_timeout: ODVInput[float] = DEFAULT_NONE,
Expand DownExpand Up@@ -1204,6 +1206,8 @@ async def create_invoice_link(
write_timeout=write_timeout,
connect_timeout=connect_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),
)

Expand Down
11 changes: 9 additions & 2 deletionstests/_payment/test_invoice.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
import asyncio
import datetime as dtm

import pytest

Expand DownExpand Up@@ -122,10 +123,14 @@ async def make_assertion(*args, **_):
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, **_):
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)
assert await offline_bot.create_invoice_link(
Expand All@@ -149,6 +154,8 @@ async def make_assertion(*args, **_):
send_phone_number_to_provider="send_phone_number_to_provider",
send_email_to_provider="send_email_to_provider",
is_flexible="is_flexible",
business_connection_id="business_connection_id",
subscription_period=subscription_period,
)

async def test_send_object_as_provider_data(
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp