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); }
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 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(""); }