|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +import pyrogram |
| 20 | +from pyrogram import raw |
| 21 | + |
| 22 | + |
| 23 | +class AnswerPreCheckoutQuery: |
| 24 | + async def answer_pre_checkout_query( |
| 25 | + self: "pyrogram.Client", |
| 26 | + pre_checkout_query_id: str, |
| 27 | + ok: bool, |
| 28 | + error_message: str = None |
| 29 | + ): |
| 30 | + """Once the user has confirmed their payment and shipping details, the API sends the final confirmation in the form of an :obj:`~pyrogram.handlers.PreCheckoutQueryHandler`. |
| 31 | + |
| 32 | + Use this method to respond to such pre-checkout queries. |
| 33 | +
|
| 34 | + **Note**: The API must receive an answer within 10 seconds after the pre-checkout query was sent. |
| 35 | +
|
| 36 | + .. include:: /_includes/usable-by/bots.rst |
| 37 | +
|
| 38 | + Parameters: |
| 39 | + pre_checkout_query_id (``str``): |
| 40 | + Unique identifier for the query to be answered. |
| 41 | +
|
| 42 | + ok (``bool``): |
| 43 | + Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. |
| 44 | +
|
| 45 | + error_message (``str``, *optional*): |
| 46 | + Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. |
| 47 | +
|
| 48 | + Returns: |
| 49 | + ``bool``: True, on success. |
| 50 | +
|
| 51 | + Example: |
| 52 | + .. code-block:: python |
| 53 | +
|
| 54 | + # Proceed with the order |
| 55 | + await app.answer_pre_checkout_query(query_id, ok=True) |
| 56 | +
|
| 57 | + # Answer with error message |
| 58 | + await app.answer_pre_checkout_query(query_id, ok=False, error_message="Error Message displayed to the user") |
| 59 | +
|
| 60 | + """ |
| 61 | + return await self.invoke( |
| 62 | + raw.functions.messages.SetBotPrecheckoutResults( |
| 63 | + query_id=int(pre_checkout_query_id), |
| 64 | + success=ok or None, |
| 65 | + error=error_message or None |
| 66 | + ) |
| 67 | + ) |
0 commit comments