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.
Only a new client, who has not yet purchased any services, can be added using a promotional code.
Referral program results:
partner makes a profit from the attracted clients;
provider gets new clients and advertising by the partner.
To integrate the referral program with a website, when creating a referral program, specify the Website URL in the settings:
if the website URL is the BILLmanager address, no additional actions are required. The platform will automatically extract the parameter value from the request and register the referral link click;
if the URL is a third-party website, from the website side, send a request to the platform in the following format:
bill_address — domain name of the server with the platform;
func=referralprogram.registerclick — function that registers a click on a referral link;
&p=website_address
— URL-encoded link that the client clicked. Special characters must be replaced with codes according to percent encoding. Percent encoding (or URL encoding) is a method to safely transmit special characters in links (URL). For example, for the URL
https://site.com/?from=2
specify &p=https%3A%2F%2Fsite.com%2F%3Ffrom%3D2. This address is displayed in the referrer's client area and provided by them to potential referrals;
The value of the p parameter must exactly match the link specified in the referral program settings — field Website URL, otherwise the click will not be registered. For example, if the program is configured for the domain root https://example.ru/ , and the parameter transmits an address with a path .../catalog/. For universal configuration, it is recommended to normalize the address: leave only the protocol and domain, removing the path and parameters.
out=xjson — response format.
The platform registers the click and returns a unique identifier in the field doc["cntid"]["$"] of the JSON response. The received identifier is saved on the website side and transmitted as a parameter during subsequent redirection to BILLmanager.
Example with normalization
Example HTML page with referral program integration and a button to navigate 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"]) {
// Save cntid to localStorage
localStorage.setItem("bill_cntid", doc["cntid"]["$"]);
}
}
}
// Forming address for parameter p
var referralParam;
// Link normalization: leave only protocol and domain
// This guarantees matching with referral program settings,
// even if the user navigated to a page with a path (e.g., /catalog/)
if (typeof URL === "function") {
var urlObj = new URL(window.location.href);
urlObj.pathname = "/"; // reset path to root
urlObj.search = ""; // optionally: remove query parameters
referralParam = encodeURIComponent(urlObj.toString());
} else {
// Fallback for old browsers: use as is
referralParam = encodeURIComponent(window.location.href);
}
// Replace bill.example.com with your platform address
var billUrl = "https://bill.example.com/billmgr ";
// Sending request
req.open("GET", billUrl + "?func=referralprogram.registerclick&p=" + referralParam + "&out=xjson", true);
req.send(null);
}
if (!localStorage.hasOwnProperty("bill_cntid")) {
getBillCntid();
}
</script>
</head>
<body>
<script type="text/javascript">
function gotoBillManager() {
// Replace bill.example.com with your platform address
var url = "https://bill.example.com/billmgr ";
// If the referral program connection identifier (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>
Explanations for the HTML code
getBillCntid() — function that sends a request to the platform to register a click on a referral link;
encodeURIComponent(...) — function that encodes the normalized URL for safe transmission in the request;
localStorage.setItem("bill_cntid", ...) — function that saves the received unique click identifier between sessions;
gotoBillManager() — function that forms the URL for navigation to the platform with addition of the cntid parameter, if it was saved;
cntid — parameter that allows the platform to associate a future registration or purchase with a specific click on a referral link.
Database tables
The referralprogram table contains information about referral programs:
name
project
url
promocode
account_group
account_group_restrict
assign_by_default
start_date
end_date
Referral Program
1
https://example.com/ref
PROMO2025
5
10
1
2025-01-01
2025-12-31
Explanation of the database table
name — name of the referral program. Localized field;
project — provider;
url — website URL from which the transition to the referral program is made;
method — method of access. E.g., via storefront, registration, etc.;
project — provider code under whose referral program the click was registered;
referer_account — client-partner account ID whose link was used;
referralprogram — referral program identifier;
sesid — unique session key;
site — URL of the page from which the transition occurred.
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 Entry
INSERT INTO referralprogram_referer (account, project, referralprogram) VALUES('44', '2', '5')
Explanation of the entry
account — account ID of the client who will become the referrer;
project — provider code;
referralprogram — referral program ID.
Adding a link between the registered referral client, the referrer, and the referral program:
referralprogram — referral program ID. For example, 1.
Adding the referral ID to referralprogram_click:
Database Entry
SELECT * 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:
Aug 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:
currency — currency code. For example, 126 corresponds to Euro;
expense — referral expense ID on which the reward is based;
id — unique reward entry ID;
referer_account — referrer client ID;
referral_account — referral client ID;
referralprogram — referral program ID;
referralprogram_rule — referral program rule under which the reward was applied.
If the reward crediting date matches the current date, a payment is created:
Request example
Aug 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'
createdate — date and time the payment was created;
currency — payment currency code;
id — unique payment ID;
paymethodamount — amount in the payment method's currency;
randomnumber — unique internal payment number;
status — payment status. For example, 1 — new, 4 — credited, etc.;
subaccount — referrer's account to which the reward is credited;
subaccountamount — amount in the account's currency;
usedamount — amount of the payment used.
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: