Telegram

How to connect the payment system

Payment system is built into Telegram.

In order to make payments inside the messenger, you need:

  • connect payment system to bot in botfather bot

  • go to the desired bot settings and in the menu select Payments

  • following instructions to connect an accessible payment system and copy the issued token

How to Invoice a Client

To send invoice to telegram use method

tg_send_invoice(provider_token, platform_id, title, description, currency, prices, photo_url, payload, protect_content, disable_notification, need_name, phone_number, need_email, reply_to_message_id, reply_markup, reply_id) - the required parameters are highlighted in bold

provider_token - token received in Botfather, after connecting the payment system

platform_id - recipient - identifier of user, group or channel

title - item title, 1-32 characters

description - description of goods, 1-255 characters

currency - payment currency (RUB, USD, UAH and so on https://core.telegram.org/bots/payments#supported-currencies)

payload - the first part of the coin about payment, by default tg_payment

prices - price breakdown (description below)

photo_url - link to product picture

disable_notification - 1 - send with notification, 0 - without notification

protect_content - 1 copy and screenshot protection, 0 - unprotected

need_name - 1 if you need a full username to complete the order, 0 - without asking for a name

need_phone_number - 1 if you require a user’s phone number to complete the order, 0 - without a request number

need_email - 1 if you require an email address of the user to complete the order, 0 - without a mail request

reply_to_message_id - the message id to which we respond, '' is not the answer

reply_markup - keyboard, the first button should be a button with pay type

If one of the parameters need_name, need_phone_number or need_email is specified, the user will request the data before paying and save it to the client variables if the payment is successful. In the screenshot below the request for all data input:

prices - an array of arrays with data on the cost of goods and additional services (delivery, packaging, etc.). Displayed on the payment page. The amount shall be indicated either by an integer of 125 or by a fraction through point 120.25 For example: [["goods", 2000], ["VAT", 20.75], ["packaging", 100]

Callback on payment

After successful payment in the chat with the user will come a colbeck as follows:

phone_best 4737685 2120.75 UAH 1955518436

where phone_best - payload - from the request for creation of invoice 473737685 - a chat id, to which originally was sent invoice 2120.75 - the full amount of payment UAH - currency 1955518436 - payment id in the merchant system

Also, if you requested a name, phone and/or email, the client will write down the variables:

tg_payment_name, tg_payment_phone and tg_payment_email

In case of success, the kolbek will be sent to the user’s personal messages. To do this, the client and the bot must cooperate before payment (the client must be subscribed to the bot)!

After receiving the hook about payment, the payment will be automatically confirmed, by answerPreCheckoutQuery https://core.telegram.org/bots/api#answerprecheckoutquery .

Examples

prices = [["product", 2000], ["NDS", 20.75], ["package", 100]] result = tg_send_invoice('632593626:TEST:sandbox_i38014109763', platform_id, 'phoneW-200', 'Best Model on the Market', 'UAH', prices, 'https://images11.popmeh.ru/cropped.jpg', 'phone_best', 0, 0, 1, 0, 1)

Example with minimum parameter sets

prices = [["an amazing product", 20000]] result = tg_send_invoice('632593626:TEST:sandbox_i38014109763', platform_id, 'The best bot ever!', 'An amazing course! Be the best!', 'UAH', prices)

Example with a Keyboard

prices = [["product", 2000], ["NDS", 20.75], ["package", 100]] result = tg_send_invoice('632593626:TEST:sandbox_i38014109763', platform_id, 'Phone W-200', 'BEst Model on the Market', 'UAH', prices, 'https://helpix.ru/news/200405/181746/gf200_2.jpg', 'phone_best', 0, 0, 1, 1, 1, '', '{"inline_keyboard": [[{"text":"Pay", "pay":"True"}], [{"text":"One more button", "callback_data": "One more button"}]]}')

Last updated