X Tutup
Skip to content

Commit 8e62b02

Browse files
committed
Add new payment classes
Invoice, LabeledPrice, OrderInfo, PreCheckoutQuery, ShippingAddress, ShippingOption, ShippingQuery and SuccessfulPayment
1 parent 9720f59 commit 8e62b02

File tree

9 files changed

+567
-1
lines changed

9 files changed

+567
-1
lines changed

telegram/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@
8484
from .inputlocationmessagecontent import InputLocationMessageContent
8585
from .inputvenuemessagecontent import InputVenueMessageContent
8686
from .inputcontactmessagecontent import InputContactMessageContent
87+
from .labeledprice import LabeledPrice
88+
from .successfulpayment import SuccessfulPayment
89+
from .shippingoption import ShippingOption
90+
from .shippingaddress import ShippingAddress
91+
from .precheckoutquery import PreCheckoutQuery
92+
from .orderinfo import OrderInfo
93+
from .shippingquery import ShippingQuery
94+
from .invoice import Invoice
8795
from .webhookinfo import WebhookInfo
8896
from .gamehighscore import GameHighScore
8997
from .update import Update
@@ -115,5 +123,6 @@
115123
'Video', 'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
116124
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
117125
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo', 'Animation',
118-
'Game', 'GameHighScore'
126+
'Game', 'GameHighScore', 'LabeledPrice', 'SuccessfulPayment', 'ShippingOption',
127+
'ShippingAddress', 'PreCheckoutQuery', 'OrderInfo', 'Invoice', 'ShippingQuery'
119128
]

telegram/invoice.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 Invoice."""
20+
21+
from telegram import TelegramObject
22+
23+
24+
class Invoice(TelegramObject):
25+
"""This object contains basic information about an invoice.
26+
27+
Attributes:
28+
title (str): Product name
29+
description (str): Product description
30+
start_parameter (str): Unique bot deep-linking parameter that can
31+
be used to generate this invoice
32+
currency (str): Three-letter ISO 4217 currency code
33+
total_amount (int): Total price in the smallest units of the currency (integer)
34+
35+
"""
36+
37+
def __init__(self, title, description, start_parameter, currency, total_amount):
38+
self.title = title
39+
self.description = description
40+
self.start_parameter = start_parameter
41+
self.currency = currency
42+
self.total_amount = total_amount
43+
44+
@staticmethod
45+
def de_json(data, bot):
46+
"""
47+
Args:
48+
data (dict):
49+
bot (telegram.Bot):
50+
51+
Returns:
52+
telegram.Invoice:
53+
"""
54+
if not data:
55+
return None
56+
57+
return Invoice(**data)

telegram/labeledprice.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 LabeledPrice."""
20+
21+
from telegram import TelegramObject
22+
23+
24+
class LabeledPrice(TelegramObject):
25+
"""This object represents a portion of the price for goods or services.
26+
27+
Attributes:
28+
label (str): Portion label
29+
amount (int): Price of the product in the smallest units of the currency (integer)
30+
"""
31+
32+
def __init__(self, label, amount):
33+
self.label = label
34+
self.amount = amount
35+
36+
@staticmethod
37+
def de_json(data, bot):
38+
"""
39+
Args:
40+
data (dict):
41+
bot (telegram.Bot):
42+
43+
Returns:
44+
telegram.LabeledPrice:
45+
46+
"""
47+
if not data:
48+
return None
49+
50+
return LabeledPrice(**data)
51+
52+
@staticmethod
53+
def de_list(data, bot):
54+
"""
55+
Args:
56+
data (list):
57+
bot (telegram.Bot):
58+
59+
Returns:
60+
List<telegram.PhotoSize>:
61+
"""
62+
if not data:
63+
return []
64+
65+
labeled_prices = list()
66+
for labeled_price in data:
67+
labeled_prices.append(LabeledPrice.de_json(labeled_price, bot))
68+
69+
return labeled_prices

telegram/orderinfo.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 OrderInfo."""
20+
21+
from telegram import TelegramObject, ShippingAddress
22+
23+
24+
class OrderInfo(TelegramObject):
25+
"""This object represents information about an order.
26+
27+
Attributes:
28+
name (Optional[str]): User name
29+
phone_number (Optional[str]): User's phone number
30+
email (Optional[str]): User email
31+
shipping_address (Optional[:class:`telegram.ShippingAddress`]): User shipping address
32+
33+
"""
34+
35+
def __init__(self, name=None, phone_number=None, email=None, shipping_address=None):
36+
self.name = name
37+
self.phone_number = phone_number
38+
self.email = email
39+
self.shipping_address = shipping_address
40+
41+
@staticmethod
42+
def de_json(data, bot):
43+
"""
44+
Args:
45+
data (dict):
46+
bot (telegram.Bot):
47+
48+
Returns:
49+
telegram.OrderInfo:
50+
"""
51+
if not data:
52+
return None
53+
54+
data = super(OrderInfo, OrderInfo).de_json(data, bot)
55+
56+
data['shipping_address'] = ShippingAddress.de_json(data.get('shipping_address'), bot)
57+
58+
return OrderInfo(**data)

telegram/precheckoutquery.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

telegram/shippingaddress.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 ShippingAddress."""
20+
21+
from telegram import TelegramObject
22+
23+
24+
class ShippingAddress(TelegramObject):
25+
"""This object represents a Telegram ShippingAddress.
26+
27+
Attributes:
28+
country_code (str): ISO 3166-1 alpha-2 country code
29+
state (str): State, if applicable
30+
city (str): City
31+
street_line1 (str): First line for the address
32+
street_line2 (str): Second line for the address
33+
post_code (str): Address post code
34+
35+
"""
36+
37+
def __init__(self, country_code, state, city, street_line1, street_line2, post_code):
38+
self.country_code = country_code
39+
self.state = state
40+
self.city = city
41+
self.street_line1 = street_line1
42+
self.street_line2 = street_line2
43+
self.post_code = post_code
44+
45+
self._id_attrs = (self.country_code, self.state, self.city, self.street_line1,
46+
self.street_line2, self.post_code)
47+
48+
@staticmethod
49+
def de_json(data, bot):
50+
"""
51+
Args:
52+
data (dict):
53+
bot (telegram.Bot):
54+
55+
Returns:
56+
telegram.ShippingAddress:
57+
"""
58+
if not data:
59+
return None
60+
61+
return ShippingAddress(**data)

0 commit comments

Comments
 (0)
X Tutup