8000 Make `provider_token` Argument Optional by Bibo-Joshi · Pull Request #4689 · python-telegram-bot/python-telegram-bot · GitHub
[go: up one dir, main page]

Skip to content

Make provider_token Argument Optional #4689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/paymentbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ async def start_with_shipping_callback(update: Update, context: ContextTypes.DEF
title,
description,
payload,
PAYMENT_PROVIDER_TOKEN,
currency,
prices,
provider_token=PAYMENT_PROVIDER_TOKEN,
need_name=True,
need_phone_number=True,
need_email=True,
Expand All @@ -90,7 +90,13 @@ async def start_without_shipping_callback(
# optionally pass need_name=True, need_phone_number=True,
# need_email=True, need_shipping_address=True, is_flexible=True
await context.bot.send_invoice(
chat_id, title, description, payload, PAYMENT_PROVIDER_TOKEN, currency, prices
chat_id,
title,
description,
payload,
currency,
prices,
provider_token=PAYMENT_PROVIDER_TOKEN,
)


Expand Down
20 changes: 10 additions & 10 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5177,9 +5177,9 @@ async def send_invoice(
title: str,
description: str,
payload: str,
provider_token: Optional[str], # This arg is now optional as of Bot API 7.4
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
start_parameter: Optional[str] = None,
photo_url: Optional[str] = None,
photo_size: Optional[int] = None,
Expand Down Expand Up @@ -5232,13 +5232,13 @@ async def send_invoice(
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be
displayed to the user, use it for your internal processes.
provider_token (:obj:`str`): Payments provider token, obtained via
provider_token (:obj:`str`, optional): Payments provider token, obtained via
`@BotFather <https://t.me/BotFather>`_. Pass an empty string for payments in
|tg_stars|.

.. deprecated:: 21.3
As of Bot API 7.4, this parameter is now optional and future versions of the
library will make it optional as well.
.. versionchanged:: NEXT.VERSION
Bot API 7.4 made this parameter is optional and this is now reflected in the
function signature.

currency (:obj:`str`): Three-letter ISO 4217 currency code, see `more on currencies
<https://core.telegram.org/bots/payments#supported-currencies>`_. Pass ``XTR`` for
Expand Down Expand Up @@ -8252,9 +8252,9 @@ async def create_invoice_link(
title: str,
description: str,
payload: str,
provider_token: Optional[str], # This arg is now optional as of Bot API 7.4
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
provider_data: Optional[Union[str, object]] = None,
Expand Down Expand Up @@ -8296,13 +8296,13 @@ async def create_invoice_link(
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be
displayed to the user, use it for your internal processes.
provider_token (:obj:`str`): Payments provider token, obtained via
provider_token (:obj:`str`, optional): Payments provider token, obtained via
`@BotFather <https://t.me/BotFather>`_. Pass an empty string for payments in
|tg_stars|.

.. deprecated:: 21.3
As of Bot API 7.4, this parameter is now optional and future versions of the
library will make it optional as well.
.. versionchanged:: NEXT.VERSION
Bot API 7.4 made this parameter is optional and this is now reflected in the
function signature.

currency (:obj:`str`): Three-letter ISO 4217 currency code, see `more on currencies
<https://core.telegram.org/bots/payments#supported-currencies>`_. Pass ``XTR`` for
Expand Down
2 changes: 1 addition & 1 deletion telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,9 +1576,9 @@ async def send_invoice(
title: str,
description: str,
payload: str,
provider_token: Optional[str],
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
start_parameter: Optional[str] = None,
photo_url: Optional[str] = None,
photo_size: Optional[int] = None,
Expand Down
17 changes: 9 additions & 8 deletions telegram/_inline/inputinvoicemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class InputInvoiceMessageContent(InputMessageContent):

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.
:attr:`currency` and :attr:`prices` are equal.

.. versionadded:: 13.5
.. versionchanged:: NEXT.VERSION
:attr:`provider_token` is no longer considered for equality comparison.

Args:
title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`-
Expand All @@ -49,13 +51,13 @@ class InputInvoiceMessageContent(InputMessageContent):
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed
to the user, use it for your internal processes.
provider_token (:obj:`str`): Payment provider token, obtained via
provider_token (:obj:`str`, optional): Payment provider token, obtained via
`@Botfather <https://t.me/Botfather>`_. Pass an empty string for payments in
|tg_stars|.

.. deprecated:: 21.3
As of Bot API 7.4, this parameter is now optional and future versions of the
library will make it optional as well.
.. versionchanged:: NEXT.VERSION
Bot API 7.4 made this parameter is optional and this is now reflected in the
class signature.
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_.
Pass ``XTR`` for payments in |tg_stars|.
Expand Down Expand Up @@ -199,9 +201,9 @@ def __init__(
title: str,
description: str,
payload: str,
provider_token: Optional[str], # This arg is now optional since Bot API 7.4
currency: str,
prices: Sequence[LabeledPrice],
provider_token: Optional[str] = None,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
provider_data: Optional[str] = None,
Expand All @@ -225,10 +227,10 @@ def __init__(
self.title: str = title
self.description: str = description
self.payload: str = payload
self.provider_token: Optional[str] = provider_token
self.currency: str = currency
self.prices: tuple[LabeledPrice, ...] = parse_sequence_arg(prices)
# Optionals
self.provider_token: Optional[str] = provider_token
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
Expand All @@ -248,7 +250,6 @@ def __init__(
self.title,
self.description,
self.payload,
self.provider_token,
self.currency,
self.prices,
)
Expand Down
2 changes: 1 addition & 1 deletion telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3382,9 +3382,9 @@ async def reply_invoice(
title: str,
description: str,
payload: str,
provider_token: Optional[str],
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
start_parameter: Optional[str] = None,
photo_url: Optional[str] = None,
photo_size: Optional[int] = None,
Expand Down
2 changes: 1 addition & 1 deletion telegram/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,9 @@ async def send_invoice(
title: str,
description: str,
payload: str,
provider_token: Optional[str],
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
start_parameter: Optional[str] = None,
photo_url: Optional[str] = None,
photo_size: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions telegram/ext/_extbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,9 @@ async def create_invoice_link(
title: str,
description: str,
payload: str,
provider_token: Optional[str],
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
provider_data: Optional[Union[str, object]] = None,
Expand Down Expand Up @@ -2768,9 +2768,9 @@ async def send_invoice(
title: str,
description: str,
payload: str,
provider_token: Optional[str],
currency: str,
prices: Sequence["LabeledPrice"],
provider_token: Optional[str] = None,
start_parameter: Optional[str] = None,
photo_url: Optional[str] = None,
photo_size: Optional[int] = None,
Expand Down
2 changes: 1 addition & 1 deletion tests/_inline/test_inputinvoicemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ def test_equality(self):
self.title,
self.description,
self.payload,
self.provider_token,
self.currency,
# the first prices amount & the second lebal changed
[LabeledPrice("label1", 24), LabeledPrice("label22", 314)],
self.provider_token,
)
d = InputInvoiceMessageContent(
self.title,
Expand Down
9 changes: 4 additions & 5 deletions tests/_payment/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ async def test_send_invoice_default_protect_content(
self.title,
self.description,
self.payload,
provider_token,
self.currency,
self.prices,
provider_token,
**kwargs,
)
for kwargs in ({}, {"protect_content": False})
Expand Down Expand Up @@ -301,7 +301,6 @@ async def test_send_invoice_default_allow_sending_without_reply(
self.title,
self.description,
self.payload,
"", # using tg stars
"XTR",
[self.prices[0]],
allow_sending_without_reply=custom,
Expand All @@ -315,9 +314,9 @@ async def test_send_invoice_default_allow_sending_without_reply(
self.title,
self.description,
self.payload,
provider_token,
self.currency,
self.prices,
provider_token,
reply_to_message_id=reply_to_message.message_id,
)
assert message.reply_to_message is None
Expand All @@ -328,9 +327,9 @@ async def test_send_invoice_default_allow_sending_without_reply(
self.title,
self.description,
self.payload,
provider_token,
self.currency,
self.prices,
provider_token,
reply_to_message_id=reply_to_message.message_id,
)

Expand All @@ -340,9 +339,9 @@ async def test_send_all_args_send_invoice(self, bot, chat_id, provider_token):
self.title,
self.description,
self.payload,
provider_token,
self.currency,
self.prices,
provider_token=provider_token,
max_tip_amount=self.max_tip_amount,
suggested_tip_amounts=self.suggested_tip_amounts,
start_parameter=self.start_parameter,
Expand Down
2 changes: 1 addition & 1 deletion
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ async def make_assertion(*_, **kwargs):
"title",
"description",
"payload",
"provider_token",
"currency",
"prices",
"provider_token",
)

async def test_instance_method_send_location(self, monkeypatch, chat):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,9 +2216,9 @@ async def make_assertion(*_, **kwargs):
"title",
"description",
"payload",
"provider_token",
"currency",
"prices",
"provider_token",
)
await self.check_quote_parsing(
message,
Expand Down
4 changes: 1 addition & 3 deletions tests/test_official/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def ignored_param_requirements(object_name: str) -> set[str]:


# Arguments that are optional arguments for now for backwards compatibility
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {
"send_invoice|create_invoice_link|InputInvoiceMessageContent": {"provider_token"},
}
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {}


def backwards_compat_kwargs(object_name: str) -> set[str]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ async def make_assertion(*_, **kwargs):
"title",
"description",
"payload",
"provider_token",
"currency",
"prices",
"provider_token",
)

async def test_instance_method_send_location(self, monkeypatch, user):
Expand Down
Loading
0