|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# A library that provides a Python interface to the Telegram Bot API |
| 4 | +# Copyright (C) 2015-2017 |
| 5 | +# Leandro Toledo de Souza <devs@python-telegram-bot.org> |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser Public License |
| 18 | +# along with this program. If not, see [http://www.gnu.org/licenses/]. |
| 19 | +"""This module contains an object that represents a Telegram PreCheckoutQuery.""" |
| 20 | + |
| 21 | +from telegram import TelegramObject, User, OrderInfo |
| 22 | + |
| 23 | + |
| 24 | +class PreCheckoutQuery(TelegramObject): |
| 25 | + """This object contains information about an incoming pre-checkout query. |
| 26 | +
|
| 27 | + Note: |
| 28 | + * In Python `from` is a reserved word, use `from_user` instead. |
| 29 | +
|
| 30 | + Attributes: |
| 31 | + id (int): Unique query identifier |
| 32 | + from_user (:class:`telegram.User`): User who sent the query |
| 33 | + currency (str): Three-letter ISO 4217 currency code |
| 34 | + total_amount (int): Total price in the smallest units of the currency (integer) |
| 35 | + invoice_payload (str): Bot specified invoice payload |
| 36 | +
|
| 37 | + Keyword Args: |
| 38 | + shipping_option_id (Optional[str]): Identifier of the shipping option chosen by the user |
| 39 | + order_info (Optional[:class:`telegram.OrderInfo`]): Order info provided by the user |
| 40 | +
|
| 41 | + """ |
| 42 | + |
| 43 | + def __init__(self, |
| 44 | + id, |
| 45 | + from_user, |
| 46 | + currency, |
| 47 | + total_amount, |
| 48 | + invoice_payload, |
| 49 | + shipping_option_id=None, |
| 50 | + order_info=None): |
| 51 | + self.id = id |
| 52 | + self.from_user = from_user |
| 53 | + self.currency = currency |
| 54 | + self.total_amount = total_amount |
| 55 | + self.invoice_payload = invoice_payload |
| 56 | + self.shipping_option_id = shipping_option_id |
| 57 | + self.order_info = order_info |
| 58 | + |
| 59 | + self._id_attrs = (self.id,) |
| 60 | + |
| 61 | + @staticmethod |
| 62 | + def de_json(data, bot): |
| 63 | + """ |
| 64 | + Args: |
| 65 | + data (dict): |
| 66 | + bot (telegram.Bot): |
| 67 | +
|
| 68 | + Returns: |
| 69 | + telegram.PreCheckoutQuery: |
| 70 | + """ |
| 71 | + if not data: |
| 72 | + return None |
| 73 | + |
| 74 | + data = super(PreCheckoutQuery, PreCheckoutQuery).de_json(data, bot) |
| 75 | + |
| 76 | + data['from_user'] = User.de_json(data.get('from'), bot) |
| 77 | + data['order_info'] = OrderInfo.de_json(data.get('order_info'), bot) |
| 78 | + |
| 79 | + return PreCheckoutQuery(**data) |
| 80 | + |
| 81 | + def to_dict(self): |
| 82 | + """ |
| 83 | + Returns: |
| 84 | + dict: |
| 85 | + """ |
| 86 | + data = super(PreCheckoutQuery, self).to_dict() |
| 87 | + |
| 88 | + data['from'] = data.pop('from_user', None) |
| 89 | + |
| 90 | + return data |
0 commit comments