Referral program is a type of cooperation between the client and provider, in which the client receives a referral link or a promotional code. Such a client is considered a partner or referrer, and new clients who have registered under that link (promotional code) are referrals. The partner receives a percentage of the expenses of his referrals.
Referral program results:
- partner makes a profit from the attracted clients;
- provider gets new clients and advertising by the partner.
For information on how to create a referral program, see the article Referral program. General information.
Integration with your website
To integrate the referral program with your website, specify the Website URL in the program settings when creating it.
If the website URL points to BILLmanager, no additional actions are required. The platform will automatically extract the parameter from the request and register the referral link click.
If the URL belongs to a third-party website, perform the following steps:
-
From the website side, send a request to the platform in the following format:
https://bill_address?func=referralprogram.registerclick&p=https%3A%2F%2Fsite.com%2F%3Ffrom%3D2&out=xjsonWhere:
bill_address— IP address of the server with the platform;func=referralprogram.registerclick— function that registers a click on the referral link;&p=website_url— URL-encoded link used by the client. Special characters must be replaced with codes according to percent encoding. Percent encoding (or URL encoding) is a way to safely transmit special characters in URLs. For example, for the URLhttps://site.com/?from=2, specify&p=https%3A%2F%2Fsite.com%2F%3Ffrom%3D2. This address is displayed in the partner’s personal account and provided by them to potential referrals;out=xjson— response format.
The platform registers the click and returns a unique identifier in the
doc["cntid"]["$"]field of the JSON response. Store this identifier on the website side and pass it as a parameter during subsequent redirects to BILLmanager.Example of HTML page with referral program integration and a button to redirect to BILLmanager:<html> <head> <script type="text/javascript"> function getBillCntid() { var req = new XMLHttpRequest(); req.responseType = 'json'; req.onload = function() { if (req.status == 200) { var json = req.response; var doc = json.doc; if (doc["cntid"]) { // If the platform returns cntid, save it in localStorage localStorage.setItem("bill_cntid", doc["cntid"]["$"]) } } } // Request to the platform, parameter p passes the current URL, which may contain the referrer parameter. req.open("GET", "https://billmgr_addr/?func=referralprogram.registerclick&p=" + encodeURIComponent(window.location.href) + "&out=xjson", true); req.send(null); } if (!localStorage.hasOwnProperty("bill_cntid")) { getBillCntid(); } </script> </head> <body> <script type="text/javascript"> function gotoBillManager() { var url = "https://billmgr_addr"; // If the connection identifier for the referral program (bill_cntid) is found in localStorage, add it as a parameter: if (localStorage.getItem("bill_cntid") !== null) { url += "?cntid=" + localStorage.getItem('bill_cntid'); } window.location.href=url } </script> <input type="button" onclick="gotoBillManager();" value="Go to BILLmanager"> </body> </html>Explanation of HTML code
Database tables
The referralprogram table contains information about referral programs:
The referralprogram_rule table contains rules for referral programs, defined for a specific referral program:
The referralprogram_condition table contains conditions defined for a specific rule of a referral program:
The referralprogram_click table records transitions to the referral program:
The referralprogram_referer table establishes the link between a referrer and a referral program:
The referralprogram_link table establishes the link between referrer, referral, and referral program:
The referralprogram_reward table contains information about rewards under the referral program:
Client click on referral link
Tracking link clicks
When a client clicks on a referral link, BILLmanager makes an entry in the database:
INSERT INTO referralprogram_click (cdate, ip, method, project, referer_account, referralprogram, sesid, site) VALUES('2025-11-10 03:28:25', '10.4.202.1', '2', '2', '2', '7', '1762745305.hvtgBc', 'http://localhost:8080/?from=2')If the client did not have an active browser session, the referral will be linked, but no record will be created in the table. This can occur, for example, in incognito mode or when using a proxy.
Referral link click logs are stored in the file /usr/local/mgr5/var/counter.log.
Registering a new client via referral link
-
Adding a new user as a potential referrer:
Database EntryINSERT INTO referralprogram_referer (account, project, referralprogram) VALUES('44', '2', '5')Explanation of the entry -
Adding a link between the registered referral client, the referrer, and the referral program:
Database EntryINSERT INTO referralprogram_link (cdate, referer_account, referral_account, referralprogram) VALUES('2025-11-10', '2', '43', '1')Explanation of the database entry -
Adding the referral ID to
referralprogram_click:Database EntrySELECT * FROM referralprogram_click WHERE referer_account = 2 AND sesid = '1762745305.hvtgBc' FOR UPDATE UPDATE referralprogram_click SET referral_account='44', referralprogram='1' WHERE referer_account='2' AND sesid='1762745305.hvtgBc'
Awarding rewards
By default, referral rewards are credited on the first day of each month at 03:10 server time, according to a cron job:
10 3 1 * * /usr/local/mgr5/sbin/billmaintain --command affiliatemonthly >/dev/null 2>&1When awarding referral rewards, BILLmanager:
-
Discovers a new reward and executes a request:
Request exampleAug 1 12:00:47 [134624:19] core_module INFO Request [billmaintain][root] 'func=referralprogram.createreward&out=xml&referer_account=49&referral_expense=538&referralprogram_rule=11&reward_amount=100.00&reward_cdate=2025%2D08%2D01' -
Sends an SQL query to create a reward entry in the database:
Database EntryINSERT INTO referralprogram_reward (amount, cdate, currency, expense, id, referer_account, referral_account, referralprogram, referralprogram_rule) VALUES('100.0000', '2025-08-01', '126', '538', '308', '49', '50', '9', '11')Explanation of the database entry -
If the reward crediting date matches the current date, a payment is created:
Request exampleAug 1 12:00:47 [134624:20] core_module INFO Request [billmaintain][root] 'func=referralprogram.createpayment&out=xml&referer_account=49&referralprogram=9&reward_date=2025%2D08%2D01' -
An SQL query is executed to create a payment:
Example database entriesINSERT INTO payment (createdate, currency, id, paymethodamount, randomnumber, status, subaccount, subaccountamount, usedamount) VALUES('2025-08-01 12:00:47', '126', '585', '100.0000', 'mRj2cTHawIeA', '1', '46', '100.0000', '0.0000')Explanation of the database entry
Logging
Additional diagnostic information is contained in the /usr/local/mgr5/var/ billmaintain.log file. To enable printing of debug information about reward generation for the referral program to the billmaintain.log log, increase the logging level:
billmaintain.referral 9
En
Es