Skip to content

API 7.4 - refund_star_payment #4280

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions docs/source/inclusions/bot_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@
- Used for getting basic info about a file
* - :meth:`~telegram.Bot.get_me`
- Used for getting basic information about the bot
* - :meth:`~telegram.Bot.refund_star_payment`
- Used for refunding a payment in Telegram Stars

.. raw:: html

Expand Down
43 changes: 43 additions & 0 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9011,6 +9011,47 @@ async def replace_sticker_in_set(
api_kwargs=api_kwargs,
)

async def refund_star_payment(
self,
user_id: int,
telegram_payment_charge_id: str,
*,
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:
"""Refunds a successful payment in `Telegram Stars <https://t.me/BotNews/90>`.

.. versionadded:: NEXT.VERSION

Args:
user_id (:obj:`int`): User identifier of the user whose payment will be refunded.
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier.

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

return await self._post(
"refundStarPayment",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002
"""See :meth:`telegram.TelegramObject.to_dict`."""
data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name}
Expand Down Expand Up @@ -9261,3 +9302,5 @@ def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002
"""Alias for :meth:`get_business_connection`"""
replaceStickerInSet = replace_sticker_in_set
"""Alias for :meth:`replace_sticker_in_set`"""
refundStarPayment = refund_star_payment
"""Alias for :meth:`refund_star_payment`"""
32 changes: 32 additions & 0 deletions telegram/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,3 +2145,35 @@ async def get_chat_boosts(
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

async def refund_star_payment(
self,
telegram_payment_charge_id: str,
*,
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:
"""Shortcut for::

await bot.refund_star_payment(user_id=update.effective_user.id, *args, **kwargs)

For the documentation of the arguments, please see
:meth:`telegram.Bot.refund_star_payment`.

.. versionadded:: NEXT.VERSION

Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return await self.get_bot().refund_star_payment(
user_id=self.id,
telegram_payment_charge_id=telegram_payment_charge_id,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
23 changes: 23 additions & 0 deletions telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4157,6 +4157,28 @@ async def replace_sticker_in_set(
api_kwargs=self._merge_api_rl_kwargs(api_kwargs, rate_limit_args),
)

async def refund_star_payment(
self,
user_id: int,
telegram_payment_charge_id: str,
*,
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().refund_star_payment(
user_id=user_id,
telegram_payment_charge_id=telegram_payment_charge_id,
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),
)

# updated camelCase aliases
getMe = get_me
sendMessage = send_message
Expand Down Expand Up @@ -4278,3 +4300,4 @@ async def replace_sticker_in_set(
setMessageReaction = set_message_reaction
getBusinessConnection = get_business_connection
replaceStickerInSet = replace_sticker_in_set
refundStarPayment = refund_star_payment
11 changes: 11 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,17 @@ async def do_request(*args, **kwargs):
obj = await bot.get_business_connection(business_connection_id=bci)
assert isinstance(obj, BusinessConnection)

async def test_refund_star_payment(self, bot, monkeypatch):
# can't make actual request so we just test that the correct data is 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") == "37"
)

monkeypatch.setattr(bot.request, "post", make_assertion)
assert await bot.refund_star_payment(42, "37")


class TestBotWithRequest:
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,18 @@ async def make_assertion(*_, **kwargs):

monkeypatch.setattr(user.get_bot(), "forward_messages", make_assertion)
assert await user.forward_messages_to(chat_id="test_forwards", message_ids=(42, 43))

async def test_instance_method_refund_star_payment(self, monkeypatch, user):
async def make_assertion(*_, **kwargs):
return kwargs["user_id"] == user.id and kwargs["telegram_payment_charge_id"] == 42

assert check_shortcut_signature(
user.refund_star_payment, Bot.refund_star_payment, ["user_id"], []
)
assert await check_shortcut_call(
user.refund_star_payment, user.get_bot(), "refund_star_payment"
)
assert await check_defaults_handling(user.refund_star_payment, user.get_bot())

monkeypatch.setattr(user.get_bot(), "refund_star_payment", make_assertion)
assert await user.refund_star_payment(telegram_payment_charge_id=42)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy