Setting up payments via Telegram bot
To accept payments via Telegram, you'll need to do three things:
How to create a bot
- Open the chat with @BotFather in Telegram, click "Start" (/start command), then /newbot.
- Give the bot a name and a username. The bot's name will be shown in the contact list and at the top of the chat, it can be non-unique. The username will be in the short link to the bot, and it must be unique.
- Example:
- YooMoney: payments is the bot's name
- YooMoneyPaymentBot is the bot's username
- If the username isn't taken, BotFather will respond to you with the token, i.e. the "key" to access the created bot. Don't give this token to anyone else, even the YooMoney's or Telegram's support services.Once you have the key, the bot is ready: you can add an icon and configure the dialog patterns for customers. You can also set up payments via the bot.
How to connect your bot to the YooMoney bot
Before connecting, make sure your store is running on the base of the API protocol. You can check this in the settings, under the Store section
If there's another protocol specified in the settings (or there's no protocol field at all), contact us via email merchants@yoomoney.ru or call us at 8 800 350-46-56. We'll configure the API for your store. Please, specify the ShopID of the store which needs to be linked to the bot in the email.
- Send the /mybots command to @BotFather. Click on your bot's name.
- This will open the bot's dashboard. Select Payments.
- If you'd like to set up real payments right away, select Connect YooMoney: payments in the menu. If you'd like to test payments first, select Connect YooMoney: test.
- This will open the chat with the YooMoney bot, click "Start". After that, select "Sign in and grant access", authorize in YooMoney, and allow the bot to send data from your Merchant Profile.
- If you need to change store, enter "/start" and click "Change store".
- Return to the chat with @BotFather. It'll send you the token required for payment acceptance. You can always view the token via BotSettings → Payments.
Setting up the bot to process payments
Next we'll talk about setting up a bot via the Telegram API. If you're using a bot builder (Manybot, Botobot, Botmaker, or any other), follow its instructions.
- Implement the sendinvoice method from the Telegram payment API: your bot will start sending invoices to customers in response to this request. Invoices should include the price, name, product description,
payload
parameter, andprovider_token
parameter which is the token provided by @BotFather after you connected your bot to the YooMoney bot. Please note that payments for the demo store should not exceed 1,000 rubles.View example of a sendinvoice requestIf you set up fiscalization via YooMoney**, you'll need to send data for fiscalization to YooMoney. To do this, add the following parameters to the request:need_phone_number
orneed_email
send_email_to_provider
(if you requested an email address from the customer) orsend_phone_number_to_provider
(if you requested a phone number from the customer),provider_data
with thereceipt
object. Learn more in the YooMoney API (see Attributes section — receipt).
See an exampleYou can request the customer's phone number or email address earlier, during the chat with the bot. Then the first two parameters are not required, andprovider_data
with thereceipt
object would be enough.See an exampleIf you need the customer to provide you with an address for delivery, implement the Shipping Query method. When the user provides the address, respond to this query with the answerShippingQuery method. Indicate the delivery methods and their prices in this method. - When the user confirms the payment, Telegram will send you a webhook with Update containing the PreCheckoutQuery object. You need to respond to this query within 10 seconds by calling the answerPreCheckoutQuery method.
- If the payment is successful, you'll receive two notifications: one from Telegram (webhook with SuccessfulPayment object) and one from YooMoney (email). The bot can be programmed to perform a certain action after a successful payment: for example, it can activate a service or send content to the customer.Find the provider_payment_charge_id parameter in the SuccessfulPayment object from the Telegram notification. It'll contain the transaction number in YooMoney. We recommend keeping this number: you can use it to find the payment in your Merchant Profile.
What payments via Telegram bot looks like
Use the @YooKassaTestShopBot bot to follow the customer's steps.
- Click Start (/start command). You'll receive a message with instructions and a payment button.
- Click Pay to open the payment form.
- Click Payment method, enter your card details, and click Pay.
- Confirm the payment by clicking Pay again.