mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
Add PreCheckoutQuery.answer
This commit is contained in:
parent
65002b9280
commit
cf12da0c4a
4 changed files with 47 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ from .base import TelegramObject
|
|||
if TYPE_CHECKING: # pragma: no cover
|
||||
from .order_info import OrderInfo
|
||||
from .user import User
|
||||
from ..methods import AnswerPreCheckoutQuery
|
||||
|
||||
|
||||
class PreCheckoutQuery(TelegramObject):
|
||||
|
|
@ -35,3 +36,15 @@ class PreCheckoutQuery(TelegramObject):
|
|||
"""Identifier of the shipping option chosen by the user"""
|
||||
order_info: Optional[OrderInfo] = None
|
||||
"""Order info provided by the user"""
|
||||
|
||||
def answer(self, ok: bool, error_message: Optional[str] = None) -> AnswerPreCheckoutQuery:
|
||||
"""
|
||||
:param ok:
|
||||
:param error_message:
|
||||
:return:
|
||||
"""
|
||||
from ..methods import AnswerPreCheckoutQuery
|
||||
|
||||
return AnswerPreCheckoutQuery(
|
||||
pre_checkout_query_id=self.id, ok=ok, error_message=error_message,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -56,3 +56,5 @@ return AnswerPreCheckoutQuery(...)
|
|||
## Related pages:
|
||||
|
||||
- [Official documentation](https://core.telegram.org/bots/api#answerprecheckoutquery)
|
||||
- [aiogram.types.PreCheckoutQuery](../types/pre_checkout_query.md)
|
||||
- [Aliases](../types/pre_checkout_query.md#aliases)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,22 @@ This object contains information about an incoming pre-checkout query.
|
|||
- `from aiogram.api.types import PreCheckoutQuery`
|
||||
- `from aiogram.api.types.pre_checkout_query import PreCheckoutQuery`
|
||||
|
||||
## Aliases
|
||||
|
||||
Aliases is always returns related API method (Awaitable) and can be used directly or as answer's into webhook.
|
||||
|
||||
### Answer
|
||||
|
||||
This method has the same specification with the API but without `pre_checkout_query_id` argument.
|
||||
|
||||
| Answer method | Alias for | Description |
|
||||
| - | - | - |
|
||||
| `answer` | [Bot.answer_pre_checkout_query](../methods/answer_pre_checkout_query.md) | Answer to pre checkout query |
|
||||
|
||||
|
||||
## Related pages:
|
||||
|
||||
- [Official documentation](https://core.telegram.org/bots/api#precheckoutquery)
|
||||
- [aiogram.types.OrderInfo](../types/order_info.md)
|
||||
- [aiogram.types.User](../types/user.md)
|
||||
- [aiogram.methods.AnswerPreCheckoutQuery](../methods/answer_pre_checkout_query.md)
|
||||
|
|
|
|||
18
tests/test_api/test_types/test_pre_checkout_query.py
Normal file
18
tests/test_api/test_types/test_pre_checkout_query.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from aiogram.api.methods import AnswerPreCheckoutQuery
|
||||
from aiogram.api.types import PreCheckoutQuery, User
|
||||
|
||||
|
||||
class TestPreCheckoutQuery:
|
||||
def test_answer_alias(self):
|
||||
pre_checkout_query = PreCheckoutQuery(
|
||||
id="id",
|
||||
from_user=User(id=42, is_bot=False, first_name="name"),
|
||||
currency="currency",
|
||||
total_amount=123,
|
||||
invoice_payload="payload",
|
||||
)
|
||||
|
||||
api_method = pre_checkout_query.answer(True)
|
||||
|
||||
assert isinstance(api_method, AnswerPreCheckoutQuery)
|
||||
assert api_method.pre_checkout_query_id == pre_checkout_query.id
|
||||
Loading…
Add table
Add a link
Reference in a new issue