Partner Programme Hooks
The four hooks over enrolment, commissions, referral clicks and payout requests.
Overview
The four moments of the partner programme: a customer joins, their link is clicked, a sale raises a commission, and they ask to be paid.
One distinction to hold from the start: the id of the partner record and the id of the customer are separate numbers, and the hooks carry both.
Reference
Following an enrolment
Runs after a customer joins the partner programme.
Hook::add('action:user.affiliate_activated', 10, function ($user_id, $aff_id) {
// Two different ids: the partner record is not the customer number.
Acme::openPartnerDashboard($user_id, $aff_id);
});Following a commission being made
Runs after a commission is credited to a partner. Both first sales and renewals land here.
sale for a first sale, renewal for a renewal. On renewals the commission recurs every period: mind the difference if you hand out a one-off reward.Hook::add('action:user.affiliate_commission_created', 10,
function ($affiliate_id, $service, $transaction_type, $commission) {
// On renewals the commission recurs every period.
if ($transaction_type === 'sale') Acme::rewardFirstSale($affiliate_id);
});Following a referral click
Runs when a partner link is clicked. It fires on every click, with or without a sale, with or without a logged-in visitor.
Hook::add('action:user.affiliate_referral_clicked', 10, function ($ownerId, $context) {
// It runs on every click: keep heavy work out of here.
Acme::countClick($ownerId);
});Following a payout request
Runs when a partner asks for their earnings. Nothing has been paid: the record opens in a waiting state.
Hook::add('action:user.affiliate_withdrawal_requested', 10,
function ($uid, $affId, $amount, $cid, $gateway, $wid) {
// Nothing was PAID: the request opened in a waiting state.
Acme::queuePayout($wid, $affId, $amount, $gateway);
});Pitfalls
The payout hook carries both the customer id and the partner record, and they are not the same number. Taking the partner record for a customer id books the earnings against the wrong account.
The commission hook fires on the first sale and on every renewal. If you hand out a one-off reward, check the transaction type; otherwise the same customer earns it again each month.
Related Articles
¡Gracias por sus comentarios!
Nuestro equipo de soporte está disponible las 24 horas para ayudarle con lo que no encuentre aquí.