Button - pay from Balance
In this tutorial, we'll create a button letting you pay for something. Payment will be made from your bot's Balance, as this functionality is available to everyone by default.
Creating such a button is advisable if this is a one-off sale in your project, a specific function based on the same mechanics, or a way for you to master the basic approach. In other cases, it's easier to use the «Shop» functionality, where the payment process is automated and formalized.
CASE: A user wants to make a purchase in your bot. The button, using a Condition, should check the user's Balance. If there are insufficient funds, display an error message. If there are sufficient funds, debit the amount specified by the admin and perform the action specified by the Command.
When creating this tutorial, we assume that functionality allowing the user to top-up their Balance already exists. Balance top-up subjects are discussed here:
• Manual: «Autopayments and Withdrawals of Funds»
• Tutorial: «Custom Form - request for manual payment acceptance»
REQUIRED KNOWLEDGE:
Creating a Button: Basic Functions Guide.
Adding a Message to a Button: Basic Functions Guide.
User Balance in the Bot: Balance and Variable Editor.
Working with Actions: Actions Guide.
Working with Conditions: Conditions Guide.
Using Macros: Macros Guide.
❖ Acquisition of functionality
All functionality is purchased IN YOUR BOT, for this go to your bot:☞ 🔐Admin | 🧩Extensions
IMPORTANT: The purchase of functionality for the bot is available only to the Creator (owner) of the bot. Admins CANNOT buy functionality!
You will need:
1. Actions - 2 pieces☞ 🔐Admin | 🧩Extensions | 📂Actions
2. Conditions for a Button☞ 🔐Admin | 🧩Extensions | 📂Buttons
3. Macros and Expressions for Buttons☞ 🔐Admin | 🧩Extensions | 📂Buttons
❖ Creating of a payment button
1. Create the button itself
The user will have to click this button for the funds to be debited.
In your bot, go to:
☞ Buttons Editor > Add Button.
• Enter a Name for the new button.
• Send the Name to the Bot.
Guide for creating a button: «Basic Functions Guide».
2. Add a Condition to the button
The condition will check whether there are sufficient funds in the user's Balance and display an error message.
Go to your bot:
☞ Buttons Editor
• Go to «Button Settings» by clicking on the button with an asterisk ("*"):
• Click: «Assign Condition».
• Enter the Condition itself:
Example of a condition : {%balance% >= 100} ➨ This condition means that the user's Balance must be greater than or equal to 100.
• Enter an error message (will be shown if there are not enough funds on the balance):
Example of an error message:
"Insufficient funds.
Cost: 100 USD
Balance: %balance% USD"
Guide to using Conditions: «Conditions».
3. Add Actions for writing off and executing the Command
If the Condition check shows that there are sufficient funds in the Balance, you can debit them and perform the required action (the sale itself). For this, we need two Actions.
3.1 Writing funds off from the Balance as payment
Without leaving the Button Settings and the Button Editor (if you exited, enter again):
• Click «Assign Pre-Action».
• Select «Action of Numbers» (this will be our first Action in the chain).
• Specify the variable to change (write off) - in our case, this is “balance”.
• Specify the method: «Change Value».
• Enter the value - in our case, we need to write off, therefore “-100” (minus one hundred).
• Do NOT set the condition (we have previously checked everything that is necessary at the level of the button itself).
• Set the execution message at your discretion (you can inform the user that the funds have been written off).
3.2 Calling a function that does what was paid for
Depending on what you're selling, the "Sale Function" itself can be placed in the same button (using the same Actions), but to demonstrate the concept, where the sale function can be complex and contain actions affecting both the User and the Admin and Bot's data, it's clearer and more convenient to place it in a separate button and access it by command from anywhere.
Without leaving the Button Settings and the Button Editor (if you exited, enter again):
• Click «Assign Pre-Action».
• Select «Action of Commands» (this will be our second Action in the chain).
• Set the command for the button where we have locate the function designated for selling something.
Example of a command: “/sell_item1” (leave the execution settings for the Action itself at your discretion).
• Do NOT set the condition
In our case, a Condition is not needed, but technically you can call different functions depending on some factors by checking the data in the user variables in the Condition - when one condition is met, you can call one function, when another is met, another (or even call additional functions depending on the conditions).
Actions Guide: «Actions»