Adding a payment bot in Telegram
Overview
You can create a payment bot in Telegram to allow your clients safely pay for products and goods right from the application. Your bot is connected to the Payment Provider bot that interacts with the Payment Gateway and allows to perform necessary payment operations.
As an example of a payment bot for a shop you can refer to @bpc_sandbox_shop_bot.
For better visibility, here is the video:
Typical scenario of using the bot:




Creating and connecting a bot
To start receiving payments in Telegram, follow these steps:
- Create an application for bot implementation using Bot Payments API (see the overview and the detailed API description).
- Open Telegram and register a bot using @BotFather, by running the
/newbot
command.- You will receive the message:
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
Enter the display name of the bot in Telegram, for example,Bank Acquiring Test Bot
. - You will receive the message:
Good. Now let's choose a username for your bot. It must end in 'bot'. Like this, for example: TetrisBot or tetris_bot.
Enter the internal name of the bot ending withbot
, for example,bank_acquiring_test_bot
. - You will receive the Telegram token of the bot (
BOT_TOKEN
) that should be passed in the URL of thesendInvoice
request (see Send invoice request).
- You will receive the message:
- Connect your bot to the Provider bot. To do it, enter
/payconnect
@<the_name_of_your_bot> @<bpc_sandbox_provider_bot>
command in @BotFather. - Go right to the Provider bot chat and press the
Start
button. In the dialog box of the Provider bot enter the merchant's login (merchantLogin
). As themerchantLogin
you can send thetest
phrase or your already knownmerchantLogin
. - Return to @BotFather – in the Payments section of the previously created bot, you will see the payment provider token (
PROVIDER_TOKEN
) that should be passed in thesendInvoice
request (see Send invoice request). - Enter the two issued tokens in the
BOT_TOKEN
andPROVIDER_TOKEN
fields in your associated application respectively. Save the changes and restart your bot. Further in the created bot after/start
command, it will be possible to call the command for payment (see Send invoice request). - Your bot can be used for testing or accepting payments in accordance with the scenario implemented in the bot.
Send invoice request
When you send sendInvoice request from your bot application to Telegram API, you must pass:
-
BOT_TOKEN
value received at step 2 - in the request URL, -
PROVIDER_TOKEN
value received at step 5 - in theprovider_token
parameter of the request.
Example:
POST https://api.telegram.org/bot<BOT_TOKEN>/sendInvoice
Content-Type: application/json
{
"chat_id": 123456789,
"title": "Item name",
"description": "Item description",
"payload": "Unique identifier",
"provider_token": "PROVIDER_TOKEN",
....
}