@@ -1818,6 +1818,214 @@ def get_game_high_scores(self,
18181818
18191819 return [GameHighScore .de_json (hs , self ) for hs in result ]
18201820
1821+ @log
1822+ @message
1823+ def send_invoice (self ,
1824+ chat_id ,
1825+ title ,
1826+ description ,
1827+ payload ,
1828+ provider_token ,
1829+ start_parameter ,
1830+ currency ,
1831+ prices ,
1832+ photo_url = None ,
1833+ photo_size = None ,
1834+ photo_width = None ,
1835+ photo_height = None ,
1836+ need_name = None ,
1837+ need_phone_number = None ,
1838+ need_email = None ,
1839+ need_shipping_address = None ,
1840+ is_flexible = None ,
1841+ disable_notification = False ,
1842+ reply_to_message_id = None ,
1843+ reply_markup = None ,
1844+ timeout = None ,
1845+ ** kwargs ):
1846+ """
1847+ Use this method to send invoices.
1848+
1849+ Args:
1850+ chat_id (int|str): Unique identifier for the target private chat
1851+ title (str): Product name
1852+ description (str): Product description
1853+ payload (str): Bot-defined invoice payload, 1-128 bytes. This will not be displayed
1854+ to the user, use for your internal processes.
1855+ provider_token (str): Payments provider token, obtained via Botfather
1856+ start_parameter (str): Unique deep-linking parameter that can be used to generate
1857+ this invoice when used as a start parameter
1858+ currency (str): Three-letter ISO 4217 currency code
1859+ prices (List[:class:`telegram.LabeledPrice`]): Price breakdown, a list of components
1860+ (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
1861+ photo_url (Optional[str]): URL of the product photo for the invoice. Can be a photo of
1862+ the goods or a marketing image for a service. People like it better when they
1863+ see what they are paying for.
1864+ photo_size (Optional[str]): Photo size
1865+ photo_width (Optional[int]): Photo width
1866+ photo_height (Optional[int]): Photo height
1867+ need_name (Optional[bool]): Pass True, if you require the user's full name to complete
1868+ the order
1869+ need_phone_number (Optional[bool]): Pass True, if you require the user's phone number
1870+ to complete the order
1871+ need_email (Optional[bool]): Pass True, if you require the user's email to
1872+ complete the order
1873+ need_shipping_address (Optional[bool]): Pass True, if you require the user's shipping
1874+ address to complete the order
1875+ is_flexible (Optional[bool]): Pass True, if the final price depends on the shipping
1876+ method
1877+ disable_notification (Optional[bool]): Sends the message silently. iOS users will not
1878+ receive a notification, Android users will receive a notification with no sound.
1879+ reply_to_message_id (Optional[int]): If the message is a reply, ID of the original
1880+ message.
1881+ reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options.
1882+ An inlinekeyboard. If empty, one 'Pay total price' button will be shown. If not
1883+ empty, the first button must be a Pay button.
1884+ timeout (Optional[int|float]): If this value is specified, use it as the read timeout
1885+ from the server (instead of the one specified during creation of the connection
1886+ pool).
1887+ **kwargs (dict): Arbitrary keyword arguments.
1888+
1889+ Returns:
1890+ :class:`telegram.Message`: On success, instance representing the message posted.
1891+
1892+ Raises:
1893+ :class:`telegram.TelegramError`
1894+
1895+ """
1896+ url = '{0}/sendInvoice' .format (self .base_url )
1897+
1898+ data = {
1899+ 'chat_id' : chat_id ,
1900+ 'title' : title ,
1901+ 'description' : description ,
1902+ 'payload' : payload ,
1903+ 'provider_token' : provider_token ,
1904+ 'start_parameter' : start_parameter ,
1905+ 'currency' : currency ,
1906+ 'prices' : [p .to_dict () for p in prices ]
1907+ }
1908+
1909+ if photo_url is not None :
1910+ data ['photo_url' ] = photo_url
1911+ if photo_size is not None :
1912+ data ['photo_size' ] = photo_size
1913+ if photo_width is not None :
1914+ data ['photo_width' ] = photo_width
1915+ if photo_height is not None :
1916+ data ['photo_height' ] = photo_height
1917+ if need_name is not None :
1918+ data ['need_name' ] = need_name
1919+ if need_phone_number is not None :
1920+ data ['need_phone_number' ] = need_phone_number
1921+ if need_email is not None :
1922+ data ['need_email' ] = need_email
1923+ if need_shipping_address is not None :
1924+ data ['need_shipping_address' ] = need_shipping_address
1925+ if is_flexible is not None :
1926+ data ['is_flexible' ] = is_flexible
1927+
1928+ return url , data
1929+
1930+ def answer_shipping_query (self ,
1931+ shipping_query_id ,
1932+ ok ,
1933+ shipping_options = None ,
1934+ error_message = None ,
1935+ timeout = None ,
1936+ ** kwargs ):
1937+ """
1938+ If you sent an invoice requesting a shipping address and the parameter is_flexible was
1939+ specified, the Bot API will send an Update with a shipping_query field to the bot. Use
1940+ this method to reply to shipping queries.
1941+
1942+ Args:
1943+ shipping_query_id (str): Unique identifier for the query to be answered
1944+ ok (bool): Specify True if delivery to the specified address is possible and False if
1945+ there are any problems (for example, if delivery to the specified address
1946+ is not possible)
1947+ shipping_options (Optional[List[:class:`telegram.ShippingOption`]]): Required if ok is
1948+ True. A list of available shipping options.
1949+ error_message (Optional[str]): Required if ok is False. Error message in human readable
1950+ form that explains why it is impossible to complete the order (e.g. "Sorry,
1951+ delivery to your desired address is unavailable'). Telegram will display this
1952+ message to the user.
1953+ **kwargs (dict): Arbitrary keyword arguments.
1954+
1955+ Returns:
1956+ bool: On success, `True` is returned.
1957+
1958+ Raises:
1959+ :class:`telegram.TelegramError`
1960+
1961+ """
1962+
1963+ if ok is True and (shipping_options is None or error_message is not None ):
1964+ raise TelegramError (
1965+ 'answerShippingQuery: If ok is True, shipping_options '
1966+ 'should not be empty and there should not be error_message' )
1967+
1968+ if ok is False and (shipping_options is not None or error_message is None ):
1969+ raise TelegramError (
1970+ 'answerShippingQuery: If ok is False, error_message '
1971+ 'should not be empty and there should not be shipping_options' )
1972+
1973+ url_ = '{0}/answerShippingQuery' .format (self .base_url )
1974+
1975+ data = {'shipping_query_id' : shipping_query_id , 'ok' : ok }
1976+
1977+ if ok is True :
1978+ data ['shipping_options' ] = shipping_options
1979+ if error_message is not None :
1980+ data ['error_message' ] = error_message
1981+
1982+ result = self ._request .post (url_ , data , timeout = timeout )
1983+
1984+ return result
1985+
1986+ def answer_pre_checkout_query (self , pre_checkout_query_id , ok ,
1987+ error_message = None , timeout = None , ** kwargs ):
1988+ """
1989+ If you sent an invoice requesting a shipping address and the parameter is_flexible was
1990+ specified, the Bot API will send an Update with a shipping_query field to the bot.
1991+ Use this method to reply to shipping queries.
1992+
1993+ Args:
1994+ pre_checkout_query_id (str): Unique identifier for the query to be answered
1995+ ok (bool): Specify True if everything is alright (goods are available, etc.) and the
1996+ bot is ready to proceed with the order. Use False if there are any problems.
1997+ error_message (Optional[str]): Required if ok is False. Error message in human readable
1998+ form that explains the reason for failure to proceed with the checkout (e.g.
1999+ "Sorry, somebody just bought the last of our amazing black T-shirts while you were
2000+ busy filling out your payment details. Please choose a different color or
2001+ garment!"). Telegram will display this message to the user.
2002+ **kwargs (dict): Arbitrary keyword arguments.
2003+
2004+ Returns:
2005+ bool: On success, `True` is returned.
2006+
2007+ Raises:
2008+ :class:`telegram.TelegramError`
2009+
2010+ """
2011+
2012+ if not (ok ^ (error_message is None )):
2013+ raise TelegramError (
2014+ 'answerPreCheckoutQuery: If ok is True, there should '
2015+ 'not be error_message; if ok is False, error_message '
2016+ 'should not be empty' )
2017+
2018+ url_ = '{0}/answerPreCheckoutQuery' .format (self .base_url )
2019+
2020+ data = {'pre_checkout_query_id' : pre_checkout_query_id , 'ok' : ok }
2021+
2022+ if error_message is not None :
2023+ data ['error_message' ] = error_message
2024+
2025+ result = self ._request .post (url_ , data , timeout = timeout )
2026+
2027+ return result
2028+
18212029 @staticmethod
18222030 def de_json (data , bot ):
18232031 data = super (Bot , Bot ).de_json (data , bot )
@@ -1873,3 +2081,6 @@ def __reduce__(self):
18732081 getWebhookInfo = get_webhook_info
18742082 setGameScore = set_game_score
18752083 getGameHighScores = get_game_high_scores
2084+ sendInvoice = send_invoice
2085+ answerShippingQuery = answer_shipping_query
2086+ answerPreCheckoutQuery = answer_pre_checkout_query
0 commit comments