CoolCMS API

UserReferralTrait

Affiliate program and the registration bonus.

Every account gets a referral code; a new account registered through /registrace?ref=<code> remembers its referrer. When the new account is activated, it receives the registration bonus (account.registration.bonusCredits) and its referrer the reward (account.referral.rewardCredits), unless the referrer is inactive, has the affiliate program disabled, registered from the same IP or reached the monthly cap (account.referral.monthlyCap). Each decision is recorded in cms_system_user_referral_rewards, at most once per account and type, so a repeated activation never pays twice. All settings at 0 switch the respective part off.

Fail-open: a failure here is logged (referral) and never breaks the registration or activation.

Requires on the host: $userService, getSettingContext(), bumpCacheTagsForClass().

Table of Contents

Constants

REFERRAL_SKIP_DISABLED  : string = 'disabled'
REFERRAL_SKIP_MONTHLY_CAP  : string = 'monthly_cap'
REFERRAL_SKIP_REFERRER_INACTIVE  : string = 'referrer_inactive'
REFERRAL_SKIP_SAME_IP  : string = 'same_ip'

Methods

getReferralOverview()  : array{enabled: bool, code: ?string, registered: int, activated: int, credits: int, rewardCredits: int}
Referral data of the user for the "My account" page.
getReferralRewardCredits()  : int
Credits of the referral reward; 0 = the affiliate program is off.
assignReferralCode()  : void
attachReferrerByCode()  : void
Links a new account to the owner of the referral code. An unknown, malformed or own code is ignored; the registration itself always goes on.
onboardNewAccount()  : void
Steps after a new account got its code: links the referrer and, for an account already active, pays the rewards right away. Fail-open.
referralSkipReason()  : string|null
rewardActivatedAccount()  : void
Registration bonus for the account and the reward for its referrer, once the account is active.

Constants

REFERRAL_SKIP_MONTHLY_CAP

public string REFERRAL_SKIP_MONTHLY_CAP = 'monthly_cap'

REFERRAL_SKIP_REFERRER_INACTIVE

public string REFERRAL_SKIP_REFERRER_INACTIVE = 'referrer_inactive'

Methods

getReferralOverview()

Referral data of the user for the "My account" page.

public getReferralOverview(int $userId) : array{enabled: bool, code: ?string, registered: int, activated: int, credits: int, rewardCredits: int}
Parameters
$userId : int
Return values
array{enabled: bool, code: ?string, registered: int, activated: int, credits: int, rewardCredits: int}

getReferralRewardCredits()

Credits of the referral reward; 0 = the affiliate program is off.

public getReferralRewardCredits() : int
Return values
int

assignReferralCode()

private assignReferralCode(int $userId) : void
Parameters
$userId : int

attachReferrerByCode()

Links a new account to the owner of the referral code. An unknown, malformed or own code is ignored; the registration itself always goes on.

private attachReferrerByCode(int $userId, string $code) : void

IMPORTANT: a code is also ignored while the program is off or the referrer has the affiliate disabled. The cookie lives 30 days, so it can carry a code from before the switch-off; such a registration must not count in the referrer's statistics on "My account".

Parameters
$userId : int
$code : string

onboardNewAccount()

Steps after a new account got its code: links the referrer and, for an account already active, pays the rewards right away. Fail-open.

private onboardNewAccount(int $userId, string|null $referralCode, bool $activated) : void
Parameters
$userId : int
$referralCode : string|null
$activated : bool

referralSkipReason()

private referralSkipReason(array{ip: ?string, referrerUserId: ?int, referrerIp: ?string, referrerActive: bool, referrerAffiliateDisabled: bool} $state, int $referrerId) : string|null
Parameters
$state : array{ip: ?string, referrerUserId: ?int, referrerIp: ?string, referrerActive: bool, referrerAffiliateDisabled: bool}
$referrerId : int
Return values
string|null

rewardActivatedAccount()

Registration bonus for the account and the reward for its referrer, once the account is active.

private rewardActivatedAccount(int $userId) : void

Fail-open.

Parameters
$userId : int
On this page

Search results