mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Add PaymentRefunded
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
de5d2e747b
commit
918a55de3b
5 changed files with 99 additions and 1 deletions
|
|
@ -550,6 +550,7 @@ def pyrogram_api():
|
||||||
BotApp
|
BotApp
|
||||||
BotBusinessConnection
|
BotBusinessConnection
|
||||||
PaymentInfo
|
PaymentInfo
|
||||||
|
PaymentRefunded
|
||||||
ShippingAddress
|
ShippingAddress
|
||||||
ShippingOption
|
ShippingOption
|
||||||
ShippingQuery
|
ShippingQuery
|
||||||
|
|
|
||||||
|
|
@ -115,5 +115,8 @@ class MessageServiceType(AutoName):
|
||||||
SUCCESSFUL_PAYMENT = auto()
|
SUCCESSFUL_PAYMENT = auto()
|
||||||
"Successful payment"
|
"Successful payment"
|
||||||
|
|
||||||
|
PAYMENT_REFUNDED = auto()
|
||||||
|
"Payment refunded"
|
||||||
|
|
||||||
BOT_ALLOWED = auto()
|
BOT_ALLOWED = auto()
|
||||||
"Bot allowed"
|
"Bot allowed"
|
||||||
|
|
@ -45,6 +45,7 @@ from .menu_button_commands import MenuButtonCommands
|
||||||
from .menu_button_default import MenuButtonDefault
|
from .menu_button_default import MenuButtonDefault
|
||||||
from .menu_button_web_app import MenuButtonWebApp
|
from .menu_button_web_app import MenuButtonWebApp
|
||||||
from .payment_info import PaymentInfo
|
from .payment_info import PaymentInfo
|
||||||
|
from .payment_refunded import PaymentRefunded
|
||||||
from .pre_checkout_query import PreCheckoutQuery
|
from .pre_checkout_query import PreCheckoutQuery
|
||||||
from .reply_keyboard_markup import ReplyKeyboardMarkup
|
from .reply_keyboard_markup import ReplyKeyboardMarkup
|
||||||
from .reply_keyboard_remove import ReplyKeyboardRemove
|
from .reply_keyboard_remove import ReplyKeyboardRemove
|
||||||
|
|
@ -97,6 +98,7 @@ __all__ = [
|
||||||
"ShippingOption",
|
"ShippingOption",
|
||||||
"ShippingQuery",
|
"ShippingQuery",
|
||||||
"PaymentInfo",
|
"PaymentInfo",
|
||||||
|
"PaymentRefunded",
|
||||||
"PreCheckoutQuery",
|
"PreCheckoutQuery",
|
||||||
"SuccessfulPayment"
|
"SuccessfulPayment"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
82
pyrogram/types/bots_and_keyboards/payment_refunded.py
Normal file
82
pyrogram/types/bots_and_keyboards/payment_refunded.py
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
@ -395,6 +395,9 @@ class Message(Object, Update):
|
||||||
successful_payment (:obj:`~pyrogram.types.SuccessfulPayment`, *optional*):
|
successful_payment (:obj:`~pyrogram.types.SuccessfulPayment`, *optional*):
|
||||||
Service message: successful payment.
|
Service message: successful payment.
|
||||||
|
|
||||||
|
payment_refunded (:obj:`~pyrogram.types.PaymentRefunded`, *optional*):
|
||||||
|
Service message: payment refunded.
|
||||||
|
|
||||||
boosts_applied (``int``, *optional*):
|
boosts_applied (``int``, *optional*):
|
||||||
Service message: how many boosts were applied.
|
Service message: how many boosts were applied.
|
||||||
|
|
||||||
|
|
@ -424,7 +427,7 @@ class Message(Object, Update):
|
||||||
Message is a scheduled message and has been sent.
|
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__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
@ -530,6 +533,7 @@ class Message(Object, Update):
|
||||||
video_chat_members_invited: "types.VideoChatMembersInvited" = None,
|
video_chat_members_invited: "types.VideoChatMembersInvited" = None,
|
||||||
web_app_data: "types.WebAppData" = None,
|
web_app_data: "types.WebAppData" = None,
|
||||||
successful_payment: "types.SuccessfulPayment" = None,
|
successful_payment: "types.SuccessfulPayment" = None,
|
||||||
|
payment_refunded: "types.PaymentRefunded" = None,
|
||||||
reply_markup: Union[
|
reply_markup: Union[
|
||||||
"types.InlineKeyboardMarkup",
|
"types.InlineKeyboardMarkup",
|
||||||
"types.ReplyKeyboardMarkup",
|
"types.ReplyKeyboardMarkup",
|
||||||
|
|
@ -642,6 +646,7 @@ class Message(Object, Update):
|
||||||
self.video_chat_members_invited = video_chat_members_invited
|
self.video_chat_members_invited = video_chat_members_invited
|
||||||
self.web_app_data = web_app_data
|
self.web_app_data = web_app_data
|
||||||
self.successful_payment = successful_payment
|
self.successful_payment = successful_payment
|
||||||
|
self.payment_refunded = payment_refunded
|
||||||
self.reactions = reactions
|
self.reactions = reactions
|
||||||
self.raw = raw
|
self.raw = raw
|
||||||
|
|
||||||
|
|
@ -749,6 +754,7 @@ class Message(Object, Update):
|
||||||
giveaway_launched = None
|
giveaway_launched = None
|
||||||
giveaway_result = None
|
giveaway_result = None
|
||||||
successful_payment = None
|
successful_payment = None
|
||||||
|
payment_refunded = None
|
||||||
boosts_applied = None
|
boosts_applied = None
|
||||||
|
|
||||||
service_type = None
|
service_type = None
|
||||||
|
|
@ -856,6 +862,9 @@ class Message(Object, Update):
|
||||||
elif isinstance(action, (raw.types.MessageActionPaymentSent, raw.types.MessageActionPaymentSentMe)):
|
elif isinstance(action, (raw.types.MessageActionPaymentSent, raw.types.MessageActionPaymentSentMe)):
|
||||||
successful_payment = types.SuccessfulPayment._parse(client, action)
|
successful_payment = types.SuccessfulPayment._parse(client, action)
|
||||||
service_type = enums.MessageServiceType.SUCCESSFUL_PAYMENT
|
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(
|
parsed_message = Message(
|
||||||
id=message.id,
|
id=message.id,
|
||||||
|
|
@ -894,6 +903,7 @@ class Message(Object, Update):
|
||||||
giveaway_launched=giveaway_launched,
|
giveaway_launched=giveaway_launched,
|
||||||
giveaway_result=giveaway_result,
|
giveaway_result=giveaway_result,
|
||||||
successful_payment=successful_payment,
|
successful_payment=successful_payment,
|
||||||
|
payment_refunded=payment_refunded,
|
||||||
boosts_applied=boosts_applied,
|
boosts_applied=boosts_applied,
|
||||||
raw=message,
|
raw=message,
|
||||||
client=client
|
client=client
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue