Skip to content

Commit 24c12e2

Browse files
committed
Fix subscription_period in create_invoice_link
Closes #135
1 parent 887f221 commit 24c12e2

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ STORY_NOT_MODIFIED The new story information you passed is equal to the previous
464464
STORY_PERIOD_INVALID The specified story period is invalid for this account.
465465
STORY_SEND_FLOOD_MONTHLY_X You've hit the monthly story limit as specified by the [`stories_sent_monthly_limit_*` client configuration parameters](https://core.telegram.org/api/config#stories-sent-monthly-limit-default): wait for the specified number of seconds before posting a new story.
466466
STORY_SEND_FLOOD_WEEKLY_X You've hit the weekly story limit as specified by the [`stories_sent_weekly_limit_*` client configuration parameters](https://core.telegram.org/api/config#stories-sent-weekly-limit-default): wait for the specified number of seconds before posting a new story.
467+
SUBSCRIPTION_PERIOD_INVALID The subscription period is invalid.
467468
SWITCH_PM_TEXT_EMPTY The switch_pm.text field was empty.
468469
SWITCH_WEBVIEW_URL_INVALID The URL specified in switch_webview.url is invalid!
469470
TAKEOUT_INVALID The takeout id is invalid

pyrogram/methods/business/create_invoice_link.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import logging
20-
from datetime import datetime
20+
from datetime import timedelta
2121
from typing import Optional, Union
2222

2323
import pyrogram
24-
from pyrogram import enums, raw, utils, types
24+
from pyrogram import raw, types
2525

2626
log = logging.getLogger(__name__)
2727

@@ -34,23 +34,23 @@ async def create_invoice_link(
3434
payload: Union[str, bytes],
3535
currency: str,
3636
prices: list["types.LabeledPrice"],
37-
provider_token: str = None,
38-
subscription_period: datetime = None,
39-
max_tip_amount: int = None,
40-
suggested_tip_amounts: list[int] = None,
41-
start_parameter: str = None,
42-
provider_data: str = None,
43-
photo_url: str = None,
44-
photo_size: int = None,
45-
photo_width: int = None,
46-
photo_height: int = None,
47-
need_name: bool = None,
48-
need_phone_number: bool = None,
49-
need_email: bool = None,
50-
need_shipping_address: bool = None,
51-
send_phone_number_to_provider: bool = None,
52-
send_email_to_provider: bool = None,
53-
is_flexible: bool = None
37+
provider_token: Optional[str] = None,
38+
subscription_period: Optional[Union[int, timedelta]] = None,
39+
max_tip_amount: Optional[int] = None,
40+
suggested_tip_amounts: Optional[list[int]] = None,
41+
start_parameter: Optional[str] = None,
42+
provider_data: Optional[str] = None,
43+
photo_url: Optional[str] = None,
44+
photo_size: Optional[int] = None,
45+
photo_width: Optional[int] = None,
46+
photo_height: Optional[int] = None,
47+
need_name: Optional[bool] = None,
48+
need_phone_number: Optional[bool] = None,
49+
need_email: Optional[bool] = None,
50+
need_shipping_address: Optional[bool] = None,
51+
send_phone_number_to_provider: Optional[bool] = None,
52+
send_email_to_provider: Optional[bool] = None,
53+
is_flexible: Optional[bool] = None
5454
) -> str:
5555
"""Use this method to create a link for an invoice.
5656
@@ -75,7 +75,7 @@ async def create_invoice_link(
7575
provider_token (``str``, *optional*):
7676
Payment provider token, obtained via `@BotFather <https://t.me/botfather>`_. Pass an empty string for payments in `Telegram Stars <https://t.me/BotNews/90>`_.
7777
78-
subscription_period (:py:obj:`~datetime.datetime`, *optional*):
78+
subscription_period (``int`` | :py:obj:`~datetime.timedelta`, *optional*):
7979
The number of seconds the subscription will be active for before the next payment. The currency must be set to "XTR" (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must no exceed ``stars_paid_post_amount_max`` Telegram Stars.
8080
8181
max_tip_amount (``int``, *optional*):
@@ -154,7 +154,11 @@ async def create_invoice_link(
154154
flexible=is_flexible,
155155
phone_to_provider=send_phone_number_to_provider,
156156
email_to_provider=send_email_to_provider,
157-
subscription_period=utils.datetime_to_timestamp(subscription_period)
157+
subscription_period=int(
158+
subscription_period.total_seconds()
159+
if isinstance(subscription_period, timedelta)
160+
else subscription_period
161+
)
158162
),
159163
payload=payload.encode() if isinstance(payload, str) else payload,
160164
provider=provider_token,

0 commit comments

Comments
 (0)