BILLmanager 6
en En
es Es
We want your feedback!
Take our survey and help us improve the ISPsystem ecosystem as our lead advisor
Take the survey

How does the referal program work?

The affiliate 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.

For information on how to create a referral program, see the article Referal program. General information.

The information in this article is relevant for BILLmanager version 6.135 and above. For information on how the referral program works in earlier versions, see the article How does the affiliate program work? (for version 6.134 and lower)

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:

  1. 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=xjson

    Where:

    • 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 URL https://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:

nameprojecturlpromocodeaccount_groupaccount_group_restrictassign_by_defaultstart_dateend_date
Referral Program1https://example.com/ref PROMO202551012025-01-012025-12-31
Explanation of the database table

The referralprogram_rule table contains rules for referral programs, defined for a specific referral program:

referralprogramreward_value_fixedreward_value_percentreward_max_amountreward_months_afterreward_expense_periodreward_periodreward_payment_intervalstatus
10.0010.005000.00111210
Explanation of the database table

The referralprogram_condition table contains conditions defined for a specific rule of a referral program:

referralprogram_rulectypecgroupcomparisonamountorderperiodsitem_countreferral_countproduct_treestatus
110ge10000.003NULLNULLNULL0
Explanation of the database table

The referralprogram_click table records transitions to the referral program:

referer_accountreferral_accountipsesidsitecdateproject
101205192.168.1.100a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8https://example.com/ref?ref=1012025-11-01 14:30:001
Explanation of the database table

The referralprogram_referer table establishes the link between a referrer and a referral program:

accountprojectreferralprogram
10113
Explanation of the database table

The referralprogram_link table establishes the link between referrer, referral, and referral program:

referer_accountreferral_accountreferralprogram
1012053
Explanation of the database table

The referralprogram_reward table contains information about rewards under the referral program:

referralprogramreferralprogram_rulereferral_accountreferer_accountamountcurrencyexpensepaymentcdate
312051011250.00USD500178902025-11-05 10:15:00
Explanation of the database table

Tracking link clicks

When a client clicks on a referral link, BILLmanager makes an entry in the database:

Database Entry
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')
Explanation of the database entry

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.

  1. 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
  2. Adding a link between the registered referral client, the referrer, and the referral program:

    Database Entry
    INSERT INTO referralprogram_link (cdate, referer_account, referral_account, referralprogram) VALUES('2025-11-10', '2', '43', '1')
    Explanation of the database entry
  3. 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:

Cron Job
10 3 1 * *      /usr/local/mgr5/sbin/billmaintain --command affiliatemonthly >/dev/null 2>&1

When awarding referral rewards, BILLmanager:

  1. Discovers a new reward and executes a request:

    Request example
    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'
  2. Sends an SQL query to create a reward entry in the database:

    Database Entry
    INSERT 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
  3. 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'
  4. An SQL query is executed to create a payment:

    Example database entries
    INSERT 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:

Logging level configuration
billmaintain.referral 9
The article was last updated on 11.11.2025. The article was prepared by technical writers of ISPsystem