diff --git a/docs/source/inclusions/bot_methods.rst b/docs/source/inclusions/bot_methods.rst
index 3189de1c1d3..d1737c5b639 100644
--- a/docs/source/inclusions/bot_methods.rst
+++ b/docs/source/inclusions/bot_methods.rst
@@ -355,7 +355,7 @@
.. raw:: html
- Miscellaneous
+ Payments and Stars
.. list-table::
:align: left
@@ -363,6 +363,27 @@
* - :meth:`~telegram.Bot.create_invoice_link`
- Used to generate an HTTP link for an invoice
+ * - :meth:`~telegram.Bot.edit_user_star_subscription`
+ - Used for editing a user's star subscription
+ * - :meth:`~telegram.Bot.get_star_transactions`
+ - Used for obtaining the bot's Telegram Stars transactions
+ * - :meth:`~telegram.Bot.refund_star_payment`
+ - Used for refunding a payment in Telegram Stars
+
+.. raw:: html
+
+
+
+
+.. raw:: html
+
+
+ Miscellaneous
+
+.. list-table::
+ :align: left
+ :widths: 1 4
+
* - :meth:`~telegram.Bot.close`
- Used for closing server instance when switching to another local server
* - :meth:`~telegram.Bot.log_out`
@@ -371,10 +392,6 @@
- Used for getting basic info about a file
* - :meth:`~telegram.Bot.get_me`
- Used for getting basic information about the bot
- * - :meth:`~telegram.Bot.get_star_transactions`
- - Used for obtaining the bot's Telegram Stars transactions
- * - :meth:`~telegram.Bot.refund_star_payment`
- - Used for refunding a payment in Telegram Stars
.. raw:: html
diff --git a/telegram/_bot.py b/telegram/_bot.py
index cc2ba38fb3a..eb91daf1e29 100644
--- a/telegram/_bot.py
+++ b/telegram/_bot.py
@@ -9254,6 +9254,53 @@ async def get_star_transactions(
bot=self,
)
+ async def edit_user_star_subscription(
+ self,
+ user_id: int,
+ telegram_payment_charge_id: str,
+ is_canceled: bool,
+ *,
+ read_timeout: ODVInput[float] = DEFAULT_NONE,
+ write_timeout: ODVInput[float] = DEFAULT_NONE,
+ connect_timeout: ODVInput[float] = DEFAULT_NONE,
+ pool_timeout: ODVInput[float] = DEFAULT_NONE,
+ api_kwargs: Optional[JSONDict] = None,
+ ) -> bool:
+ """Allows the bot to cancel or re-enable extension of a subscription paid in Telegram
+ Stars.
+
+ .. versionadded:: NEXT.VERSION
+
+ Args:
+ user_id (:obj:`int`): Identifier of the user whose subscription will be edited.
+ telegram_payment_charge_id (:obj:`str`): Telegram payment identifier for the
+ subscription.
+ is_canceled (:obj:`bool`): Pass :obj:`True` to cancel extension of the user
+ subscription; the subscription must be active up to the end of the current
+ subscription period. Pass :obj:`False` to allow the user to re-enable a
+ subscription that was previously canceled by the bot.
+
+ Returns:
+ :obj:`bool`: On success, :obj:`True` is returned.
+
+ Raises:
+ :class:`telegram.error.TelegramError`
+ """
+ data: JSONDict = {
+ "user_id": user_id,
+ "telegram_payment_charge_id": telegram_payment_charge_id,
+ "is_canceled": is_canceled,
+ }
+ return await self._post(
+ "editUserStartSubscription",
+ data,
+ read_timeout=read_timeout,
+ write_timeout=write_timeout,
+ connect_timeout=connect_timeout,
+ pool_timeout=pool_timeout,
+ api_kwargs=api_kwargs,
+ )
+
async def send_paid_media(
self,
chat_id: Union[str, int],
@@ -9729,6 +9776,8 @@ def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002
"""Alias for :meth:`refund_star_payment`"""
getStarTransactions = get_star_transactions
"""Alias for :meth:`get_star_transactions`"""
+ editUserStarSubscription = edit_user_star_subscription
+ """Alias for :meth:`edit_user_star_subscription`"""
sendPaidMedia = send_paid_media
"""Alias for :meth:`send_paid_media`"""
createChatSubscriptionInviteLink = create_chat_subscription_invite_link
diff --git a/telegram/ext/_extbot.py b/telegram/ext/_extbot.py
index 66921e415df..d9844cbdd0b 100644
--- a/telegram/ext/_extbot.py
+++ b/telegram/ext/_extbot.py
@@ -4255,6 +4255,30 @@ async def get_star_transactions(
api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args),
)
+ async def edit_user_star_subscription(
+ self,
+ user_id: int,
+ telegram_payment_charge_id: str,
+ is_canceled: bool,
+ *,
+ read_timeout: ODVInput[float] = DEFAULT_NONE,
+ write_timeout: ODVInput[float] = DEFAULT_NONE,
+ connect_timeout: ODVInput[float] = DEFAULT_NONE,
+ pool_timeout: ODVInput[float] = DEFAULT_NONE,
+ api_kwargs: Optional[JSONDict] = None,
+ rate_limit_args: Optional[RLARGS] = None,
+ ) -> bool:
+ return await super().edit_user_star_subscription(
+ user_id=user_id,
+ telegram_payment_charge_id=telegram_payment_charge_id,
+ is_canceled=is_canceled,
+ read_timeout=read_timeout,
+ write_timeout=write_timeout,
+ connect_timeout=connect_timeout,
+ pool_timeout=pool_timeout,
+ api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args),
+ )
+
async def send_paid_media(
self,
chat_id: Union[str, int],
@@ -4478,6 +4502,7 @@ async def edit_chat_subscription_invite_link(
replaceStickerInSet = replace_sticker_in_set
refundStarPayment = refund_star_payment
getStarTransactions = get_star_transactions
+ editUserStarSubscription = edit_user_star_subscription
createChatSubscriptionInviteLink = create_chat_subscription_invite_link
editChatSubscriptionInviteLink = edit_chat_subscription_invite_link
sendPaidMedia = send_paid_media
diff --git a/tests/test_bot.py b/tests/test_bot.py
index 8ff0dec8d7b..f981f609a70 100644
--- a/tests/test_bot.py
+++ b/tests/test_bot.py
@@ -2321,6 +2321,22 @@ async def do_request(url, request_data: RequestData, *args, **kwargs):
obj = await offline_bot.get_star_transactions(offset=3)
assert isinstance(obj, StarTransactions)
+ async def test_edit_user_star_subscription(self, offline_bot, monkeypatch):
+ """Can't properly test, so we only check that the correct values are passed"""
+
+ async def make_assertion(url, request_data: RequestData, *args, **kwargs):
+ return (
+ request_data.parameters.get("user_id") == 42
+ and request_data.parameters.get("telegram_payment_charge_id")
+ == "telegram_payment_charge_id"
+ and request_data.parameters.get("is_canceled") is False
+ )
+
+ monkeypatch.setattr(offline_bot.request, "post", make_assertion)
+ assert await offline_bot.edit_user_star_subscription(
+ 42, "telegram_payment_charge_id", False
+ )
+
async def test_create_chat_subscription_invite_link(
self,
monkeypatch,