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