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 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:
https://bill_address?func=referralprogram.registerclick&p=https%3A%2F%2Fsite.com%2F%3Ffrom%3D2&r=https%3A%2F%2Freferrer.com%2Fpage&out=xjsonWhere:
-
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 URLhttps://site.com/?from=2specify&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 thepparameter 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 roothttps://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.&r=referrer_url— the URL-encoded link to the page from which the client navigated to the current page (the `HTTP_REFERER` value). This parameter is passed to track the referral source. To obtain the value, use the `document.referrer` property in JavaScript. If the referrer is missing, this parameter can be omitted.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.
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
Processing referral relationships when merging clients
When two clients are merged, the system applies the following rules:
- preserving and extending relationships: the current relationships of the primary client (referrer or referee status) are fully preserved. At the same time, all referees and referrers of the joined client that the primary client did not already have are transferred to the primary client;
- data transfer: if the primary client does not participate in the program, the system transfers the referral relationships from the joined client;
- preserving rewards: the system preserves all actual and planned rewards of both clients, even if they have not been accrued yet;
- breaking cyclic relationships: if the clients were each other's referrer and referee, the system deletes this relationship. Their other referral relationships are preserved;
- separation by providers: if there are relationships with different providers, the system preserves separate records for each provider.
Examples
Example 1. The primary client is a referrer, and the joined client is a referee with no own referees
After the merge, the primary client keeps the referrer status. Since the joined client has no own referees, there is nothing to transfer. The primary client becomes a referee for the person who previously referred the joined client.
Before the merge:
- Client A (primary) is a referrer and has referees: Client B and Client C;
- Client D (joined) is a referee, and its referrer is Client E. Client D has no own referees.
After the merge:
- Client A keeps the referrer status and its referees (Clients B and C remain linked to it);
- Client A becomes a referee for Client E (takes over Client D's relationship);
- Client D's account is deleted, and all its relationships are transferred to Client A.
Example 2. Both clients are referrers (each has its own referees)
After the merge, the primary client keeps all its referees. In addition, all referees of the joined client are transferred to it. The primary client becomes the referrer for the merged group.
Before the merge:
- Client A (primary) is a referrer and has referees: Client B and Client C;
- Client D (joined) is a referrer and has referees: Client E and Client F.
After the merge:
- Client A keeps the referrer status and its referees (Clients B and C remain linked to it);
- Clients E and F (former referees of Client D) move under Client A's management;
- Client A becomes the referrer for the merged group of four clients: B, C, E, and F.
Example 3. The primary client is a referee, and the joined client is a referrer
After the merge, the primary client keeps the relationship with its referrer. In addition, all referees of the joined client are transferred to it. The primary client remains a referee for its referrer and becomes a referrer for the new group at the same time.
Before the merge:
- Client A (primary) is a referee, and its referrer is Client B;
- Client D (joined) is a referrer and has referees: Client C and Client E.
After the merge:
- Client A keeps the relationship with its referrer, Client B (remains its referee);
- Clients C and E (former referees of Client D) move under Client A's management;
- Client A remains a referee for Client B and becomes a referrer for Clients C and E.
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