@@ -148,9 +148,11 @@ def de_json(cls, json_string):
148148 max_connections = obj ['max_connections' ]
149149 if 'allowed_updates' in obj :
150150 allowed_updates = obj ['allowed_updates' ]
151- return cls (url , has_custom_certificate , pending_update_count , last_error_date , last_error_message , max_connections , allowed_updates )
151+ return cls (url , has_custom_certificate , pending_update_count , last_error_date , last_error_message ,
152+ max_connections , allowed_updates )
152153
153- def __init__ (self , url , has_custom_certificate , pending_update_count , last_error_date , last_error_message , max_connections , allowed_updates ):
154+ def __init__ (self , url , has_custom_certificate , pending_update_count , last_error_date , last_error_message ,
155+ max_connections , allowed_updates ):
154156 self .url = url
155157 self .has_custom_certificate = has_custom_certificate
156158 self .pending_update_count = pending_update_count
@@ -1608,3 +1610,167 @@ def __init__(self, position, user, score):
16081610 self .position = position
16091611 self .user = user
16101612 self .score = score
1613+
1614+
1615+ # Payments
1616+
1617+ class LabeledPrice (JsonSerializable ):
1618+ def __init__ (self , label , amount ):
1619+ self .label = label
1620+ self .amount = amount
1621+
1622+ def to_json (self ):
1623+ return json .dumps (self .to_dic ())
1624+
1625+ def to_dic (self ):
1626+ return {'label' : self .label , 'amount' : self .amount }
1627+
1628+
1629+ class Invoice (JsonDeserializable ):
1630+ @classmethod
1631+ def de_json (cls , json_string ):
1632+ obj = cls .check_json (json_string )
1633+ title = obj ['title' ]
1634+ description = obj ['description' ]
1635+ start_parameter = obj ['start_parameter' ]
1636+ currency = obj ['currency' ]
1637+ total_amount = obj ['total_amount' ]
1638+ return cls (title , description , start_parameter , currency , total_amount )
1639+
1640+ def __init__ (self , title , description , start_parameter , currency , total_amount ):
1641+ self .title = title
1642+ self .description = description
1643+ self .start_parameter = start_parameter
1644+ self .currency = currency
1645+ self .total_amount = total_amount
1646+
1647+
1648+ class ShippingAddress (JsonDeserializable ):
1649+ @classmethod
1650+ def de_json (cls , json_string ):
1651+ obj = cls .check_json (json_string )
1652+ country_code = obj ['country_code' ]
1653+ state = obj ['state' ]
1654+ city = obj ['city' ]
1655+ street_line1 = obj ['street_line1' ]
1656+ street_line2 = obj ['street_line2' ]
1657+ post_code = obj ['post_code' ]
1658+ return cls (country_code , state , city , street_line1 , street_line2 , post_code )
1659+
1660+ def __init__ (self , country_code , state , city , street_line1 , street_line2 , post_code ):
1661+ self .country_code = country_code
1662+ self .state = state
1663+ self .city = city
1664+ self .street_line1 = street_line1
1665+ self .street_line2 = street_line2
1666+ self .post_code = post_code
1667+
1668+
1669+ class OrderInfo (JsonDeserializable ):
1670+ @classmethod
1671+ def de_json (cls , json_string ):
1672+ obj = cls .check_json (json_string )
1673+ name = obj .get ('name' )
1674+ phone_number = obj .get ('phone_number' )
1675+ email = obj .get ('email' )
1676+ shipping_address = None
1677+ if 'shipping_address' in obj :
1678+ shipping_address = ShippingAddress .de_json (obj ['shipping_address' ])
1679+ return cls (name , phone_number , email , shipping_address )
1680+
1681+ def __init__ (self , name , phone_number , email , shipping_address ):
1682+ self .name = name
1683+ self .phone_number = phone_number
1684+ self .email = email
1685+ self .shipping_address = shipping_address
1686+
1687+
1688+ class ShippingOption (JsonSerializable ):
1689+ def __init__ (self , id , title ):
1690+ self .id = id
1691+ self .title = title
1692+ self .prices = []
1693+
1694+ def add_price (self , * args ):
1695+ """
1696+ Add LabeledPrice to ShippingOption
1697+ :param args: LabeledPrices
1698+ """
1699+ for price in args :
1700+ self .prices .append (price )
1701+
1702+ def to_json (self ):
1703+ price_list = []
1704+ for p in self .prices :
1705+ price_list .append (p .to_dic ())
1706+ json_dict = {'id' : self .id , 'title' : self .title , 'prices' : price_list }
1707+ return json_dict
1708+
1709+
1710+ class SuccessfulPayment (JsonDeserializable ):
1711+ @classmethod
1712+ def de_json (cls , json_string ):
1713+ obj = cls .check_json (json_string )
1714+ currency = obj ['currency' ]
1715+ total_amount = obj ['total_amount' ]
1716+ invoice_payload = obj ['invoice_payload' ]
1717+ shipping_option_id = obj .get ('shipping_option_id' )
1718+ order_info = None
1719+ if 'order_info' in obj :
1720+ order_info = OrderInfo .de_json (obj ['order_info' ])
1721+ telegram_payment_charge_id = obj ['telegram_payment_charge_id' ]
1722+ provider_payment_charge_id = obj ['provider_payment_charge_id' ]
1723+ return cls (currency , total_amount , invoice_payload , shipping_option_id , order_info ,
1724+ telegram_payment_charge_id , provider_payment_charge_id )
1725+
1726+ def __init__ (self , currency , total_amount , invoice_payload , shipping_option_id , order_info ,
1727+ telegram_payment_charge_id , provider_payment_charge_id ):
1728+ self .currency = currency
1729+ self .total_amount = total_amount
1730+ self .invoice_payload = invoice_payload
1731+ self .shipping_option_id = shipping_option_id
1732+ self .order_info = order_info
1733+ self .telegram_payment_charge_id = telegram_payment_charge_id
1734+ self .provider_payment_charge_id = provider_payment_charge_id
1735+
1736+
1737+ class ShippingQuery (JsonDeserializable ):
1738+ @classmethod
1739+ def de_json (cls , json_string ):
1740+ obj = cls .check_json (json_string )
1741+ id = obj ['id' ]
1742+ from_user = User .de_json (obj ['from' ])
1743+ invoice_payload = obj ['invoice_payload' ]
1744+ shipping_address = ShippingAddress .de_json (obj ['shipping_address' ])
1745+ return cls (id , from_user , invoice_payload , shipping_address )
1746+
1747+ def __init__ (self , id , from_user , invoice_payload , shipping_address ):
1748+ self .id = id
1749+ self .from_user = from_user
1750+ self .invoice_payload = invoice_payload
1751+ self .shipping_address = shipping_address
1752+
1753+
1754+ class PreCheckoutQuery (JsonDeserializable ):
1755+ @classmethod
1756+ def de_json (cls , json_string ):
1757+ obj = cls .check_json (json_string )
1758+ id = obj ['id' ]
1759+ from_user = User .de_json (obj ['from' ])
1760+ currency = obj ['currency' ]
1761+ total_amount = obj ['total_amount' ]
1762+ invoice_payload = obj ['invoice_payload' ]
1763+ shipping_option_id = obj .get ('shipping_option_id' )
1764+ order_info = None
1765+ if 'order_info' in obj :
1766+ order_info = OrderInfo .de_json (obj ['order_info' ])
1767+ return cls (id , from_user , currency , total_amount , invoice_payload , shipping_option_id , order_info )
1768+
1769+ def __init__ (self , id , from_user , currency , total_amount , invoice_payload , shipping_option_id , order_info ):
1770+ self .id = id
1771+ self .from_user = from_user
1772+ self .currency = currency
1773+ self .total_amount = total_amount
1774+ self .invoice_payload = invoice_payload
1775+ self .shipping_option_id = shipping_option_id
1776+ self .order_info = order_info
0 commit comments