/** * @return string campaignId * @throws Gpf_Exception */ public function recognizeCampaignId(Pap_Contexts_Tracking $context, $productId) { if($productId == '') { $context->debug('Empty product ID'); throw new Gpf_Exception('Empty product ID'); } $matchingCampaigns = $this->getMatchingCampaignsRecordSet($productId); switch ($matchingCampaigns->getSize()) { case 0: $context->debug('No campaign matching product ID: '.$productId); throw new Gpf_Exception('No campaign matching product ID: '.$productId); case 1: foreach ($matchingCampaigns as $campaign) { $campaignId = $campaign->get(Pap_Db_Table_Campaigns::ID); $context->debug("Campaign was found for this Product ID. Campaign Id: ".$campaignId); return $campaignId; } default: $context->debug("More campaigns matched product ID '.$productId.'. Finding correct campaign"); $campaignId = $this->findBestMatchingCampaignId($matchingCampaigns, $productId, $context); $context->debug('Campaign was chosen. Campaign Id: '.$campaignId); return $campaignId; } }
/** * returns commission group for user (if not set already) * Commission group can be set previously in the checkCampaignType() function * */ protected function getCommissionGroup(Pap_Contexts_Tracking $context) { $context->debug('Recognizing commission group started'); if (($user = $context->getUserObject()) == null) { $context->debug('STOPPING, user is not set - cannot find commission group'); return; } $commGroupId = $this->getUserCommissionGroupFromCache($context->getCampaignObject(), $user->getId()); if($commGroupId == false) { $context->debug("STOPPING, Cannot find commission group for this affiliate and campaign! ".$context->getCampaignObject()->getId().' - '.$user->getId()); $context->setDoCommissionsSave(false); $context->setDoTrackerSave(false); return; } Gpf_Plugins_Engine::extensionPoint('PostAffiliate.RecognizeCommGroup.getCommissionGroup', $context); $commissionGroup = $this->getCommissionGroupFromCache($commGroupId); if ($commissionGroup == null) { $context->debug(' Commission group with ID '.$commGroupId . ' does not exist'); return; } $context->setCommissionGroup($commissionGroup); $context->debug('Received commission group ID = '.$commGroupId); }
private function recognizeAccountId(Pap_Contexts_Tracking $context) { if (!$this->accountValid($context->getVisit()->getAccountId())) { $context->debug('Account from visit with accountId='.$context->getVisit()->getAccountId() . ' is not valid! For now, set default account: '.$context->getAccountId()); return; } $context->debug('Set AccountId: '.$context->getVisit()->getAccountId()); $context->setAccountId($context->getVisit()->getAccountId(), Pap_Contexts_Tracking::ACCOUNT_RECOGNIZED_FROM_FORCED_PARAMETER); }
/** * returns user object from standard parameter from request * * @return Pap_Common_Banner * @throws Gpf_Exception */ protected function getBannerFromParameter(Pap_Contexts_Tracking $context) { $id = $context->getBannerId(); if($id == '') { $message = 'Banner id not found in parameter'; $context->debug($message); throw new Pap_Tracking_Exception($message); } $context->debug("Getting banner from request parameter. Banner Id: ".$id); return $this->getBannerById($context, $id); }
public function saveCommissions(Pap_Contexts_Tracking $context) { $context->debug('Saving recurring commissions started'); $commissionType = $context->getCommissionTypeObject(); if ($commissionType == null) { $context->debug('No commission type defined. Recurring commissions saving ended'); return; } if ($commissionType->getRecurrencePresetId() == Pap_Db_CommissionType::RECURRENCE_NONE || $commissionType->getRecurrencePresetId() == null) { $context->debug('Saving recurring commissions ended - No recurring commissions defined'); return; } $tier = 1; $currentUser = $context->getUserObject(); $currentCommission = $context->getCommission($tier, Pap_Db_Table_Commissions::SUBTYPE_RECURRING); if ($currentUser == null || $currentCommission == null) { $context->debug('Saving recurring commissions ended - current user or current commission is null'); return; } $recurringCommission = new Pap_Db_RecurringCommission(); $relatedTransaction = $this->getTransaction($context); $recurringCommission->setOrderId($relatedTransaction->getOrderId()); $recurringCommission->setTransactionId($relatedTransaction->getTransactionId()); $recurringCommission->setRecurrencePresetId($commissionType->getRecurrencePresetId()); $recurringCommission->setCommissionTypeId($commissionType->getId()); $recurringCommission->setStatus($relatedTransaction->getStatus()); $recurringCommission->setLastCommissionDate($relatedTransaction->getDateInserted()); $recurringCommission->insert(); $context->debug('Recurring commission successfully saved.'); while($currentUser != null && $currentCommission != null && $tier < 100) { $rcEntry = new Pap_Db_RecurringCommissionEntry(); $rcEntry->setRecurringCommissionId($recurringCommission->getId()); $rcEntry->setUserId($currentUser->getId()); $rcEntry->setTier($tier); $rcEntry->setCommission($currentCommission->getCommission($context->getRealTotalCost())); $rcEntry->insert(); $tier++; $currentUser = $currentUser->getParentUser(); $currentCommission = $context->getCommission($tier, Pap_Db_Table_Commissions::SUBTYPE_RECURRING); } $context->debug('Saving recurring commissions ended'); $context->debug(""); }
public function recognize(Pap_Contexts_Tracking $context) { if ($context->isVisitorAffiliateRecognized()) { return; } Pap_Tracking_Common_VisitorAffiliateCheckCompatibility::getHandlerInstance()->checkCompatibility($context->getVisitorId(), $this->visitorAffiliateCache); $context->debug('Getting VisitorAffiliate for visitorId = ' . $context->getVisitorId()); if (($visitorAffiliate = $this->visitorAffiliateCache->getActualVisitorAffiliate($context->getVisitorId())) == null) { $context->debug('Recognize VisitorAffiliate not recognized from actual'); return; } $context->debug('Recognize VisitorAffiliate recognized from actual, id: '.$visitorAffiliate->getId(). ', accountId: '. $visitorAffiliate->getAccountId()); $context->setVisitorAffiliate($visitorAffiliate); }
public function recognize(Pap_Contexts_Tracking $context) { if(($context->getUserObject()) != null) { $context->debug(' User already recognized, finishing user recognizer'); return; } parent::recognize($context); }
public function recognize(Pap_Contexts_Tracking $context) { $fpStatus = $context->getFraudProtectionStatus(); if($fpStatus != null && $fpStatus != '') { $context->debug(" Using status '".$fpStatus."' set by fraud protection"); $context->setStatusForAllCommissions($fpStatus); return; } if($this->getCustomStatus($context)) { return; } }
/** * recognizes commission type for campaign * * @param Pap_Plugins_Tracking_Action_Context $context */ public function getCommissionType(Pap_Contexts_Tracking $context) { $campaign = $context->getCampaignObject(); $context->debug('Recognizing commission type started'); $type = $context->getActionType(); try { $context->debug(' Checking commission type : '.$type.' is in campaign'); $hash = $campaign->getId().$type.Pap_Db_CommissionType::STATUS_ENABLED; if (isset($this->commissionTypesCache[$hash])) { return $this->commissionTypesCache[$hash]; } $commissionType = $campaign->getCommissionTypeObject($type, '', $context->getCountryCode()); $this->commissionTypesCache[$hash] = $commissionType; } catch (Pap_Tracking_Exception $e) { $context->debug(" STOPPING, This commission type is not supported by current campaign or is NOT enabled! "); return; } $context->setCommissionTypeObject($commissionType); $context->getTransaction(1)->setType($type); $context->debug(' Commission type set to: '.$type.', ID: '.$commissionType->getId()); $context->debug('Recognizing commission type ended'); $context->debug(""); }
public function recognize(Pap_Contexts_Tracking $context) { $context->debug('Recognizing affiliate started'); $user = $this->getUser($context); if($user == null) { $context->debug(' Error, no affiliate recognized! setDoSaveCommissions(false)'); $context->setDoTrackerSave(false); $context->setDoCommissionsSave(false); return; } $context->setUserObject($user); $context->debug('Recognizing affiliate ended. Recognized affiliate id: '.$user->getId()); $context->debug(""); }
public function process(Pap_Contexts_Tracking $context) { $context->debug(' Preparing commissions for the click started'); $context->setDoCommissionsSave($this->isValidCommission($context)); if (!$context->getDoCommissionsSave()) { return; } $this->recognizeCommissions($context); if($context->getDoCommissionsSave() && $context->getDoTrackerSave() && $context->getClickStatus() != Pap_Db_ClickImpression::STATUS_DECLINED) { $this->saveCommissions($context); } $context->debug(' Preparing commissions for the click ended'); $context->debug(''); }
/** * @return Pap_Common_Banner */ public function recognizeBanners(Pap_Contexts_Tracking $context) { if ($context->getBannerObject() != null) { $context->debug('Banner oject was set before banner recognizing.'); return $context->getBannerObject(); } try { $banner = $this->getBannerById($context, $context->getBannerIdFromRequest()); $context->debug('Banner is recognized from request parameter.'); return $banner; } catch (Exception $e) { } try { $banner = $this->getBannerById($context, $context->getVisitorAffiliate()->getBannerId()); $context->debug('Banner is recognized from VisitorAffiliate.'); return $banner; } catch (Exception $e) { $context->debug('Banner not recognized'); return; } }
/** * returns user object from user ID stored in default affiliate * * @return string */ private function getDefaultAffiliate(Pap_Contexts_Tracking $context) { $context->debug(" Trying to get default affiliate"); if (Gpf_Settings::get(Pap_Settings::SAVE_UNREFERED_SALE_LEAD_SETTING_NAME) != Gpf::YES) { $context->debug(" Save unreferred sale is not enabled"); return null; } $userId = Gpf_Settings::get(Pap_Settings::DEFAULT_AFFILIATE_SETTING_NAME); if($userId == '') { $context->debug(" No default affiliate defined"); return null; } $userObj = Pap_Affiliates_User::loadFromId($userId); if($userObj == null) { return null; } return $userObj; }
public function saveCommission(Pap_Contexts_Tracking $context, Pap_Common_User $user, Pap_Tracking_Common_Commission $commission) { $context->debug('Saving '.$context->getActionType().' commission started'); $transaction = $context->getTransaction($commission->getTier()); if ($transaction == null) { $transaction = clone $context->getTransaction(1); $transaction->setPersistent(false); $transaction->generateNewTransactionId(); } if (($parentTransaction = $context->getTransaction($commission->getTier() - 1)) != null) { $transaction->setParentTransactionId($parentTransaction->getId()); } if (($channel = $context->getChannelObject()) != null) { $transaction->setChannel($channel->getId()); } $transaction->setTier($commission->getTier()); $transaction->setUserId($user->getId()); $transaction->setCampaignId($context->getCampaignObject()->getId()); $transaction->setAccountId($context->getAccountId()); $banner = $context->getBannerObject(); if (!is_null($banner)) { $transaction->setBannerId($banner->getId()); } if ($user->getStatus() == 'P') { $transaction->setStatus('P'); $context->debug('Commission is saved as pending because user state is in pending'); } else { $transaction->setStatus($commission->getStatus()); } $transaction->setPayoutStatus(Pap_Common_Transaction::PAYOUT_UNPAID); $transaction->setCommissionTypeId($context->getCommissionTypeObject()->getId()); $transaction->setCountryCode(($context->getVisit()!=null)?$context->getVisit()->getCountryCode():''); $transaction->setType($context->getCommissionTypeObject()->getType()); $transaction->setCommission($commission->getCommission($context->getRealTotalCost()-$context->getFixedCost())); $context->debug(' Computed commission is: '.$transaction->getCommission()); $transaction->setClickCount(1); $transaction->setLogGroupId($context->getLoggerGroupId()); if ($transaction->getTier() == 1) { $transaction->setSaleId($transaction->getId()); } else { $transaction->setSaleId($context->getTransaction(1)->getSaleId()); } //check if we can save zero commission if ($transaction->getCommission() == 0 && $context->getCommissionTypeObject()->getSaveZeroCommissions() != Gpf::YES) { $context->debug(' Saving of commission transaction was STOPPED. Saving of zero commissions is disabled. Trans id: '.$transaction->getId()); return Gpf_Plugins_Engine::PROCESS_CONTINUE; } $transactionCompoundContext = new Pap_Common_TransactionCompoundContext($transaction, $context); Gpf_Plugins_Engine::extensionPoint('Tracker.saveCommissions.beforeSaveTransaction', $transactionCompoundContext); if (!$transactionCompoundContext->getSaveTransaction()) { $context->debug(' Saving of commission transaction was STOPPED by plugin. Trans id: '.$transaction->getId()); return Gpf_Plugins_Engine::PROCESS_CONTINUE; } $this->saveTransaction($transaction, $context->getVisitDateTime()); $context->setTransactionObject($transaction, $commission->getTier()); $context->debug(' Commission transaction was successfully saved with ID: '.$transaction->getId()); $context->debug('Saving '.$context->getActionType().' commission ended'); $context->debug(''); return Gpf_Plugins_Engine::PROCESS_CONTINUE; }
/** * @return Gpf_DbEngine_Row_Collection */ private function getTierCommissionCollection(Pap_Contexts_Tracking $context, $userId, $tier) { $context->debug('Loading tier commission collection for userid: ' . $userId . ' and tier: ' . $tier); $commissionTypeId = $context->getCommissionTypeObject()->getId(); $groupId = $this->getCommissionGroupForUser($context->getCampaignObject(), $userId); $hash = $commissionTypeId.$groupId.$tier; if (isset($this->commissions[$hash])) { $context->debug('Record found in cache.'); return $this->commissions[$hash]; } $context->debug('Trying to load commission for typeid:' . $commissionTypeId . ', groupId:' . $groupId . ',tier:' . $tier); $commission = new Pap_Db_Commission(); $commission->setCommissionTypeId($commissionTypeId); $commission->setGroupId($groupId); $commission->setTier($tier); try { $commissions = $this->loadCommissionCollectionFromData($commission); } catch (Gpf_DbEngine_NoRowException $e) { $context->debug('Error loading collection from data. returning empty collection.'); return new Gpf_DbEngine_Row_Collection(); } $context->debug('Commissions succ. loaded, saving to cache.'); $this->commissions[$hash] = $commissions; return $this->commissions[$hash]; }
/** * @param $message * @throws Pap_Tracking_Exception */ protected function logAndThrow(Pap_Contexts_Tracking $context, $message) { $context->debug($message); throw new Pap_Tracking_Exception($message); }
/** * returns campaign object from standard parameter from request * * @return string */ protected function getCampaignFromParameter(Pap_Contexts_Tracking $context) { $campaignId = $context->getCampaignId(); if($campaignId != '') { $context->debug("Getting affiliate from request parameter. Campaign Id: ".$campaignId); return $this->getCampaignById($context, $campaignId); } $this->logAndThrow($context, "Campaign not found in parameter"); }
public function process(Pap_Contexts_Tracking $context) { $context->debug('Preparing for save visitor affiliate'); $cacheCompoundContex = new Pap_Common_VisitorAffiliateCacheCompoundContext($this->visitorAffiliateCache, $context); Gpf_Plugins_Engine::extensionPoint('PostAffiliate.click.beforeSaveVisitorAffiliate', $cacheCompoundContex); if ($cacheCompoundContex->getVisitorAffiliateAlreadySaved()) { $context->debug('VisitorAffiliate already set by plugins, not saving'); return; } Pap_Tracking_Common_VisitorAffiliateCheckCompatibility::getHandlerInstance()->checkCompatibility($context->getVisitorId(), $this->visitorAffiliateCache); $rows = $this->visitorAffiliateCache->getVisitorAffiliateAllRows($context->getVisitorId()); $context->debug('Found ' . $rows->getSize() . ' records in visitorAffiliates'); switch ($rows->getSize()) { case 0: $visitorAffiliate = $this->createAndPrepareVisitorAffiliate($context); $visitorAffiliate->setActual(true); $rows->add($visitorAffiliate); $context->debug('Saving first visitorAffiliate '.$visitorAffiliate->toString()); break; case 1: $lastVisit = $this->createAndPrepareVisitorAffiliate($context); if ($this->isOverWriteEnabled($context) || !$rows->get(0)->isValid()) { $rows->get(0)->setActual(false); $lastVisit->setActual(true); } $context->debug('Adding second visitorAffiliate '.$lastVisit->toString()); $rows->add($lastVisit); break; case 2: if ($this->isOverWriteEnabled($context) || ($rows->get(0)->isActual() && !$rows->get(0)->isValid())) { $rows->get(0)->setActual(false); $this->prepareVisitorAffiliate($rows->get(1), $context); $rows->get(1)->setActual(true); $context->debug('Overwrting second visitor affilite '.$rows->get(1)->toString()); } else { if ($rows->get(1)->isActual() && $rows->get(1)->isValid()) { $rows->add($this->createAndPrepareVisitorAffiliate($context)); $context->debug('Adding third (last) visitor affiliate '.$rows->get(1)->toString()); } else { $this->prepareVisitorAffiliate($rows->get(1), $context); $context->debug('Overwriting second visitor affiliate '.$rows->get(1)->toString()); } } break; case 3: if ($this->isOverWriteEnabled($context) || ($rows->get(1)->isActual() && !$rows->get(1)->isValid())) { for ($i = 1; $i <=2; $i++) { if ($rows->get($i)->isPersistent()) { $rows->get($i)->delete(); $context->debug('Deleting '.$i.' visitoraffiliate ' . $rows->get($i)->toString()); } $rows->remove($i); } $rows->correctIndexes(); $lastVisit = $this->createAndPrepareVisitorAffiliate($context); $lastVisit->setActual(true); $rows->add($lastVisit); $context->debug('Adding third (last) visitor affiliate '.$lastVisit->toString()); } else { $this->prepareVisitorAffiliate($rows->get(2), $context); $context->debug('Overwriting third (last) visitor affiliate '.$rows->get(2)->toString()); } break; default: $context->error('Too many rows per visitor in visitor affiliates table'); break; } $this->checkActualSelected($rows); $context->debug('Finished saving visitor affiliate'); $context->debug(''); }
/** * @return Pap_Db_VisitorAffiliate */ private function findAlreadyStoredVisitorAffiliate(Pap_Tracking_Common_VisitorAffiliateCollection $rows, Pap_Db_VisitorAffiliate $firstClickVisitorAffiliate = null, Pap_Contexts_Tracking $context) { foreach ($rows as $row) { if (!$row->isValid()) { continue; } if ($context->getUserObject()->getId() == $row->getUserId() && $row !== $firstClickVisitorAffiliate) { $context->debug('VisitorAffiliate with affiliate already exist'); return $row; } } return null; }
public function getCommissionGroup(Pap_Contexts_Tracking $context) { if ($context->getCampaignObject()->getCampaignType() != Pap_Db_Campaign::CAMPAIGN_TYPE_PUBLIC) { try { $status = Pap_Db_Table_UserInCommissionGroup::getStatus($context->getCampaignObject()->getId(), $context->getUserObject()->getId()); if ($status != Pap_Features_PerformanceRewards_Condition::STATUS_APPROVED && $status != Pap_Features_PerformanceRewards_Condition::STATUS_FIXED) { throw new Gpf_Exception(''); } } catch (Gpf_Exception $e) { $context->debug(' STOPPING, User is not approved in this campaign!'); $context->setDoCommissionsSave(false); $context->setDoTrackerSave(false); } } }
/** * recomputes total cost to default currency * * @return unknown */ public function computeRealTotalCost(Pap_Contexts_Tracking $context) { if($context->getActionType() != Pap_Common_Constants::TYPE_ACTION) { $context->debug('Setting commission to 0 as the transaction type is not sale/action but '.$context->getActionType()); return 0; } $this->recognizeCurrency->processTotalCost($context); $newTotalCost = $this->computeRealCost($context,$context->getRealTotalCost() ,'realTotalCost'); $context->debug('Setting realTotalCost to '.$newTotalCost); $context->setRealTotalCost($newTotalCost); }
protected function setParentBannerNotExistsDebug(Pap_Contexts_Tracking $context) { $context->debug(' FEATURE BannerRotator: Parent banner is not exists, skipping'); }