BILLmanager 6
en En
es Es

How does the referral program work?

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.

For information on how to create a referral program, see the article Referral 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 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=xjson

Where:

    • 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.
    • &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.

Example with normalization

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

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:

Logging level configuration
billmaintain.referral 9