How to connect a payment system
The payment system is built into Telegram. To accept payments within the messenger, you need to:
- Connect a payment system to your bot using BotFather.
- Go to the desired bot settings and select "Payments" from the menu.


Follow the instructions to connect an available payment system and copy the provided token.



How to invoice a client
To send an invoice in Telegram, use the method and specify the required parameters.
tg_send_invoice(provider_token, platform_id, title, description, currency, prices, photo_url, payload, protect_content, disable_notification, need_name, need_phone_number, need_email, reply_to_message_id, reply_markup, message_thread_id, provider_data)
IMPORTANT! All parameters must be passed in the order specified in the function. If you need to specify a particular parameter and omit others, leave empty values or values as specified in the documentation for the parameters you don’t need.
Example:

If any of the parameters need_name, need_phone_number, or need_email are enabled, the user will be prompted to provide that information before completing payment. Upon successful payment, the data is saved to the corresponding client variables.
Example:

The result: data is requested before payment.
Payment callback
If a payment is successful, a callback with the following content will be sent to the user’s chat:
tg_payment 1372995196 120.75 USD 2ff747b9-000f-5000-b000-16d7e3517aa9, where
- course_pay - payload - the payload from the original invoice creation request;
- 1372995196 - the chat ID where the invoice was originally sent;
- 120.75 - the total payment amount;
- USD - the currency;
- 2ff747b9-000f-5000-b000-16d7e3517aa9 - the payment ID in the merchant’s system.

Additionally, if the user's name, phone number, and/or email were requested, the corresponding variables will be assigned to the client:
tg_payment_name, tg_payment_phone и tg_payment_email

A payment success callback will be sent to the user's direct messages with the bot.
The user must have an existing chat with the bot (i.e., they must have started or subscribed to the bot) before the payment is made. Otherwise, the bot cannot send them the direct message.
Once the payment webhook is received, the payment will be automatically confirmed via the answerPreCheckoutQuery method. https://core.telegram.org/bots/api#answerprecheckoutquery
Pinned message with a payment button
You need to use the message pinning feature after connecting the payment system.
tg_pin_chat_message(platform_id, message_id, disable_notification)
Example:
Step 1:
prices = [["course", 100], ["VAT", 20.75]]
result=tg_send_invoice('381764678:TEST:129736', platform_id, 'Course on courses', 'Creating courses is easy', 'USD', prices, 'https://salebot.pro/promo.png', 'course_pay','0', '0', '1', '1', '1', '', '{"inline_keyboard": [[{"text":"Pay", "pay":"True"}]]}')
Step 2:
As a result of the first step, you will receive a response from which you need to extract the message_id value using the get() function.
res=get(result,'result')
m_id=get(res,'message_id')

Next, pin the message: tg_pin_chat_message(#{platform_id}, #{m_id}, 1)
Example: minimal set of parameters
prices = [["super course", 100]]
result= tg_send_invoice('381764678:TEST:129736', platform_id, 'Course on courses', 'Creating courses is super easy', 'USD', prices)

Example: keyboard
prices = [["course", 100], ["VAT", 20.75]]
tg_send_invoice('381764678:TEST:129736', platform_id, 'Course on courses', 'Creating courses is easy, 'USD', prices, 'https://mavibot.ai/promo.png', 'course_pay','0', '0', '1', '1', '1', '', '{"inline_keyboard": [[{"text":"Pay", "pay":"True"}], [{"text":"Another button", "callback_data": "Another button"}]]}')
