public function displayAffiliateTrackingCode(Pap_Contexts_Action $context) { if ($context->getDoCommissionsSave() == false) { $context->debug('AffiliateTrackingCode: commissions were not saved. stopping'); return; } $commissionType = $context->getCommissionTypeObject(); $affiliate = $context->getUserObject(); if ($commissionType == null || $affiliate == null) { $context->debug('AffiliateTrackingCode: no affiliate or commission type. stopping'); return; } if ($context->getTransactionObject()->getTransactionId() == '') { $context->debug('AffiliateTrackingCode: no transaction saved for affiliate: ' . $affiliate->getId() . '. stopping'); return; } try { $affiliateTrackingCode = $this->loadAffiliateTrackingCode($commissionType, $affiliate); } catch (Gpf_Exception $e) { $context->debug('AffiliateTrackingCode: no approved code for this affiliate'); return $context; } $affiliateTrackingCode->setCode($this->replaceTransactionConstants($affiliateTrackingCode->getCode(), $context->getTransactionObject())); $this->printAffiliateTrackingCode($affiliateTrackingCode); }
protected function getCommission($tier, Pap_Contexts_Action $context) { $commissionPercentage = $this->getFixedCommissionPercentage($context->getTransaction()->getCommissionTypeId()); if ($commissionPercentage == TopLevelAffiliateFixedCommision_Config::UNDEFINED_PERCENTAGE) { $context->debug('TopLevelAffiliateFixedCommision undefined for this commission group.'); return null; } $context->debug('TopLevelAffiliateFixedCommision defined '.$commissionPercentage.' for this commission group.'); return new Pap_Tracking_Common_Commission($tier, Pap_Db_CommissionType::COMMISSION_PERCENTAGE, $commissionPercentage); }
public function process(Pap_Contexts_Action $context) { $context->debug('Started checking md5 checksums'); $checksum = $context->getExtraDataFromRequest(Gpf_Settings::get(SaleFraudProtection_Config::PARAM_NAME)); $myChecksum = $this->createCheckSum($context->getTotalCostFromRequest(), $context->getOrderIdFromRequest()); if ($checksum == $myChecksum) { $context->debug('Checkings md5 checksums finished. Checksums equals.'); return; } $context->debug('Checking md5 checksums failed. Transaction not saved. Checksums: '.$checksum.' - '.$myChecksum); $context->setDoCommissionsSave(false); }
private function computeFixedCost(Pap_Contexts_Action $context) { $context->debug('Recognizing fixedCost currency started'); $defaultCurrency = $this->getDefaultCurrency(); $context->debug(" Default currency is ".$defaultCurrency->getName()); $context->set("defaultCurrencyObject", $defaultCurrency); if ($context->getCurrencyFromRequest() != '') { Gpf_Plugins_Engine::extensionPoint('Tracker.action.computeFixedCost', $context); } $context->debug('Recognizing fixedCost currency ended'); $context->debug(""); return Gpf_Plugins_Engine::PROCESS_CONTINUE; }
/** * * @param $context */ public function setSaveCommission(Pap_Contexts_Action $context) { $context->debug('MaxCommission per referral checking.'); $commissionTypeId = $this->getCommissionTypeId($context); if ($commissionTypeId == null) { $context->debug('MaxCommission Commission type is null. Ended.'); return; } try { $maxReferralNumber = $this->getMaxReferralLimitNumber($commissionTypeId); } catch (Gpf_DbEngine_NoRowException $e) { $context->debug('MaxCommission limit per referral is not defined. Ended.'); return; } if ($maxReferralNumber == '' || $maxReferralNumber <= -1) { $context->debug('MaxCommission limit is not set.'); return; } try { $maxReferralTimePeriod = $this->getMaxReferralLimitTimePeriod($commissionTypeId); } catch (Gpf_DbEngine_NoRowException $e) { $maxReferralTimePeriod = -1; } $numberOfCommission = $this->getNumberOfAllTransactionPerReferralFromContext($context, $commissionTypeId, $maxReferralTimePeriod); if ($numberOfCommission < $maxReferralNumber) { $context->debug('MaxCommission per referral limit is not full ('.$numberOfCommission.'/ '.$maxReferralNumber.'). Saved. Ended.'); return; } $context->setDoCommissionsSave(false); $context->debug('MaxCommission per referral is full (' . $numberOfCommission . '). Commission will be NOT SAVED. Ended.'); }
protected function getCustomStatus(Pap_Contexts_Action $context) { $context->debug(" Trying to get custom status from request parameter '".Pap_Tracking_ActionRequest::PARAM_ACTION_CUSTOM_STATUS."'"); $status = $context->getCustomStatusFromRequest(); if($status != '') { $context->debug(" Found custom status: ".$status.", checking"); if(in_array($status, array(Pap_Common_Constants::STATUS_APPROVED, Pap_Common_Constants::STATUS_PENDING, Pap_Common_Constants::STATUS_DECLINED))) { $context->debug(" Setting custom status to $status"); $context->setStatusForAllCommissions($status); return true; } else { $context->debug(" Custom status is incorrect, it must be one of: A, P, D"); } } return false; }
public function recognize(Pap_Contexts_Action $context) { if ($context->isVisitorAffiliateRecognized()) { return; } if(Gpf_Settings::get(Pap_Settings::TRACK_BY_IP_SETTING_NAME) != Gpf::YES) { return; } $ip = $context->getIp(); $context->debug('Trying to get visitor affiliate from IP address '. $ip); $visitorAffiliate = $this->visitorAffiliateCache->getLatestVisitorAffiliateFromIp($ip, $context->getAccountId()); if ($visitorAffiliate == null) { $context->debug("No visitor affiliate from IP '$ip'"); return; } try { $periodInSeconds = $this->getValidityInSeconds(); } catch (Gpf_Exception $e) { $context->debug($e->getMessage()); return; } $dateFrom = new Gpf_DateTime($context->getVisitDateTime()); $dateFrom->addSecond(-1*$periodInSeconds); $dateVisit = new Gpf_DateTime($visitorAffiliate->getDateVisit()); if ($dateFrom->compare($dateVisit) > 0) { $context->debug(" No click from IP '$ip' found within ip validity period"); return null; } if (!$context->isTrackingMethodSet()) { $context->setTrackingMethod(Pap_Common_Transaction::TRACKING_METHOD_IP_ADDRESS); } $context->debug('Visitor affiliate recognized from IP, id: '.$visitorAffiliate->getId(). ', accountId: '. $visitorAffiliate->getAccountId()); $context->setVisitorAffiliate($visitorAffiliate); }
/** * recognizes commission type for campaign * * @param Pap_Plugins_Tracking_Action_Context $context */ public function getCommissionType(Pap_Contexts_Action $context) { $campaign = $context->getCampaignObject(); $context->debug('Recognizing commission type started'); $actionCode = $context->getActionCodeFromRequest(); if ($actionCode == null || $actionCode == '') { $type = Pap_Common_Constants::TYPE_SALE; } else { $type = Pap_Common_Constants::TYPE_ACTION; } try { $context->debug(' Checking commission type : '.$type.' is in campaign'); $commissionType = $campaign->getCommissionTypeObject($type, $context->getActionCodeFromRequest(), $context->getVisit()->getCountryCode()); } catch (Pap_Tracking_Exception $e) { $context->debug(" STOPPING, This commission type is not supported by current campaign or is NOT enabled! "); throw $e; } $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 getCommissionType(Pap_Contexts_Action $context) { $context->debug("Begin recognizing country specific commission type"); if(!strlen($context->getTransactionObject()->getCountryCode())) { $context->debug("STOPPING recognizing country specific commission type eneded: country code not recognized or empty"); return; } $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Pap_Db_Table_CommissionTypes::getInstance()); $select->from->add(Pap_Db_Table_CommissionTypes::getName()); $select->where->add(Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '=', $context->getCommissionTypeObject()->getId()); $compoundContext = new Gpf_Data_Record(array(Pap_Db_Table_RawImpressions::IP, Pap_Db_Table_Impressions::COUNTRYCODE), array($context->getVisit()->getIp(), '')); $this->getCountryCode($compoundContext); $countryCode = $compoundContext->get(Pap_Db_Table_Impressions::COUNTRYCODE); if (!strlen($countryCode)) { $context->debug("STOPPING recognizing country specific commission type eneded: country code not recognized or empty"); return; } $select->where->add(Pap_Db_Table_CommissionTypes::COUNTRYCODES, 'LIKE', '%'.$countryCode.'%'); try { $commType = new Pap_Db_CommissionType(); $collection = $commType->loadCollectionFromRecordset($select->getAllRows()); $context->setCommissionTypeObject($collection->get(0)); } catch (Gpf_DbEngine_NoRowException $e) { $context->debug("Recognizing country specific commission type eneded - no country secpific commission defined"); return; } catch (Gpf_DbEngine_TooManyRowsException $e) { $context->debug("STOPPING ecognizing country specific commission type eneded: more than one commision type is defined for country " . $context->getTransactionObject()->getCountryCode()); return; } catch (Gpf_Exception $e) { $context->debug("STOPPING recognizing country specific commission type eneded: " . $e->getMessage()); } }
public function computeCommission(Pap_Contexts_Action $context) { $context->debug('MC commision'); if (Gpf_Settings::get(Pap_Settings::MULTIPLE_CURRENCIES) == 'N') { return; } $context->debug('Multiple currencies started'); try { $currency = $this->process($context); } catch (Gpf_Exception $e) { $context->debug('STOPING with exception: ' . $e->getMessage()); return; } $commissionValue = $context->getCommission(1,Pap_Db_Table_Commissions::SUBTYPE_NORMAL)->getValue(); $commissionType = $context->getCommission(1,Pap_Db_Table_Commissions::SUBTYPE_NORMAL)->getType(); $context->debug('commission recomputed from '.$commissionValue.' to '.$commissionValue * $currency->getExchangeRate()); $context->removeCommission(1); $context->addCommission(new Pap_Tracking_Common_Commission(1, $commissionType, $commissionValue * $currency->getExchangeRate())); $context->debug('commision was successfully recomputed'); }
/** * returns campaign object from Product ID stored in request parameter */ private function getCampaignFromProductID(Pap_Contexts_Action $context) { $context->debug('Trying to get campaign from Product ID: '.$context->getProductIdFromRequest()); return $this->getCampaignById($context, $this->recognizeCampaignIdByProductId->recognizeCampaignId($context, $context->getProductIdFromRequest())); }
private function saveReferral(Pap_Contexts_Action $context) { $transactionObject = $context->getTransactionObject(); if($transactionObject == null) { $context->debug(' Transaction object is null'); return; } $identifier = $this->getIdentifier($context); if($identifier == null || $identifier == '') { $context->debug(" Identifier (data1) is empty, stopping"); return; } $userId = $transactionObject->get(Pap_Db_Table_Transactions::USER_ID); $context->debug(" User is '$userId'"); $context->debug(" Identifier (data1) is '$identifier'"); $lifetimeCommission = new Pap_Db_LifetimeCommission(); $lifetimeCommission->setIdentifier($identifier); $lifetimeCommission->setUserId($userId); try { $lifetimeCommission->loadFromData(array(Pap_Db_Table_LifetimeCommissions::IDENTIFIER)); $context->debug(" Lifetime referral: identifier '$identifier' already exists for user: "******" New lifetime referral: identifier '$identifier' <-> user '$userId' inserted"); } }
private function recognizeCampaign(Pap_Contexts_Action $context) { if ($this->banner == null) { return; } $context->debug("Checking campaign with Id: ".$this->banner->getCampaignId()); if ($this->banner->getCampaignId() != null) { try { $this->campaign = $this->getCampaign($this->banner->getCampaignId()); } catch (Gpf_Exception $e) { $context->debug("Campaign with id: " . $this->banner->getCampaignId() . " doesn't exist"); } } }
private function saveCommissions(Pap_Contexts_Action $context) { $context->debug('Saving commissions started'); Gpf_Plugins_Engine::extensionPoint('Tracker.action.beforeSaveCommissions', $context); if (!$context->getDoCommissionsSave()) { $context->debug('Commissions save stopped by plugin.'); return; } $this->saveCommission($context); Gpf_Plugins_Engine::extensionPoint('Tracker.action.afterSaveCommissions', $context); $context->debug("Saving commissions ended"); }
/** * returns campaign object from user ID stored in custom cookie parameter */ private function getChannelFromParameter(Pap_Contexts_Action $context) { $context->debug('Trying to get channel from forced parameter '.Pap_Tracking_ActionRequest::PARAM_ACTION_CHANNELID); return $this->getChannelById($context, $context->getChannelIdFromRequest()); }
/** * checks that user with this ID exists and is correct * * @param Pap_Contexts_Action $context * @param string $userId * @param string $trackingMethod * @return Pap_Common_User */ protected function getCorrectUser(Pap_Contexts_Action $context, $userId, $trackingMethod) { $context->debug('Checking affiliate with Id: '.$userId); $userObj = $this->getUserById($context, $userId); if($userObj == null) { return null; } if ($context->getTrackingMethod() == '') { $context->setTrackingMethod($trackingMethod); } return $userObj; }
/** * checks for duplicate records with same OrderID * * @param Pap_Contexts_Action $context * @return string */ private function checkMultipleSalesWithSameOrderID(Pap_Contexts_Action $context) { $checkIt = Gpf_Settings::get(Pap_Settings::DUPLICATE_ORDERS_ID_SETTING_NAME); if($checkIt != Gpf::YES) { $context->debug(' Check for duplicate sales / leads with the same OrderID is not turned on'); return true; } $context->debug(' Checking duplicate sales / leads with the same OrderID started'); $checkPeriod = Gpf_Settings::get(Pap_Settings::DUPLICATE_ORDER_ID_HOURS_SETTING_NAME); $checkAction = Gpf_Settings::get(Pap_Settings::DUPLICATE_ORDERS_ID_ACTION_SETTING_NAME); if($checkPeriod == '' || $checkPeriod == '0' || !is_numeric($checkPeriod)) { $context->debug("Checking period is not correct: '$checkPeriod'"); return true; } if($checkAction != self::ACTION_DECLINE && $checkAction != self::ACTION_DONTSAVE) { $context->debug("Action after check is not correct: '$checkAction'"); return true; } $orderId = $context->getOrderIdFromRequest(); $transactionsObject = $context->getTransactionObject(); if(trim($orderId) == '') { $applyToEmptyOrderIDs = Gpf_Settings::get(Pap_Settings::APPLY_TO_EMPTY_ID_SETTING_NAME); if($applyToEmptyOrderIDs != Gpf::YES) { $context->debug(' Order ID is empty, we do not aply fraud protection to empty order IDs'); return false; } } $transactionType = $this->getTransactionType($context); $parentTransactionId = $context->getParentTransactionId(); $recordsCount = $transactionsObject->getNumberOfRecordsWithSameOrderId($orderId, $transactionType, $checkPeriod, $parentTransactionId, $context->getVisitDateTime()); $context->debug("Getting number of transactions orderId=$orderId, type=$transactionType, not older than $checkPeriod hours, and not with parent transaction with id=$parentTransactionId returned $recordsCount"); if($recordsCount > 0) { if($checkAction == self::ACTION_DONTSAVE) { $context->debug(" STOPPING (setting setDoCommissionsSave(false), found another sales / leads from the same OrderID '$orderId' within $checkPeriod hours"); $context->setDoCommissionsSave(false); $context->debug(' Checking duplicate sales / leads with the same OrderID endeded'); return false; } else { $context->debug(" DECLINING, found another sales / leads with the same OrderID '$orderId' within $checkPeriod hours"); $message = Gpf_Settings::get(Pap_Settings::DUPLICATE_ORDERS_ID_MESSAGE_SETTING_NAME); $this->declineAction($context, $message); $context->debug(' Checking duplicate sales / leads with the same OrderID endeded'); return true; } } else { $context->debug(" No duplicate sales / leads with the same OrderID '$orderId' found"); } $context->debug(' Checking duplicate sales / leads with the same OrderID endeded'); return true; }
public function computeCustomCommissions(Pap_Contexts_Action $context) { $context->debug('Custom commission computing started'); $commission = $context->getCustomCommissionFromRequest(); if($commission != '') { $context->debug(" Found custom commission: ".$commission.", decoding"); $type = $this->getParameterType($commission); $commission = $this->makeCorrections($commission); $value = ''; if(is_numeric($commission) && $commission >= 0) { $value = $commission; } if($value != '') { $context->debug(" Custom commission is $type $value"); $i = 1; while ($context->getCommission($i) != null) { $context->removeCommission($i++); } $newCommission = new Pap_Tracking_Common_Commission(1, $type, $value); $newCommission->setStatus($this->recognizeStatus($context->getCommissionTypeObject())); $context->addCommission($newCommission); if ($type!='%'){ $this->recognizeCurrency->computeCustomCommission($context); } } else { $context->debug(" Custom commission has bad format"); } } else { $context->debug('No custom commission defined'); } $context->debug('Checking for forced commissions ended'); $context->debug('Custom commission computing ended'); $context->debug(""); }