Affiliates (developers)
The Affiliates module (PLAN › Affiliate engine): attribution, commissions, the portal and the fraud flags; payouts
follow, once the accountant signs off on the taxes for individuals.
-
Data:
affiliates(citextcode,coupon_codeandemail;customer_idfilled from the shopper account with the same e-mail;statusData\AffiliateStatus;ratepercent or null for the default),affiliate_clicks(affiliate and day, a counter: no visitor data),affiliate_referrals(one per order,sourceData\ReferralSourcelink|coupon,flage.g.self_referral). Settings:Settings\AffiliateSettings(window_days,last_click,coupon_beats_link,default_rateas a decimal string). -
Contract
Contracts\Referrals(Referrals\DatabaseReferrals):active(code),click(affiliateId)(an upsert per day),windowDays(),lastClickWins(),attribute(orderId, ?ReferralVisit)(idempotent: the coupon throughPromotions\Contracts\Vouchers::redeemedBy(), the visit if within the window; coupon beats link unless set otherwise; flagged: a self-referral by customer id or e-mail, andsame_addressfrom the third order for one affiliate from one IP within 30 days, the IP kept only as an HMAC with the app key inip_hash, cleared after 90 days byPrivacy\ReferralRetention),forOrder(orderId). -
Storefront:
Http\Middleware\CaptureReferralon every storefront route takes?ref=CODEon a GET, counts a click once per affiliate per session and keeps the visit in the session (Support\ReferralCookie::SESSION, "CODE|unix time"); after the response it writes thesyncshop_refcookie (encrypted, HTTP only, for what is left of the window) only while the consent allows marketing, and forgets it otherwise.ReferralCookie::visit()picks the latest (or first) of session and cookie.CheckoutController::place()credits the order with the visit only when marketing is allowed at that moment; the API checkout credits coupons only. A failure there is reported, never shown to the buyer. -
Admin:
Http\Controllers\AffiliateController(admin.affiliates.*,admin.settings.affiliates.*,affiliates.manage); the order page shows the attribution (OrderControllerpassesReferrals::forOrder());Orders\Contracts\OrderBook::summaries()lists an affiliate's orders in one query. -
Commissions (
affiliate_commissions, one per order, bani RON;Data\CommissionStatus):Actions\SettleCommissionsopen()(called byattribute(): rate frozen from the affiliate ordefault_rate),settle()(base fromAnalytics\Contracts\OrderRevenue::netProducts(), the ledger's own sale + discount − product refunds, so commissions and profit agree;approve_after= fulfilment +hold_days; cancelled with a cancelled or wholly returned order; flagged ones never approve by themselves),approve()(under a lock; booksLedgerType::AffiliateCommission, sourceaffiliate:commission:{id}, counted inFigures::marketing()) andcancel().Listeners\SettleOnOrderChangesettles on everyOrderStatusChanged;affiliates:settleruns nightly from the registry. Admin:Http\Controllers\CommissionController(admin.affiliates.commissions.*: list with totals, approve at another amount with a reason, cancel with a reason). -
Portal:
Contracts\AffiliatePortal(Portal\DatabaseAffiliatePortal):programme()(sign-up counts as open only withterms_urlset),forCustomer(),apply()(one per customer account, uniquecustomer_id; statuspending; a code from the name;Data\AffiliateApplied),stats()(clicks, orders, pending/approved sums and the latest commissions asData\PortalCommission, with no order or buyer). Staff decide by changing the status from pending, which firesData\AffiliateDecided; the storefront'sListeners\SendAffiliateMailsendsMail\AffiliateMail(accepted, rejected). The account page isAffiliatePortalController(account.affiliate,account.affiliate.apply), in the account nav while sign-up is open or the shopper has a record.
Tests: tests/Feature/Affiliates/AttributionTest.php, CommissionsTest.php, PortalTest.php.