diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index c5aaef30..f6479d74 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -550,6 +550,7 @@ def pyrogram_api(): BotApp BotBusinessConnection PaymentInfo + PaymentRefunded ShippingAddress ShippingOption ShippingQuery diff --git a/pyrogram/enums/message_service_type.py b/pyrogram/enums/message_service_type.py index d89cedde..5c7b9942 100644 --- a/pyrogram/enums/message_service_type.py +++ b/pyrogram/enums/message_service_type.py @@ -115,5 +115,8 @@ class MessageServiceType(AutoName): SUCCESSFUL_PAYMENT = auto() "Successful payment" + PAYMENT_REFUNDED = auto() + "Payment refunded" + BOT_ALLOWED = auto() "Bot allowed" \ No newline at end of file diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index 70d2c703..5286ba28 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -45,6 +45,7 @@ from .menu_button_commands import MenuButtonCommands from .menu_button_default import MenuButtonDefault from .menu_button_web_app import MenuButtonWebApp from .payment_info import PaymentInfo +from .payment_refunded import PaymentRefunded from .pre_checkout_query import PreCheckoutQuery from .reply_keyboard_markup import ReplyKeyboardMarkup from .reply_keyboard_remove import ReplyKeyboardRemove @@ -97,6 +98,7 @@ __all__ = [ "ShippingOption", "ShippingQuery", "PaymentInfo", + "PaymentRefunded", "PreCheckoutQuery", "SuccessfulPayment" ] diff --git a/pyrogram/types/bots_and_keyboards/payment_refunded.py b/pyrogram/types/bots_and_keyboards/payment_refunded.py new file mode 100644 index 00000000..91056166 --- /dev/null +++ b/pyrogram/types/bots_and_keyboards/payment_refunded.py @@ -0,0 +1,82 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrofork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrofork. If not, see . + +import pyrogram + +from pyrogram import raw +from pyrogram import types +from ..object import Object + + +class PaymentRefunded(Object): + """Contains information about a refunded payment. + + Parameters: + user (:obj:`~pyrogram.types.User`): + The user that refunded the payment. + + currency (``str``): + Three-letter ISO 4217 currency code. + + total_amount (``int``): + Total price in the smallest units of the currency. + + payload (``str``, *optional*): + Bot specified invoice payload. Only available to the bot that received the payment. + + telegram_payment_charge_id (``str``, *optional*): + Telegram payment identifier. + + provider_payment_charge_id (``str``, *optional*): + Provider payment identifier. + """ + + def __init__( + self, *, + user: "types.User", + currency: str, + total_amount: str, + telegram_payment_charge_id: str, + provider_payment_charge_id: str, + payload: str = None + ): + self.user = user + self.currency = currency + self.total_amount = total_amount + self.telegram_payment_charge_id = telegram_payment_charge_id + self.provider_payment_charge_id = provider_payment_charge_id + self.payload = payload + + @staticmethod + async def _parse( + client: "pyrogram.Client", + payment_refunded: "raw.types.MessageActionPaymentRefunded" + ) -> "PaymentRefunded": + try: + payload = payment_refunded.payload.decode() + except (UnicodeDecodeError, AttributeError): + payload = payment_refunded.payload + + return PaymentRefunded( + user=await client.get_users(payment_refunded.peer.user_id), + currency=payment_refunded.currency, + total_amount=payment_refunded.total_amount, + telegram_payment_charge_id=payment_refunded.charge.id if payment_refunded.charge.id != "" else None, + provider_payment_charge_id=payment_refunded.charge.provider_charge_id if payment_refunded.charge.provider_charge_id != "" else None, + payload=payload + ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index c18fefca..f1b56b37 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -395,6 +395,9 @@ class Message(Object, Update): successful_payment (:obj:`~pyrogram.types.SuccessfulPayment`, *optional*): Service message: successful payment. + payment_refunded (:obj:`~pyrogram.types.PaymentRefunded`, *optional*): + Service message: payment refunded. + boosts_applied (``int``, *optional*): Service message: how many boosts were applied. @@ -424,7 +427,7 @@ class Message(Object, Update): Message is a scheduled message and has been sent. """ - # TODO: Add game missing field. Also invoice, successful_payment, connected_website + # TODO: Add game missing field, Also connected_website def __init__( self, @@ -530,6 +533,7 @@ class Message(Object, Update): video_chat_members_invited: "types.VideoChatMembersInvited" = None, web_app_data: "types.WebAppData" = None, successful_payment: "types.SuccessfulPayment" = None, + payment_refunded: "types.PaymentRefunded" = None, reply_markup: Union[ "types.InlineKeyboardMarkup", "types.ReplyKeyboardMarkup", @@ -642,6 +646,7 @@ class Message(Object, Update): self.video_chat_members_invited = video_chat_members_invited self.web_app_data = web_app_data self.successful_payment = successful_payment + self.payment_refunded = payment_refunded self.reactions = reactions self.raw = raw @@ -749,6 +754,7 @@ class Message(Object, Update): giveaway_launched = None giveaway_result = None successful_payment = None + payment_refunded = None boosts_applied = None service_type = None @@ -856,6 +862,9 @@ class Message(Object, Update): elif isinstance(action, (raw.types.MessageActionPaymentSent, raw.types.MessageActionPaymentSentMe)): successful_payment = types.SuccessfulPayment._parse(client, action) service_type = enums.MessageServiceType.SUCCESSFUL_PAYMENT + elif isinstance(action, raw.types.MessageActionPaymentRefunded): + payment_refunded = await types.PaymentRefunded._parse(client, action) + service_type = enums.MessageServiceType.PAYMENT_REFUNDED parsed_message = Message( id=message.id, @@ -894,6 +903,7 @@ class Message(Object, Update): giveaway_launched=giveaway_launched, giveaway_result=giveaway_result, successful_payment=successful_payment, + payment_refunded=payment_refunded, boosts_applied=boosts_applied, raw=message, client=client