2021-04-30 10:09:21 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2024-02-19 20:06:25 +01:00
|
|
|
# Copyright (C) 2015-2024
|
2021-04-30 10:09:21 +02:00
|
|
|
# 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 a class that represents a Telegram InputInvoiceMessageContent."""
|
2023-02-02 18:55:07 +01:00
|
|
|
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
|
2021-04-30 10:09:21 +02:00
|
|
|
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram._inline.inputmessagecontent import InputMessageContent
|
|
|
|
from telegram._payment.labeledprice import LabeledPrice
|
2022-12-15 15:00:36 +01:00
|
|
|
from telegram._utils.argumentparsing import parse_sequence_arg
|
2021-10-10 15:10:21 +02:00
|
|
|
from telegram._utils.types import JSONDict
|
2021-04-30 10:09:21 +02:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from telegram import Bot
|
|
|
|
|
|
|
|
|
|
|
|
class InputInvoiceMessageContent(InputMessageContent):
|
|
|
|
"""
|
|
|
|
Represents the content of a invoice message to be sent as the result of an inline query.
|
|
|
|
|
|
|
|
Objects of this class are comparable in terms of equality. Two objects of this class are
|
|
|
|
considered equal, if their :attr:`title`, :attr:`description`, :attr:`payload`,
|
|
|
|
:attr:`provider_token`, :attr:`currency` and :attr:`prices` are equal.
|
|
|
|
|
|
|
|
.. versionadded:: 13.5
|
|
|
|
|
|
|
|
Args:
|
2022-06-27 18:54:11 +02:00
|
|
|
title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`-
|
|
|
|
:tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters.
|
|
|
|
description (:obj:`str`): Product description.
|
|
|
|
:tg-const:`telegram.Invoice.MIN_DESCRIPTION_LENGTH`-
|
|
|
|
:tg-const:`telegram.Invoice.MAX_DESCRIPTION_LENGTH` characters.
|
|
|
|
payload (:obj:`str`): Bot-defined invoice payload.
|
|
|
|
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
|
|
|
|
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed
|
2021-04-30 10:09:21 +02:00
|
|
|
to the user, use for your internal processes.
|
|
|
|
provider_token (:obj:`str`): Payment provider token, obtained via
|
2024-06-03 19:39:31 +02:00
|
|
|
`@Botfather <https://t.me/Botfather>`_. Pass an empty string for payments in
|
|
|
|
|tg_stars|.
|
|
|
|
|
2024-06-07 16:52:22 +02:00
|
|
|
.. deprecated:: 21.3
|
2024-06-03 19:39:31 +02:00
|
|
|
As of Bot API 7.4, this parameter is now optional and future versions of the
|
|
|
|
library will make it optional as well.
|
2021-04-30 10:09:21 +02:00
|
|
|
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
|
2024-06-03 19:39:31 +02:00
|
|
|
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_.
|
|
|
|
Pass ``XTR`` for payments in |tg_stars|.
|
2022-12-15 15:00:36 +01:00
|
|
|
prices (Sequence[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
|
2021-04-30 10:09:21 +02:00
|
|
|
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
|
2024-06-03 19:39:31 +02:00
|
|
|
etc.). Must contain exactly one item for payments in |tg_stars|.
|
2022-12-15 15:00:36 +01:00
|
|
|
|
|
|
|
.. versionchanged:: 20.0
|
|
|
|
|sequenceclassargs|
|
|
|
|
|
2022-06-27 18:54:11 +02:00
|
|
|
max_tip_amount (:obj:`int`, optional): The maximum accepted amount for tips in the
|
|
|
|
*smallest* units of the currency (integer, **not** float/double). For example, for a
|
|
|
|
maximum tip of US$ 1.45 pass ``max_tip_amount = 145``. See the ``exp`` parameter in
|
2021-04-30 10:09:21 +02:00
|
|
|
`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
|
2024-06-03 19:39:31 +02:00
|
|
|
of currencies). Defaults to ``0``. Defaults to ``0``. Not supported for payments in
|
|
|
|
|tg_stars|.
|
2022-12-15 15:00:36 +01:00
|
|
|
suggested_tip_amounts (Sequence[:obj:`int`], optional): An array of suggested
|
2022-06-27 18:54:11 +02:00
|
|
|
amounts of tip in the *smallest* units of the currency (integer, **not** float/double).
|
|
|
|
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
|
2021-04-30 10:09:21 +02:00
|
|
|
positive, passed in a strictly increased order and must not exceed
|
|
|
|
:attr:`max_tip_amount`.
|
2022-12-15 15:00:36 +01:00
|
|
|
|
|
|
|
.. versionchanged:: 20.0
|
|
|
|
|
|
|
|
* |tupleclassattrs|
|
|
|
|
* |alwaystuple|
|
|
|
|
|
2022-01-03 09:09:03 +01:00
|
|
|
provider_data (:obj:`str`, optional): An object for data about the invoice,
|
2021-04-30 10:09:21 +02:00
|
|
|
which will be shared with the payment provider. A detailed description of the required
|
|
|
|
fields should be provided by the payment provider.
|
|
|
|
photo_url (:obj:`str`, optional): URL of the product photo for the invoice. Can be a photo
|
|
|
|
of the goods or a marketing image for a service. People like it better when they see
|
|
|
|
what they are paying for.
|
|
|
|
photo_size (:obj:`int`, optional): Photo size.
|
|
|
|
photo_width (:obj:`int`, optional): Photo width.
|
|
|
|
photo_height (:obj:`int`, optional): Photo height.
|
2024-06-03 19:39:31 +02:00
|
|
|
need_name (:obj:`bool`, optional): Pass :obj:`True`, if you require the user's full
|
|
|
|
name to complete the order. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
need_phone_number (:obj:`bool`, optional): Pass :obj:`True`, if you require the user's
|
2024-06-03 19:39:31 +02:00
|
|
|
phone number to complete the order. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
need_email (:obj:`bool`, optional): Pass :obj:`True`, if you require the user's email
|
2024-06-03 19:39:31 +02:00
|
|
|
address to complete the order. Ignored for payments in |tg_stars|.
|
|
|
|
need_shipping_address (:obj:`bool`, optional): Pass :obj:`True`, if you require the
|
|
|
|
user's shipping address to complete the order. Ignored for payments in |tg_stars|
|
|
|
|
send_phone_number_to_provider (:obj:`bool`, optional): Pass :obj:`True`, if user's
|
|
|
|
phone number should be sent to provider. Ignored for payments in |tg_stars|.
|
|
|
|
send_email_to_provider (:obj:`bool`, optional): Pass :obj:`True`, if user's email
|
|
|
|
address should be sent to provider. Ignored for payments in |tg_stars|.
|
|
|
|
is_flexible (:obj:`bool`, optional): Pass :obj:`True`, if the final price depends on
|
|
|
|
the shipping method. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
|
|
|
|
Attributes:
|
2022-06-27 18:54:11 +02:00
|
|
|
title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`-
|
|
|
|
:tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters.
|
|
|
|
description (:obj:`str`): Product description.
|
|
|
|
:tg-const:`telegram.Invoice.MIN_DESCRIPTION_LENGTH`-
|
|
|
|
:tg-const:`telegram.Invoice.MAX_DESCRIPTION_LENGTH` characters.
|
|
|
|
payload (:obj:`str`): Bot-defined invoice payload.
|
|
|
|
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
|
|
|
|
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed
|
2021-04-30 10:09:21 +02:00
|
|
|
to the user, use for your internal processes.
|
|
|
|
provider_token (:obj:`str`): Payment provider token, obtained via
|
2024-06-03 19:39:31 +02:00
|
|
|
`@Botfather <https://t.me/Botfather>`_. Pass an empty string for payments in `Telegram
|
|
|
|
Stars <https://t.me/BotNews/90>`_.
|
2021-04-30 10:09:21 +02:00
|
|
|
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
|
2024-06-03 19:39:31 +02:00
|
|
|
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_.
|
|
|
|
Pass ``XTR`` for payments in |tg_stars|.
|
2022-12-15 15:00:36 +01:00
|
|
|
prices (Tuple[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
|
2023-01-01 16:24:00 +01:00
|
|
|
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
|
2024-06-03 19:39:31 +02:00
|
|
|
etc.). Must contain exactly one item for payments in |tg_stars|.
|
2022-12-15 15:00:36 +01:00
|
|
|
|
|
|
|
.. versionchanged:: 20.0
|
|
|
|
|tupleclassattrs|
|
|
|
|
|
2023-01-01 16:24:00 +01:00
|
|
|
max_tip_amount (:obj:`int`): Optional. The maximum accepted amount for tips in the
|
|
|
|
*smallest* units of the currency (integer, **not** float/double). For example, for a
|
|
|
|
maximum tip of US$ 1.45 ``max_tip_amount`` is ``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
|
2024-06-03 19:39:31 +02:00
|
|
|
of currencies). Defaults to ``0``. Not supported for payments in |tg_stars|.
|
2022-12-15 15:00:36 +01:00
|
|
|
suggested_tip_amounts (Tuple[:obj:`int`]): Optional. An array of suggested
|
2023-01-01 16:24:00 +01:00
|
|
|
amounts of tip in the *smallest* units of the currency (integer, **not** float/double).
|
|
|
|
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
|
|
|
|
positive, passed in a strictly increased order and must not exceed
|
|
|
|
:attr:`max_tip_amount`.
|
2022-12-15 15:00:36 +01:00
|
|
|
|
|
|
|
.. versionchanged:: 20.0
|
|
|
|
|tupleclassattrs|
|
|
|
|
|
2022-01-03 09:09:03 +01:00
|
|
|
provider_data (:obj:`str`): Optional. An object for data about the invoice,
|
2023-01-01 16:24:00 +01:00
|
|
|
which will be shared with the payment provider. A detailed description of the required
|
|
|
|
fields should be provided by the payment provider.
|
|
|
|
photo_url (:obj:`str`): Optional. URL of the product photo for the invoice. Can be a photo
|
|
|
|
of the goods or a marketing image for a service. People like it better when they see
|
|
|
|
what they are paying for.
|
2021-04-30 10:09:21 +02:00
|
|
|
photo_size (:obj:`int`): Optional. Photo size.
|
|
|
|
photo_width (:obj:`int`): Optional. Photo width.
|
|
|
|
photo_height (:obj:`int`): Optional. Photo height.
|
|
|
|
need_name (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's full name to
|
2024-06-03 19:39:31 +02:00
|
|
|
complete the order. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
need_phone_number (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's
|
2024-06-03 19:39:31 +02:00
|
|
|
phone number to complete the order. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
need_email (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's email
|
2024-06-03 19:39:31 +02:00
|
|
|
address to complete the order. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
need_shipping_address (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's
|
2024-06-03 19:39:31 +02:00
|
|
|
shipping address to complete the order. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
send_phone_number_to_provider (:obj:`bool`): Optional. Pass :obj:`True`, if user's phone
|
2024-06-03 19:39:31 +02:00
|
|
|
number should be sent to provider. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
send_email_to_provider (:obj:`bool`): Optional. Pass :obj:`True`, if user's email address
|
2024-06-03 19:39:31 +02:00
|
|
|
should be sent to provider. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
is_flexible (:obj:`bool`): Optional. Pass :obj:`True`, if the final price depends on the
|
2024-06-03 19:39:31 +02:00
|
|
|
shipping method. Ignored for payments in |tg_stars|.
|
2021-04-30 10:09:21 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2021-05-29 16:18:16 +02:00
|
|
|
__slots__ = (
|
|
|
|
"currency",
|
2024-02-05 19:24:00 +01:00
|
|
|
"description",
|
|
|
|
"is_flexible",
|
2021-05-29 16:18:16 +02:00
|
|
|
"max_tip_amount",
|
2024-02-05 19:24:00 +01:00
|
|
|
"need_email",
|
2021-05-29 16:18:16 +02:00
|
|
|
"need_name",
|
|
|
|
"need_phone_number",
|
|
|
|
"need_shipping_address",
|
2024-02-05 19:24:00 +01:00
|
|
|
"payload",
|
|
|
|
"photo_height",
|
|
|
|
"photo_size",
|
|
|
|
"photo_url",
|
|
|
|
"photo_width",
|
|
|
|
"prices",
|
|
|
|
"provider_data",
|
|
|
|
"provider_token",
|
2021-05-29 16:18:16 +02:00
|
|
|
"send_email_to_provider",
|
2024-02-05 19:24:00 +01:00
|
|
|
"send_phone_number_to_provider",
|
|
|
|
"suggested_tip_amounts",
|
|
|
|
"title",
|
2021-05-29 16:18:16 +02:00
|
|
|
)
|
|
|
|
|
2021-04-30 10:09:21 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
title: str,
|
|
|
|
description: str,
|
|
|
|
payload: str,
|
2024-06-03 19:39:31 +02:00
|
|
|
provider_token: Optional[str], # This arg is now optional since Bot API 7.4
|
2021-04-30 10:09:21 +02:00
|
|
|
currency: str,
|
2022-12-15 15:00:36 +01:00
|
|
|
prices: Sequence[LabeledPrice],
|
2023-05-18 07:57:59 +02:00
|
|
|
max_tip_amount: Optional[int] = None,
|
|
|
|
suggested_tip_amounts: Optional[Sequence[int]] = None,
|
|
|
|
provider_data: Optional[str] = None,
|
|
|
|
photo_url: Optional[str] = None,
|
|
|
|
photo_size: Optional[int] = None,
|
|
|
|
photo_width: Optional[int] = None,
|
|
|
|
photo_height: Optional[int] = None,
|
|
|
|
need_name: Optional[bool] = None,
|
|
|
|
need_phone_number: Optional[bool] = None,
|
|
|
|
need_email: Optional[bool] = None,
|
|
|
|
need_shipping_address: Optional[bool] = None,
|
|
|
|
send_phone_number_to_provider: Optional[bool] = None,
|
|
|
|
send_email_to_provider: Optional[bool] = None,
|
|
|
|
is_flexible: Optional[bool] = None,
|
2022-10-07 11:51:53 +02:00
|
|
|
*,
|
2023-05-18 07:57:59 +02:00
|
|
|
api_kwargs: Optional[JSONDict] = None,
|
2021-04-30 10:09:21 +02:00
|
|
|
):
|
2022-10-07 11:51:53 +02:00
|
|
|
super().__init__(api_kwargs=api_kwargs)
|
2023-01-01 13:04:37 +01:00
|
|
|
with self._unfrozen():
|
|
|
|
# Required
|
2023-02-02 18:55:07 +01:00
|
|
|
self.title: str = title
|
|
|
|
self.description: str = description
|
|
|
|
self.payload: str = payload
|
2024-06-03 19:39:31 +02:00
|
|
|
self.provider_token: Optional[str] = provider_token
|
2023-02-02 18:55:07 +01:00
|
|
|
self.currency: str = currency
|
|
|
|
self.prices: Tuple[LabeledPrice, ...] = parse_sequence_arg(prices)
|
2023-01-01 13:04:37 +01:00
|
|
|
# Optionals
|
2023-02-02 18:55:07 +01:00
|
|
|
self.max_tip_amount: Optional[int] = max_tip_amount
|
|
|
|
self.suggested_tip_amounts: Tuple[int, ...] = parse_sequence_arg(suggested_tip_amounts)
|
|
|
|
self.provider_data: Optional[str] = provider_data
|
|
|
|
self.photo_url: Optional[str] = photo_url
|
|
|
|
self.photo_size: Optional[int] = photo_size
|
|
|
|
self.photo_width: Optional[int] = photo_width
|
|
|
|
self.photo_height: Optional[int] = photo_height
|
|
|
|
self.need_name: Optional[bool] = need_name
|
|
|
|
self.need_phone_number: Optional[bool] = need_phone_number
|
|
|
|
self.need_email: Optional[bool] = need_email
|
|
|
|
self.need_shipping_address: Optional[bool] = need_shipping_address
|
|
|
|
self.send_phone_number_to_provider: Optional[bool] = send_phone_number_to_provider
|
|
|
|
self.send_email_to_provider: Optional[bool] = send_email_to_provider
|
|
|
|
self.is_flexible: Optional[bool] = is_flexible
|
2023-01-01 13:04:37 +01:00
|
|
|
|
|
|
|
self._id_attrs = (
|
|
|
|
self.title,
|
|
|
|
self.description,
|
|
|
|
self.payload,
|
|
|
|
self.provider_token,
|
|
|
|
self.currency,
|
|
|
|
self.prices,
|
|
|
|
)
|
2021-04-30 10:09:21 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def de_json(
|
|
|
|
cls, data: Optional[JSONDict], bot: "Bot"
|
|
|
|
) -> Optional["InputInvoiceMessageContent"]:
|
2021-05-27 09:38:17 +02:00
|
|
|
"""See :meth:`telegram.TelegramObject.de_json`."""
|
|
|
|
data = cls._parse_data(data)
|
2021-04-30 10:09:21 +02:00
|
|
|
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
data["prices"] = LabeledPrice.de_list(data.get("prices"), bot)
|
|
|
|
|
2022-10-07 11:51:53 +02:00
|
|
|
return super().de_json(data=data, bot=bot)
|