This commit is contained in:
134
.venv/lib/python3.12/site-packages/telegram/_payment/invoice.py
Normal file
134
.venv/lib/python3.12/site-packages/telegram/_payment/invoice.py
Normal file
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram Invoice."""
|
||||
|
||||
from typing import Final, Optional
|
||||
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class Invoice(TelegramObject):
|
||||
"""This object contains basic information about an invoice.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`title`, :attr:`description`, :paramref:`start_parameter`,
|
||||
:attr:`currency` and :attr:`total_amount` are equal.
|
||||
|
||||
Args:
|
||||
title (:obj:`str`): Product name.
|
||||
description (:obj:`str`): Product description.
|
||||
start_parameter (:obj:`str`): Unique bot deep-linking parameter that can be used to
|
||||
generate this invoice.
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, or ``XTR`` for payments in
|
||||
|tg_stars|.
|
||||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
|
||||
Attributes:
|
||||
title (:obj:`str`): Product name.
|
||||
description (:obj:`str`): Product description.
|
||||
start_parameter (:obj:`str`): Unique bot deep-linking parameter that can be used to
|
||||
generate this invoice.
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, or ``XTR`` for payments in
|
||||
|tg_stars|.
|
||||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"currency",
|
||||
"description",
|
||||
"start_parameter",
|
||||
"title",
|
||||
"total_amount",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
description: str,
|
||||
start_parameter: str,
|
||||
currency: str,
|
||||
total_amount: int,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.title: str = title
|
||||
self.description: str = description
|
||||
self.start_parameter: str = start_parameter
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
|
||||
self._id_attrs = (
|
||||
self.title,
|
||||
self.description,
|
||||
self.start_parameter,
|
||||
self.currency,
|
||||
self.total_amount,
|
||||
)
|
||||
|
||||
self._freeze()
|
||||
|
||||
MIN_TITLE_LENGTH: Final[int] = constants.InvoiceLimit.MIN_TITLE_LENGTH
|
||||
""":const:`telegram.constants.InvoiceLimit.MIN_TITLE_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_TITLE_LENGTH: Final[int] = constants.InvoiceLimit.MAX_TITLE_LENGTH
|
||||
""":const:`telegram.constants.InvoiceLimit.MAX_TITLE_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_DESCRIPTION_LENGTH: Final[int] = constants.InvoiceLimit.MIN_DESCRIPTION_LENGTH
|
||||
""":const:`telegram.constants.InvoiceLimit.MIN_DESCRIPTION_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_DESCRIPTION_LENGTH: Final[int] = constants.InvoiceLimit.MAX_DESCRIPTION_LENGTH
|
||||
""":const:`telegram.constants.InvoiceLimit.MAX_DESCRIPTION_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_PAYLOAD_LENGTH: Final[int] = constants.InvoiceLimit.MIN_PAYLOAD_LENGTH
|
||||
""":const:`telegram.constants.InvoiceLimit.MIN_PAYLOAD_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_PAYLOAD_LENGTH: Final[int] = constants.InvoiceLimit.MAX_PAYLOAD_LENGTH
|
||||
""":const:`telegram.constants.InvoiceLimit.MAX_PAYLOAD_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_TIP_AMOUNTS: Final[int] = constants.InvoiceLimit.MAX_TIP_AMOUNTS
|
||||
""":const:`telegram.constants.InvoiceLimit.MAX_TIP_AMOUNTS`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram LabeledPrice."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class LabeledPrice(TelegramObject):
|
||||
"""This object represents a portion of the price for goods or services.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`label` and :attr:`amount` are equal.
|
||||
|
||||
Examples:
|
||||
:any:`Payment Bot <examples.paymentbot>`
|
||||
|
||||
Args:
|
||||
label (:obj:`str`): Portion label.
|
||||
amount (:obj:`int`): Price of the product in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
|
||||
Attributes:
|
||||
label (:obj:`str`): Portion label.
|
||||
amount (:obj:`int`): Price of the product in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("amount", "label")
|
||||
|
||||
def __init__(self, label: str, amount: int, *, api_kwargs: Optional[JSONDict] = None):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.label: str = label
|
||||
self.amount: int = amount
|
||||
|
||||
self._id_attrs = (self.label, self.amount)
|
||||
|
||||
self._freeze()
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram OrderInfo."""
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._payment.shippingaddress import ShippingAddress
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class OrderInfo(TelegramObject):
|
||||
"""This object represents information about an order.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`name`, :attr:`phone_number`, :attr:`email` and
|
||||
:attr:`shipping_address` are equal.
|
||||
|
||||
Args:
|
||||
name (:obj:`str`, optional): User name.
|
||||
phone_number (:obj:`str`, optional): User's phone number.
|
||||
email (:obj:`str`, optional): User email.
|
||||
shipping_address (:class:`telegram.ShippingAddress`, optional): User shipping address.
|
||||
|
||||
Attributes:
|
||||
name (:obj:`str`): Optional. User name.
|
||||
phone_number (:obj:`str`): Optional. User's phone number.
|
||||
email (:obj:`str`): Optional. User email.
|
||||
shipping_address (:class:`telegram.ShippingAddress`): Optional. User shipping address.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("email", "name", "phone_number", "shipping_address")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: Optional[str] = None,
|
||||
phone_number: Optional[str] = None,
|
||||
email: Optional[str] = None,
|
||||
shipping_address: Optional[ShippingAddress] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.name: Optional[str] = name
|
||||
self.phone_number: Optional[str] = phone_number
|
||||
self.email: Optional[str] = email
|
||||
self.shipping_address: Optional[ShippingAddress] = shipping_address
|
||||
|
||||
self._id_attrs = (self.name, self.phone_number, self.email, self.shipping_address)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "OrderInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["shipping_address"] = de_json_optional(
|
||||
data.get("shipping_address"), ShippingAddress, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram PreCheckoutQuery."""
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._payment.orderinfo import OrderInfo
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class PreCheckoutQuery(TelegramObject):
|
||||
"""This object contains information about an incoming pre-checkout query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id` is equal.
|
||||
|
||||
Note:
|
||||
In Python :keyword:`from` is a reserved word. Use :paramref:`from_user` instead.
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique query identifier.
|
||||
from_user (:class:`telegram.User`): User who sent the query.
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, or ``XTR`` for payments in
|
||||
|tg_stars|.
|
||||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
shipping_option_id (:obj:`str`, optional): Identifier of the shipping option chosen by the
|
||||
user.
|
||||
order_info (:class:`telegram.OrderInfo`, optional): Order info provided by the user.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Unique query identifier.
|
||||
from_user (:class:`telegram.User`): User who sent the query.
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, or ``XTR`` for payments in
|
||||
|tg_stars|.
|
||||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
shipping_option_id (:obj:`str`): Optional. Identifier of the shipping option chosen by the
|
||||
user.
|
||||
order_info (:class:`telegram.OrderInfo`): Optional. Order info provided by the user.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"currency",
|
||||
"from_user",
|
||||
"id",
|
||||
"invoice_payload",
|
||||
"order_info",
|
||||
"shipping_option_id",
|
||||
"total_amount",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
from_user: User,
|
||||
currency: str,
|
||||
total_amount: int,
|
||||
invoice_payload: str,
|
||||
shipping_option_id: Optional[str] = None,
|
||||
order_info: Optional[OrderInfo] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.id: str = id
|
||||
self.from_user: User = from_user
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.shipping_option_id: Optional[str] = shipping_option_id
|
||||
self.order_info: Optional[OrderInfo] = order_info
|
||||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "PreCheckoutQuery":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["order_info"] = de_json_optional(data.get("order_info"), OrderInfo, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def answer(
|
||||
self,
|
||||
ok: bool,
|
||||
error_message: Optional[str] = None,
|
||||
*,
|
||||
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.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.answer_pre_checkout_query`.
|
||||
|
||||
"""
|
||||
return await self.get_bot().answer_pre_checkout_query(
|
||||
pre_checkout_query_id=self.id,
|
||||
ok=ok,
|
||||
error_message=error_message,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram RefundedPayment."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class RefundedPayment(TelegramObject):
|
||||
"""This object contains basic information about a refunded payment.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`telegram_payment_charge_id` is equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Args:
|
||||
currency (:obj:`str`): Three-letter ISO 4217 `currency
|
||||
<https://core.telegram.org/bots/payments#supported-currencies>`_ code, or ``XTR`` for
|
||||
payments in |tg_stars|. Currently, always ``XTR``.
|
||||
total_amount (:obj:`int`): Total refunded price in the *smallest units* of the currency
|
||||
(integer, **not** float/double). For example, for a price of ``US$ 1.45``,
|
||||
``total_amount = 145``. See the *exp* parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier.
|
||||
provider_payment_charge_id (:obj:`str`, optional): Provider payment identifier.
|
||||
|
||||
Attributes:
|
||||
currency (:obj:`str`): Three-letter ISO 4217 `currency
|
||||
<https://core.telegram.org/bots/payments#supported-currencies>`_ code, or ``XTR`` for
|
||||
payments in |tg_stars|. Currently, always ``XTR``.
|
||||
total_amount (:obj:`int`): Total refunded price in the *smallest units* of the currency
|
||||
(integer, **not** float/double). For example, for a price of ``US$ 1.45``,
|
||||
``total_amount = 145``. See the *exp* parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier.
|
||||
provider_payment_charge_id (:obj:`str`): Optional. Provider payment identifier.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"currency",
|
||||
"invoice_payload",
|
||||
"provider_payment_charge_id",
|
||||
"telegram_payment_charge_id",
|
||||
"total_amount",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
currency: str,
|
||||
total_amount: int,
|
||||
invoice_payload: str,
|
||||
telegram_payment_charge_id: str,
|
||||
provider_payment_charge_id: Optional[str] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.telegram_payment_charge_id: str = telegram_payment_charge_id
|
||||
# Optional
|
||||
self.provider_payment_charge_id: Optional[str] = provider_payment_charge_id
|
||||
|
||||
self._id_attrs = (self.telegram_payment_charge_id,)
|
||||
|
||||
self._freeze()
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram ShippingAddress."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class ShippingAddress(TelegramObject):
|
||||
"""This object represents a Telegram ShippingAddress.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`country_code`, :attr:`state`, :attr:`city`,
|
||||
:attr:`street_line1`, :attr:`street_line2` and :attr:`post_code` are equal.
|
||||
|
||||
Args:
|
||||
country_code (:obj:`str`): ISO 3166-1 alpha-2 country code.
|
||||
state (:obj:`str`): State, if applicable.
|
||||
city (:obj:`str`): City.
|
||||
street_line1 (:obj:`str`): First line for the address.
|
||||
street_line2 (:obj:`str`): Second line for the address.
|
||||
post_code (:obj:`str`): Address post code.
|
||||
|
||||
Attributes:
|
||||
country_code (:obj:`str`): ISO 3166-1 alpha-2 country code.
|
||||
state (:obj:`str`): State, if applicable.
|
||||
city (:obj:`str`): City.
|
||||
street_line1 (:obj:`str`): First line for the address.
|
||||
street_line2 (:obj:`str`): Second line for the address.
|
||||
post_code (:obj:`str`): Address post code.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"city",
|
||||
"country_code",
|
||||
"post_code",
|
||||
"state",
|
||||
"street_line1",
|
||||
"street_line2",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
country_code: str,
|
||||
state: str,
|
||||
city: str,
|
||||
street_line1: str,
|
||||
street_line2: str,
|
||||
post_code: str,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.country_code: str = country_code
|
||||
self.state: str = state
|
||||
self.city: str = city
|
||||
self.street_line1: str = street_line1
|
||||
self.street_line2: str = street_line2
|
||||
self.post_code: str = post_code
|
||||
|
||||
self._id_attrs = (
|
||||
self.country_code,
|
||||
self.state,
|
||||
self.city,
|
||||
self.street_line1,
|
||||
self.street_line2,
|
||||
self.post_code,
|
||||
)
|
||||
|
||||
self._freeze()
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram ShippingOption."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import LabeledPrice
|
||||
|
||||
|
||||
class ShippingOption(TelegramObject):
|
||||
"""This object represents one shipping option.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id` is equal.
|
||||
|
||||
Examples:
|
||||
:any:`Payment Bot <examples.paymentbot>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Shipping option identifier.
|
||||
title (:obj:`str`): Option title.
|
||||
prices (Sequence[:class:`telegram.LabeledPrice`]): List of price portions.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Shipping option identifier.
|
||||
title (:obj:`str`): Option title.
|
||||
prices (tuple[:class:`telegram.LabeledPrice`]): List of price portions.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|tupleclassattrs|
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("id", "prices", "title")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
title: str,
|
||||
prices: Sequence["LabeledPrice"],
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
|
||||
self.id: str = id
|
||||
self.title: str = title
|
||||
self.prices: tuple[LabeledPrice, ...] = parse_sequence_arg(prices)
|
||||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram ShippingQuery."""
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._payment.shippingaddress import ShippingAddress
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
from telegram._payment.shippingoption import ShippingOption
|
||||
|
||||
|
||||
class ShippingQuery(TelegramObject):
|
||||
"""This object contains information about an incoming shipping query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id` is equal.
|
||||
|
||||
Note:
|
||||
In Python :keyword:`from` is a reserved word. Use :paramref:`from_user` instead.
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique query identifier.
|
||||
from_user (:class:`telegram.User`): User who sent the query.
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
shipping_address (:class:`telegram.ShippingAddress`): User specified shipping address.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Unique query identifier.
|
||||
from_user (:class:`telegram.User`): User who sent the query.
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
shipping_address (:class:`telegram.ShippingAddress`): User specified shipping address.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("from_user", "id", "invoice_payload", "shipping_address")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
from_user: User,
|
||||
invoice_payload: str,
|
||||
shipping_address: ShippingAddress,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.id: str = id
|
||||
self.from_user: User = from_user
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.shipping_address: ShippingAddress = shipping_address
|
||||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "ShippingQuery":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["shipping_address"] = de_json_optional(
|
||||
data.get("shipping_address"), ShippingAddress, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def answer(
|
||||
self,
|
||||
ok: bool,
|
||||
shipping_options: Optional[Sequence["ShippingOption"]] = None,
|
||||
error_message: Optional[str] = None,
|
||||
*,
|
||||
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.answer_shipping_query(update.shipping_query.id, *args, **kwargs)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.answer_shipping_query`.
|
||||
|
||||
"""
|
||||
return await self.get_bot().answer_shipping_query(
|
||||
shipping_query_id=self.id,
|
||||
ok=ok,
|
||||
shipping_options=shipping_options,
|
||||
error_message=error_message,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains the classes for Telegram Stars affiliates."""
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._chat import Chat
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class AffiliateInfo(TelegramObject):
|
||||
"""Contains information about the affiliate that received a commission via this transaction.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`affiliate_user`, :attr:`affiliate_chat`,
|
||||
:attr:`commission_per_mille`, :attr:`amount`, and :attr:`nanostar_amount` are equal.
|
||||
|
||||
.. versionadded:: 21.9
|
||||
|
||||
Args:
|
||||
affiliate_user (:class:`telegram.User`, optional): The bot or the user that received an
|
||||
affiliate commission if it was received by a bot or a user
|
||||
affiliate_chat (:class:`telegram.Chat`, optional): The chat that received an affiliate
|
||||
commission if it was received by a chat
|
||||
commission_per_mille (:obj:`int`): The number of Telegram Stars received by the affiliate
|
||||
for each 1000 Telegram Stars received by the bot from referred users
|
||||
amount (:obj:`int`): Integer amount of Telegram Stars received by the affiliate from the
|
||||
transaction, rounded to 0; can be negative for refunds
|
||||
nanostar_amount (:obj:`int`, optional): The number of
|
||||
:tg-const:`~telegram.constants.Nanostar.VALUE` shares of Telegram
|
||||
Stars received by the affiliate; from
|
||||
:tg-const:`~telegram.constants.NanostarLimit.MIN_AMOUNT` to
|
||||
:tg-const:`~telegram.constants.NanostarLimit.MAX_AMOUNT`;
|
||||
can be negative for refunds
|
||||
|
||||
Attributes:
|
||||
affiliate_user (:class:`telegram.User`): Optional. The bot or the user that received an
|
||||
affiliate commission if it was received by a bot or a user
|
||||
affiliate_chat (:class:`telegram.Chat`): Optional. The chat that received an affiliate
|
||||
commission if it was received by a chat
|
||||
commission_per_mille (:obj:`int`): The number of Telegram Stars received by the affiliate
|
||||
for each 1000 Telegram Stars received by the bot from referred users
|
||||
amount (:obj:`int`): Integer amount of Telegram Stars received by the affiliate from the
|
||||
transaction, rounded to 0; can be negative for refunds
|
||||
nanostar_amount (:obj:`int`): Optional. The number of
|
||||
:tg-const:`~telegram.constants.Nanostar.VALUE` shares of Telegram
|
||||
Stars received by the affiliate; from
|
||||
:tg-const:`~telegram.constants.NanostarLimit.MIN_AMOUNT` to
|
||||
:tg-const:`~telegram.constants.NanostarLimit.MAX_AMOUNT`;
|
||||
can be negative for refunds
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"affiliate_chat",
|
||||
"affiliate_user",
|
||||
"amount",
|
||||
"commission_per_mille",
|
||||
"nanostar_amount",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
commission_per_mille: int,
|
||||
amount: int,
|
||||
affiliate_user: Optional["User"] = None,
|
||||
affiliate_chat: Optional["Chat"] = None,
|
||||
nanostar_amount: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.affiliate_user: Optional[User] = affiliate_user
|
||||
self.affiliate_chat: Optional[Chat] = affiliate_chat
|
||||
self.commission_per_mille: int = commission_per_mille
|
||||
self.amount: int = amount
|
||||
self.nanostar_amount: Optional[int] = nanostar_amount
|
||||
|
||||
self._id_attrs = (
|
||||
self.affiliate_user,
|
||||
self.affiliate_chat,
|
||||
self.commission_per_mille,
|
||||
self.amount,
|
||||
self.nanostar_amount,
|
||||
)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "AffiliateInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["affiliate_user"] = de_json_optional(data.get("affiliate_user"), User, bot)
|
||||
data["affiliate_chat"] = de_json_optional(data.get("affiliate_chat"), Chat, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
@@ -0,0 +1,180 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
# pylint: disable=redefined-builtin
|
||||
"""This module contains the classes for Telegram Stars Revenue Withdrawals."""
|
||||
import datetime as dtm
|
||||
from typing import TYPE_CHECKING, Final, Optional
|
||||
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class RevenueWithdrawalState(TelegramObject):
|
||||
"""This object describes the state of a revenue withdrawal operation. Currently, it can be one
|
||||
of:
|
||||
|
||||
* :class:`telegram.RevenueWithdrawalStatePending`
|
||||
* :class:`telegram.RevenueWithdrawalStateSucceeded`
|
||||
* :class:`telegram.RevenueWithdrawalStateFailed`
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`type` is equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Args:
|
||||
type (:obj:`str`): The type of the state.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the state.
|
||||
"""
|
||||
|
||||
__slots__ = ("type",)
|
||||
|
||||
PENDING: Final[str] = constants.RevenueWithdrawalStateType.PENDING
|
||||
""":const:`telegram.constants.RevenueWithdrawalStateType.PENDING`"""
|
||||
SUCCEEDED: Final[str] = constants.RevenueWithdrawalStateType.SUCCEEDED
|
||||
""":const:`telegram.constants.RevenueWithdrawalStateType.SUCCEEDED`"""
|
||||
FAILED: Final[str] = constants.RevenueWithdrawalStateType.FAILED
|
||||
""":const:`telegram.constants.RevenueWithdrawalStateType.FAILED`"""
|
||||
|
||||
def __init__(self, type: str, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.type: str = enum.get_member(constants.RevenueWithdrawalStateType, type, type)
|
||||
|
||||
self._id_attrs = (self.type,)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "RevenueWithdrawalState":
|
||||
"""Converts JSON data to the appropriate :class:`RevenueWithdrawalState` object, i.e. takes
|
||||
care of selecting the correct subclass.
|
||||
|
||||
Args:
|
||||
data (dict[:obj:`str`, ...]): The JSON data.
|
||||
bot (:class:`telegram.Bot`): The bot associated with this object.
|
||||
|
||||
Returns:
|
||||
The Telegram object.
|
||||
|
||||
"""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
_class_mapping: dict[str, type[RevenueWithdrawalState]] = {
|
||||
cls.PENDING: RevenueWithdrawalStatePending,
|
||||
cls.SUCCEEDED: RevenueWithdrawalStateSucceeded,
|
||||
cls.FAILED: RevenueWithdrawalStateFailed,
|
||||
}
|
||||
|
||||
if cls is RevenueWithdrawalState and data.get("type") in _class_mapping:
|
||||
return _class_mapping[data.pop("type")].de_json(data=data, bot=bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class RevenueWithdrawalStatePending(RevenueWithdrawalState):
|
||||
"""The withdrawal is in progress.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the state, always
|
||||
:tg-const:`telegram.RevenueWithdrawalState.PENDING`.
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(type=RevenueWithdrawalState.PENDING, api_kwargs=api_kwargs)
|
||||
self._freeze()
|
||||
|
||||
|
||||
class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
|
||||
"""The withdrawal succeeded.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`date` are equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Args:
|
||||
date (:obj:`datetime.datetime`): Date the withdrawal was completed as a datetime object.
|
||||
url (:obj:`str`): An HTTPS URL that can be used to see transaction details.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the state, always
|
||||
:tg-const:`telegram.RevenueWithdrawalState.SUCCEEDED`.
|
||||
date (:obj:`datetime.datetime`): Date the withdrawal was completed as a datetime object.
|
||||
url (:obj:`str`): An HTTPS URL that can be used to see transaction details.
|
||||
"""
|
||||
|
||||
__slots__ = ("date", "url")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
date: dtm.datetime,
|
||||
url: str,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(type=RevenueWithdrawalState.SUCCEEDED, api_kwargs=api_kwargs)
|
||||
|
||||
with self._unfrozen():
|
||||
self.date: dtm.datetime = date
|
||||
self.url: str = url
|
||||
self._id_attrs = (
|
||||
self.type,
|
||||
self.date,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(
|
||||
cls, data: JSONDict, bot: Optional["Bot"] = None
|
||||
) -> "RevenueWithdrawalStateSucceeded":
|
||||
"""See :meth:`telegram.RevenueWithdrawalState.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["date"] = from_timestamp(data.get("date", None), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
|
||||
"""The withdrawal failed and the transaction was refunded.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the state, always
|
||||
:tg-const:`telegram.RevenueWithdrawalState.FAILED`.
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(type=RevenueWithdrawalState.FAILED, api_kwargs=api_kwargs)
|
||||
self._freeze()
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram StarAmount."""
|
||||
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class StarAmount(TelegramObject):
|
||||
"""Describes an amount of Telegram Stars.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`amount` and :attr:`nanostar_amount` are equal.
|
||||
|
||||
Args:
|
||||
amount (:obj:`int`): Integer amount of Telegram Stars, rounded to ``0``; can be negative.
|
||||
nanostar_amount (:obj:`int`, optional): The number of
|
||||
:tg-const:`telegram.constants.Nanostar.VALUE` shares of Telegram
|
||||
Stars; from :tg-const:`telegram.constants.NanostarLimit.MIN_AMOUNT`
|
||||
to :tg-const:`telegram.constants.NanostarLimit.MAX_AMOUNT`; can be
|
||||
negative if and only if :attr:`amount` is non-positive.
|
||||
|
||||
Attributes:
|
||||
amount (:obj:`int`): Integer amount of Telegram Stars, rounded to ``0``; can be negative.
|
||||
nanostar_amount (:obj:`int`): Optional. The number of
|
||||
:tg-const:`telegram.constants.Nanostar.VALUE` shares of Telegram
|
||||
Stars; from :tg-const:`telegram.constants.NanostarLimit.MIN_AMOUNT`
|
||||
to :tg-const:`telegram.constants.NanostarLimit.MAX_AMOUNT`; can be
|
||||
negative if and only if :attr:`amount` is non-positive.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("amount", "nanostar_amount")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
amount: int,
|
||||
nanostar_amount: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.amount: int = amount
|
||||
self.nanostar_amount: Optional[int] = nanostar_amount
|
||||
|
||||
self._id_attrs = (self.amount, self.nanostar_amount)
|
||||
|
||||
self._freeze()
|
||||
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
# pylint: disable=redefined-builtin
|
||||
"""This module contains the classes for Telegram Stars transactions."""
|
||||
|
||||
import datetime as dtm
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional, de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
from .transactionpartner import TransactionPartner
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class StarTransaction(TelegramObject):
|
||||
"""Describes a Telegram Star transaction.
|
||||
Note that if the buyer initiates a chargeback with the payment provider from whom they
|
||||
acquired Stars (e.g., Apple, Google) following this transaction, the refunded Stars will be
|
||||
deducted from the bot's balance. This is outside of Telegram's control.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id`, :attr:`source`, and :attr:`receiver` are equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier of the transaction. Coincides with the identifer
|
||||
of the original transaction for refund transactions.
|
||||
Coincides with :attr:`SuccessfulPayment.telegram_payment_charge_id` for
|
||||
successful incoming payments from users.
|
||||
amount (:obj:`int`): Integer amount of Telegram Stars transferred by the transaction.
|
||||
nanostar_amount (:obj:`int`, optional): The number of
|
||||
:tg-const:`~telegram.constants.Nanostar.VALUE` shares of Telegram
|
||||
Stars transferred by the transaction; from 0 to
|
||||
:tg-const:`~telegram.constants.NanostarLimit.MAX_AMOUNT`
|
||||
|
||||
.. versionadded:: 21.9
|
||||
date (:obj:`datetime.datetime`): Date the transaction was created as a datetime object.
|
||||
source (:class:`telegram.TransactionPartner`, optional): Source of an incoming transaction
|
||||
(e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal).
|
||||
Only for incoming transactions.
|
||||
receiver (:class:`telegram.TransactionPartner`, optional): Receiver of an outgoing
|
||||
transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for
|
||||
outgoing transactions.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Unique identifier of the transaction. Coincides with the identifer
|
||||
of the original transaction for refund transactions.
|
||||
Coincides with :attr:`SuccessfulPayment.telegram_payment_charge_id` for
|
||||
successful incoming payments from users.
|
||||
amount (:obj:`int`): Integer amount of Telegram Stars transferred by the transaction.
|
||||
nanostar_amount (:obj:`int`): Optional. The number of
|
||||
:tg-const:`~telegram.constants.Nanostar.VALUE` shares of Telegram
|
||||
Stars transferred by the transaction; from 0 to
|
||||
:tg-const:`~telegram.constants.NanostarLimit.MAX_AMOUNT`
|
||||
|
||||
.. versionadded:: 21.9
|
||||
date (:obj:`datetime.datetime`): Date the transaction was created as a datetime object.
|
||||
source (:class:`telegram.TransactionPartner`): Optional. Source of an incoming transaction
|
||||
(e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal).
|
||||
Only for incoming transactions.
|
||||
receiver (:class:`telegram.TransactionPartner`): Optional. Receiver of an outgoing
|
||||
transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for
|
||||
outgoing transactions.
|
||||
"""
|
||||
|
||||
__slots__ = ("amount", "date", "id", "nanostar_amount", "receiver", "source")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str,
|
||||
amount: int,
|
||||
date: dtm.datetime,
|
||||
source: Optional[TransactionPartner] = None,
|
||||
receiver: Optional[TransactionPartner] = None,
|
||||
nanostar_amount: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.id: str = id
|
||||
self.amount: int = amount
|
||||
self.date: dtm.datetime = date
|
||||
self.source: Optional[TransactionPartner] = source
|
||||
self.receiver: Optional[TransactionPartner] = receiver
|
||||
self.nanostar_amount: Optional[int] = nanostar_amount
|
||||
|
||||
self._id_attrs = (
|
||||
self.id,
|
||||
self.source,
|
||||
self.receiver,
|
||||
)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "StarTransaction":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["date"] = from_timestamp(data.get("date", None), tzinfo=loc_tzinfo)
|
||||
|
||||
data["source"] = de_json_optional(data.get("source"), TransactionPartner, bot)
|
||||
data["receiver"] = de_json_optional(data.get("receiver"), TransactionPartner, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class StarTransactions(TelegramObject):
|
||||
"""
|
||||
Contains a list of Telegram Star transactions.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`transactions` are equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Args:
|
||||
transactions (Sequence[:class:`telegram.StarTransaction`]): The list of transactions.
|
||||
|
||||
Attributes:
|
||||
transactions (tuple[:class:`telegram.StarTransaction`]): The list of transactions.
|
||||
"""
|
||||
|
||||
__slots__ = ("transactions",)
|
||||
|
||||
def __init__(
|
||||
self, transactions: Sequence[StarTransaction], *, api_kwargs: Optional[JSONDict] = None
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.transactions: tuple[StarTransaction, ...] = parse_sequence_arg(transactions)
|
||||
|
||||
self._id_attrs = (self.transactions,)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "StarTransactions":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["transactions"] = de_list_optional(data.get("transactions"), StarTransaction, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
@@ -0,0 +1,523 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
# pylint: disable=redefined-builtin
|
||||
"""This module contains the classes for Telegram Stars transaction partners."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Final, Optional
|
||||
|
||||
from telegram import constants
|
||||
from telegram._chat import Chat
|
||||
from telegram._gifts import Gift
|
||||
from telegram._paidmedia import PaidMedia
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import (
|
||||
de_json_optional,
|
||||
de_list_optional,
|
||||
parse_sequence_arg,
|
||||
to_timedelta,
|
||||
)
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
from .affiliateinfo import AffiliateInfo
|
||||
from .revenuewithdrawalstate import RevenueWithdrawalState
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import datetime as dtm
|
||||
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class TransactionPartner(TelegramObject):
|
||||
"""This object describes the source of a transaction, or its recipient for outgoing
|
||||
transactions. Currently, it can be one of:
|
||||
|
||||
* :class:`TransactionPartnerUser`
|
||||
* :class:`TransactionPartnerChat`
|
||||
* :class:`TransactionPartnerAffiliateProgram`
|
||||
* :class:`TransactionPartnerFragment`
|
||||
* :class:`TransactionPartnerTelegramAds`
|
||||
* :class:`TransactionPartnerTelegramApi`
|
||||
* :class:`TransactionPartnerOther`
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`type` is equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
.. versionchanged:: 21.11
|
||||
Added :class:`TransactionPartnerChat`
|
||||
|
||||
Args:
|
||||
type (:obj:`str`): The type of the transaction partner.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner.
|
||||
"""
|
||||
|
||||
__slots__ = ("type",)
|
||||
|
||||
AFFILIATE_PROGRAM: Final[str] = constants.TransactionPartnerType.AFFILIATE_PROGRAM
|
||||
""":const:`telegram.constants.TransactionPartnerType.AFFILIATE_PROGRAM`
|
||||
|
||||
.. versionadded:: 21.9
|
||||
"""
|
||||
CHAT: Final[str] = constants.TransactionPartnerType.CHAT
|
||||
""":const:`telegram.constants.TransactionPartnerType.CHAT`
|
||||
|
||||
.. versionadded:: 21.11
|
||||
"""
|
||||
FRAGMENT: Final[str] = constants.TransactionPartnerType.FRAGMENT
|
||||
""":const:`telegram.constants.TransactionPartnerType.FRAGMENT`"""
|
||||
OTHER: Final[str] = constants.TransactionPartnerType.OTHER
|
||||
""":const:`telegram.constants.TransactionPartnerType.OTHER`"""
|
||||
TELEGRAM_ADS: Final[str] = constants.TransactionPartnerType.TELEGRAM_ADS
|
||||
""":const:`telegram.constants.TransactionPartnerType.TELEGRAM_ADS`"""
|
||||
TELEGRAM_API: Final[str] = constants.TransactionPartnerType.TELEGRAM_API
|
||||
""":const:`telegram.constants.TransactionPartnerType.TELEGRAM_API`"""
|
||||
USER: Final[str] = constants.TransactionPartnerType.USER
|
||||
""":const:`telegram.constants.TransactionPartnerType.USER`"""
|
||||
|
||||
def __init__(self, type: str, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.type: str = enum.get_member(constants.TransactionPartnerType, type, type)
|
||||
|
||||
self._id_attrs = (self.type,)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "TransactionPartner":
|
||||
"""Converts JSON data to the appropriate :class:`TransactionPartner` object, i.e. takes
|
||||
care of selecting the correct subclass.
|
||||
|
||||
Args:
|
||||
data (dict[:obj:`str`, ...]): The JSON data.
|
||||
bot (:class:`telegram.Bot`): The bot associated with this object.
|
||||
|
||||
Returns:
|
||||
The Telegram object.
|
||||
|
||||
"""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
_class_mapping: dict[str, type[TransactionPartner]] = {
|
||||
cls.AFFILIATE_PROGRAM: TransactionPartnerAffiliateProgram,
|
||||
cls.CHAT: TransactionPartnerChat,
|
||||
cls.FRAGMENT: TransactionPartnerFragment,
|
||||
cls.USER: TransactionPartnerUser,
|
||||
cls.TELEGRAM_ADS: TransactionPartnerTelegramAds,
|
||||
cls.TELEGRAM_API: TransactionPartnerTelegramApi,
|
||||
cls.OTHER: TransactionPartnerOther,
|
||||
}
|
||||
|
||||
if cls is TransactionPartner and data.get("type") in _class_mapping:
|
||||
return _class_mapping[data.pop("type")].de_json(data=data, bot=bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class TransactionPartnerAffiliateProgram(TransactionPartner):
|
||||
"""Describes the affiliate program that issued the affiliate commission received via this
|
||||
transaction.
|
||||
|
||||
This object is comparable in terms of equality. Two objects of this class are considered equal,
|
||||
if their :attr:`commission_per_mille` are equal.
|
||||
|
||||
.. versionadded:: 21.9
|
||||
|
||||
Args:
|
||||
sponsor_user (:class:`telegram.User`, optional): Information about the bot that sponsored
|
||||
the affiliate program
|
||||
commission_per_mille (:obj:`int`): The number of Telegram Stars received by the bot for
|
||||
each 1000 Telegram Stars received by the affiliate program sponsor from referred users.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.AFFILIATE_PROGRAM`.
|
||||
sponsor_user (:class:`telegram.User`): Optional. Information about the bot that sponsored
|
||||
the affiliate program
|
||||
commission_per_mille (:obj:`int`): The number of Telegram Stars received by the bot for
|
||||
each 1000 Telegram Stars received by the affiliate program sponsor from referred users.
|
||||
"""
|
||||
|
||||
__slots__ = ("commission_per_mille", "sponsor_user")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
commission_per_mille: int,
|
||||
sponsor_user: Optional["User"] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(type=TransactionPartner.AFFILIATE_PROGRAM, api_kwargs=api_kwargs)
|
||||
|
||||
with self._unfrozen():
|
||||
self.sponsor_user: Optional[User] = sponsor_user
|
||||
self.commission_per_mille: int = commission_per_mille
|
||||
self._id_attrs = (
|
||||
self.type,
|
||||
self.commission_per_mille,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(
|
||||
cls, data: JSONDict, bot: Optional["Bot"] = None
|
||||
) -> "TransactionPartnerAffiliateProgram":
|
||||
"""See :meth:`telegram.TransactionPartner.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["sponsor_user"] = de_json_optional(data.get("sponsor_user"), User, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class TransactionPartnerChat(TransactionPartner):
|
||||
"""Describes a transaction with a chat.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`chat` are equal.
|
||||
|
||||
.. versionadded:: 21.11
|
||||
|
||||
Args:
|
||||
chat (:class:`telegram.Chat`): Information about the chat.
|
||||
gift (:class:`telegram.Gift`, optional): The gift sent to the chat by the bot.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.CHAT`.
|
||||
chat (:class:`telegram.Chat`): Information about the chat.
|
||||
gift (:class:`telegram.Gift`): Optional. The gift sent to the user by the bot.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"chat",
|
||||
"gift",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
chat: Chat,
|
||||
gift: Optional[Gift] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(type=TransactionPartner.CHAT, api_kwargs=api_kwargs)
|
||||
|
||||
with self._unfrozen():
|
||||
self.chat: Chat = chat
|
||||
self.gift: Optional[Gift] = gift
|
||||
|
||||
self._id_attrs = (
|
||||
self.type,
|
||||
self.chat,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "TransactionPartnerChat":
|
||||
"""See :meth:`telegram.TransactionPartner.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["chat"] = de_json_optional(data.get("chat"), Chat, bot)
|
||||
data["gift"] = de_json_optional(data.get("gift"), Gift, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class TransactionPartnerFragment(TransactionPartner):
|
||||
"""Describes a withdrawal transaction with Fragment.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Args:
|
||||
withdrawal_state (:class:`telegram.RevenueWithdrawalState`, optional): State of the
|
||||
transaction if the transaction is outgoing.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.FRAGMENT`.
|
||||
withdrawal_state (:class:`telegram.RevenueWithdrawalState`): Optional. State of the
|
||||
transaction if the transaction is outgoing.
|
||||
"""
|
||||
|
||||
__slots__ = ("withdrawal_state",)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
withdrawal_state: Optional["RevenueWithdrawalState"] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(type=TransactionPartner.FRAGMENT, api_kwargs=api_kwargs)
|
||||
|
||||
with self._unfrozen():
|
||||
self.withdrawal_state: Optional[RevenueWithdrawalState] = withdrawal_state
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "TransactionPartnerFragment":
|
||||
"""See :meth:`telegram.TransactionPartner.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["withdrawal_state"] = de_json_optional(
|
||||
data.get("withdrawal_state"), RevenueWithdrawalState, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class TransactionPartnerUser(TransactionPartner):
|
||||
"""Describes a transaction with a user.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`user` and :attr:`transaction_type` are equal.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
.. versionchanged:: 22.1
|
||||
Equality comparison now includes the new required argument :paramref:`transaction_type`,
|
||||
introduced in Bot API 9.0.
|
||||
|
||||
Args:
|
||||
transaction_type (:obj:`str`): Type of the transaction, currently one of
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT` for payments via
|
||||
invoices, :tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT`
|
||||
for payments for paid media,
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.GIFT_PURCHASE` for gifts sent by
|
||||
the bot, :tg-const:`telegram.constants.TransactionPartnerUser.PREMIUM_PURCHASE`
|
||||
for Telegram Premium subscriptions gifted by the bot,
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.BUSINESS_ACCOUNT_TRANSFER` for
|
||||
direct transfers from managed business accounts.
|
||||
|
||||
.. versionadded:: 22.1
|
||||
user (:class:`telegram.User`): Information about the user.
|
||||
affiliate (:class:`telegram.AffiliateInfo`, optional): Information about the affiliate that
|
||||
received a commission via this transaction. Can be available only for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT`
|
||||
and :tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT`
|
||||
transactions.
|
||||
|
||||
.. versionadded:: 21.9
|
||||
invoice_payload (:obj:`str`, optional): Bot-specified invoice payload. Can be available
|
||||
only for :tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT`
|
||||
transactions.
|
||||
subscription_period (:obj:`int` | :class:`datetime.timedelta`, optional): The duration of
|
||||
the paid subscription. Can be available only for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT` transactions.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
Accepts :obj:`int` objects as well as :class:`datetime.timedelta`.
|
||||
paid_media (Sequence[:class:`telegram.PaidMedia`], optional): Information about the paid
|
||||
media bought by the user. for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT`
|
||||
transactions only.
|
||||
|
||||
.. versionadded:: 21.5
|
||||
paid_media_payload (:obj:`str`, optional): Bot-specified paid media payload. Can be
|
||||
available only for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT` transactions.
|
||||
|
||||
.. versionadded:: 21.6
|
||||
gift (:class:`telegram.Gift`, optional): The gift sent to the user by the bot; for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.GIFT_PURCHASE` transactions only.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
premium_subscription_duration (:obj:`int`, optional): Number of months the gifted Telegram
|
||||
Premium subscription will be active for; for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.PREMIUM_PURCHASE`
|
||||
transactions only.
|
||||
|
||||
.. versionadded:: 22.1
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.USER`.
|
||||
transaction_type (:obj:`str`): Type of the transaction, currently one of
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT` for payments via
|
||||
invoices, :tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT`
|
||||
for payments for paid media,
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.GIFT_PURCHASE` for gifts sent by
|
||||
the bot, :tg-const:`telegram.constants.TransactionPartnerUser.PREMIUM_PURCHASE`
|
||||
for Telegram Premium subscriptions gifted by the bot,
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.BUSINESS_ACCOUNT_TRANSFER` for
|
||||
direct transfers from managed business accounts.
|
||||
|
||||
.. versionadded:: 22.1
|
||||
user (:class:`telegram.User`): Information about the user.
|
||||
affiliate (:class:`telegram.AffiliateInfo`): Optional. Information about the affiliate that
|
||||
received a commission via this transaction. Can be available only for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT`
|
||||
and :tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT`
|
||||
transactions.
|
||||
|
||||
.. versionadded:: 21.9
|
||||
invoice_payload (:obj:`str`): Optional. Bot-specified invoice payload. Can be available
|
||||
only for :tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT`
|
||||
transactions.
|
||||
subscription_period (:class:`datetime.timedelta`): Optional. The duration of the paid
|
||||
subscription. Can be available only for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.INVOICE_PAYMENT` transactions.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
paid_media (tuple[:class:`telegram.PaidMedia`]): Optional. Information about the paid
|
||||
media bought by the user. for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT`
|
||||
transactions only.
|
||||
|
||||
.. versionadded:: 21.5
|
||||
paid_media_payload (:obj:`str`): Optional. Bot-specified paid media payload. Can be
|
||||
available only for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.PAID_MEDIA_PAYMENT` transactions.
|
||||
|
||||
.. versionadded:: 21.6
|
||||
gift (:class:`telegram.Gift`): Optional. The gift sent to the user by the bot; for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.GIFT_PURCHASE` transactions only.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
premium_subscription_duration (:obj:`int`): Optional. Number of months the gifted Telegram
|
||||
Premium subscription will be active for; for
|
||||
:tg-const:`telegram.constants.TransactionPartnerUser.PREMIUM_PURCHASE`
|
||||
transactions only.
|
||||
|
||||
.. versionadded:: 22.1
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"affiliate",
|
||||
"gift",
|
||||
"invoice_payload",
|
||||
"paid_media",
|
||||
"paid_media_payload",
|
||||
"premium_subscription_duration",
|
||||
"subscription_period",
|
||||
"transaction_type",
|
||||
"user",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
transaction_type: str,
|
||||
user: "User",
|
||||
invoice_payload: Optional[str] = None,
|
||||
paid_media: Optional[Sequence[PaidMedia]] = None,
|
||||
paid_media_payload: Optional[str] = None,
|
||||
subscription_period: Optional[TimePeriod] = None,
|
||||
gift: Optional[Gift] = None,
|
||||
affiliate: Optional[AffiliateInfo] = None,
|
||||
premium_subscription_duration: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
) -> None:
|
||||
super().__init__(type=TransactionPartner.USER, api_kwargs=api_kwargs)
|
||||
|
||||
with self._unfrozen():
|
||||
self.user: User = user
|
||||
self.affiliate: Optional[AffiliateInfo] = affiliate
|
||||
self.invoice_payload: Optional[str] = invoice_payload
|
||||
self.paid_media: Optional[tuple[PaidMedia, ...]] = parse_sequence_arg(paid_media)
|
||||
self.paid_media_payload: Optional[str] = paid_media_payload
|
||||
self.subscription_period: Optional[dtm.timedelta] = to_timedelta(subscription_period)
|
||||
self.gift: Optional[Gift] = gift
|
||||
self.premium_subscription_duration: Optional[int] = premium_subscription_duration
|
||||
self.transaction_type: str = transaction_type
|
||||
|
||||
self._id_attrs = (
|
||||
self.type,
|
||||
self.user,
|
||||
self.transaction_type,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "TransactionPartnerUser":
|
||||
"""See :meth:`telegram.TransactionPartner.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_optional(data.get("user"), User, bot)
|
||||
data["affiliate"] = de_json_optional(data.get("affiliate"), AffiliateInfo, bot)
|
||||
data["paid_media"] = de_list_optional(data.get("paid_media"), PaidMedia, bot)
|
||||
data["gift"] = de_json_optional(data.get("gift"), Gift, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class TransactionPartnerOther(TransactionPartner):
|
||||
"""Describes a transaction with an unknown partner.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.OTHER`.
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(type=TransactionPartner.OTHER, api_kwargs=api_kwargs)
|
||||
self._freeze()
|
||||
|
||||
|
||||
class TransactionPartnerTelegramAds(TransactionPartner):
|
||||
"""Describes a withdrawal transaction to the Telegram Ads platform.
|
||||
|
||||
.. versionadded:: 21.4
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.TELEGRAM_ADS`.
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(type=TransactionPartner.TELEGRAM_ADS, api_kwargs=api_kwargs)
|
||||
self._freeze()
|
||||
|
||||
|
||||
class TransactionPartnerTelegramApi(TransactionPartner):
|
||||
"""Describes a transaction with payment for
|
||||
`paid broadcasting <https://core.telegram.org/bots/api#paid-broadcasts>`_.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`request_count` is equal.
|
||||
|
||||
.. versionadded:: 21.7
|
||||
|
||||
Args:
|
||||
request_count (:obj:`int`): The number of successful requests that exceeded regular limits
|
||||
and were therefore billed.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): The type of the transaction partner,
|
||||
always :tg-const:`telegram.TransactionPartner.TELEGRAM_API`.
|
||||
request_count (:obj:`int`): The number of successful requests that exceeded regular limits
|
||||
and were therefore billed.
|
||||
"""
|
||||
|
||||
__slots__ = ("request_count",)
|
||||
|
||||
def __init__(self, request_count: int, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(type=TransactionPartner.TELEGRAM_API, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.request_count: int = request_count
|
||||
self._id_attrs = (self.request_count,)
|
||||
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""This module contains an object that represents a Telegram SuccessfulPayment."""
|
||||
|
||||
import datetime as dtm
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._payment.orderinfo import OrderInfo
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class SuccessfulPayment(TelegramObject):
|
||||
"""This object contains basic information about a successful payment.
|
||||
Note that if the buyer initiates a chargeback with the relevant payment provider following
|
||||
this transaction, the funds may be debited from your balance. This is outside of
|
||||
Telegram's control.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`telegram_payment_charge_id` and
|
||||
:attr:`provider_payment_charge_id` are equal.
|
||||
|
||||
Args:
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, or ``XTR`` for payments in
|
||||
|tg_stars|.
|
||||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
subscription_expiration_date (:class:`datetime.datetime`, optional): Expiration date of the
|
||||
subscription; for recurring payments only.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
is_recurring (:obj:`bool`, optional): True, if the payment is for a subscription.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
is_first_recurring (:obj:`bool`, optional): True, if the payment is the first payment of a
|
||||
subscription.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
shipping_option_id (:obj:`str`, optional): Identifier of the shipping option chosen by the
|
||||
user.
|
||||
order_info (:class:`telegram.OrderInfo`, optional): Order info provided by the user.
|
||||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier.
|
||||
provider_payment_charge_id (:obj:`str`): Provider payment identifier.
|
||||
|
||||
Attributes:
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, or ``XTR`` for payments in
|
||||
|tg_stars|.
|
||||
total_amount (:obj:`int`): Total price in the smallest units of the currency (integer,
|
||||
**not** float/double). For example, for a price of ``US$ 1.45`` pass ``amount = 145``.
|
||||
See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_,
|
||||
it shows the number of digits past the decimal point for each currency
|
||||
(2 for the majority of currencies).
|
||||
invoice_payload (:obj:`str`): Bot-specified invoice payload.
|
||||
subscription_expiration_date (:class:`datetime.datetime`): Optional. Expiration
|
||||
date of the subscription; for recurring payments only.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
is_recurring (:obj:`bool`): Optional. True, if the payment is for a subscription.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
is_first_recurring (:obj:`bool`): Optional. True, if the payment is the first payment of a
|
||||
subscription.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
shipping_option_id (:obj:`str`): Optional. Identifier of the shipping option chosen by the
|
||||
user.
|
||||
order_info (:class:`telegram.OrderInfo`): Optional. Order info provided by the user.
|
||||
telegram_payment_charge_id (:obj:`str`): Telegram payment identifier.
|
||||
provider_payment_charge_id (:obj:`str`): Provider payment identifier.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"currency",
|
||||
"invoice_payload",
|
||||
"is_first_recurring",
|
||||
"is_recurring",
|
||||
"order_info",
|
||||
"provider_payment_charge_id",
|
||||
"shipping_option_id",
|
||||
"subscription_expiration_date",
|
||||
"telegram_payment_charge_id",
|
||||
"total_amount",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
currency: str,
|
||||
total_amount: int,
|
||||
invoice_payload: str,
|
||||
telegram_payment_charge_id: str,
|
||||
provider_payment_charge_id: str,
|
||||
shipping_option_id: Optional[str] = None,
|
||||
order_info: Optional[OrderInfo] = None,
|
||||
subscription_expiration_date: Optional[dtm.datetime] = None,
|
||||
is_recurring: Optional[bool] = None,
|
||||
is_first_recurring: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.currency: str = currency
|
||||
self.total_amount: int = total_amount
|
||||
self.invoice_payload: str = invoice_payload
|
||||
self.shipping_option_id: Optional[str] = shipping_option_id
|
||||
self.order_info: Optional[OrderInfo] = order_info
|
||||
self.telegram_payment_charge_id: str = telegram_payment_charge_id
|
||||
self.provider_payment_charge_id: str = provider_payment_charge_id
|
||||
self.subscription_expiration_date: Optional[dtm.datetime] = subscription_expiration_date
|
||||
self.is_recurring: Optional[bool] = is_recurring
|
||||
self.is_first_recurring: Optional[bool] = is_first_recurring
|
||||
|
||||
self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuccessfulPayment":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["order_info"] = de_json_optional(data.get("order_info"), OrderInfo, bot)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["subscription_expiration_date"] = from_timestamp(
|
||||
data.get("subscription_expiration_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
Reference in New Issue
Block a user