Ejemplo n.º 1
0
 protected function computeCommission(Pap_Contexts_Action $context, Pap_Common_Transaction $transaction, Pap_Common_User $user, $tier){
     if (Gpf_Settings::get(TopLevelAffiliateFixedCommision_PluginConfig::USE_FIRST_TIER_COMMISSION)==Gpf::YES && $tier == 1) {
         return null;
     }
     $commissionPercentage = $this->getFixedCommissionPercentage($transaction->getCommissionTypeId());
     if ($commissionPercentage == TopLevelAffiliateFixedCommision_Config::UNDEFINED_PERCENTAGE) {
         return null;
     }
     return ($context->getRealTotalCost()-$context->getFixedCost()) / 100 * $commissionPercentage;
 }
    /**
     * @param Pap_Db_VisitorAffiliate
     * @return Pap_Db_VisitorAffiliate
     */
    public function recognizeAffiliate(Pap_Db_VisitorAffiliate $visitorAffiliate) {
        $user = $this->getUserById($visitorAffiliate->getUserId());

        if ($user == null) {
            $this->isValid = false;
            return;
        }
        
        $this->context->setUserObject($user);

        $campaign = $this->getCampaignById($visitorAffiliate->getCampaignId());
        if ($campaign != null && $this->context->getCampaignObject() == null) {
            $this->context->setCampaignObject($campaign);
        }

        $banner = $this->getBannerById($visitorAffiliate->getBannerId());
        if ($banner != null && $this->context->getBannerObject() == null) {
            $this->context->setBannerObject($banner);
        }

        $channel = $this->getChannelById($visitorAffiliate->getChannelId());
        if ($channel != null) {
            $this->context->setChannelObject($channel);
        }
        $this->context->setVisitorAffiliate($visitorAffiliate);

        $this->isValid = true;
    }
Ejemplo n.º 3
0
    protected function executeCurl($xmlRequest, $headers) {
        $url = '';
        if (!$this->containsProtocol(Gpf_Settings::get(BusinessCatalyst_Config::BC_DOMAIN_NAME))) {
            $url = 'http://';
        }

        $url .= Gpf_Settings::get(BusinessCatalyst_Config::BC_DOMAIN_NAME);

        if (!$this->endsWithSlash($url)) {
            $url .= '/';
        }

        $url .= 'catalystwebservice/catalystcrmwebservice.asmx';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);

        $response = curl_exec($ch);
        if ($response === false) {
            Pap_Contexts_Action::getContextInstance()->debug('Error in communication with bc: ' . curl_error($ch));
            throw new Gpf_Exception(curl_error($ch));
        }
        return $response;
    }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
    /**
     * registers all created sales
     */
    public function register() {
        if(!is_array($this->actionInstances)) {
            return;
        }

        $context = Pap_Contexts_Action::getContextInstance();

        if(count($this->actionInstances) <= 0) {
            $context->debug('No sales to register, create sale using createSale() function first!');
            return;
        }

        $this->track();
    }
Ejemplo n.º 6
0
    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;
    }
    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;
    }
Ejemplo n.º 8
0
    private function getEntityVisitorId($xml, $customFieldName) {
        $fieldName = '<fieldName>'.$customFieldName.'</fieldName>';
        $fieldValueLength = strlen('<fieldValue>');

        //no visitor ID in this XML response:
        if (strpos(strtolower($xml), strtolower($fieldName)) === false) {
            Pap_Contexts_Action::getContextInstance()->debug('BusinessCatalyst: no VisitorID found');
            return;
        }

        $begin = strpos(strtolower($xml), strtolower($fieldName)) + strlen($fieldName) + strlen('<fieldValue>');

        $end = strpos(strtolower($xml), strtolower('</fieldValue>'), $begin);

        $fieldValue = substr($xml, $begin, $end - $begin);

        if (($visitorIdEnd = strpos($fieldValue, ';')) !== false) {
            $fieldValue = substr($fieldValue, 0, $visitorIdEnd);
        }

        return $fieldValue;
    }
 /**
  * @throws Gpf_Exception
  * @return Pap_Tracking_Common_VisitorAffiliateCollection
  */
 protected function getVisitorAffiliatesCollection(Pap_Contexts_Action $context) {
     return $this->visitorAffiliateCache->getVisitorAffiliateAllRows($context->getVisitorAffiliate()->getVisitorId());
 }
    /**
     * 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;
 }
Ejemplo n.º 12
0
 protected function getNumberOfAllTransactionPerReferralFromContext(Pap_Contexts_Action $context, $commissionTypeId, $maxReferralTimePeriod) {
    return $this->getNumberOfAllTransactionPerReferral($context->getProductIdFromRequest(), 
         $context->getUserObject()->getId(), $commissionTypeId, $maxReferralTimePeriod);
 }
Ejemplo n.º 13
0
 public function debug($message) {
     if($message == "") {
         Pap_Contexts_Action::getContextInstance()->debug("");
     } else {
         Pap_Contexts_Action::getContextInstance()->debug($this->getTrackerName().': '.$message);
     }
 }
Ejemplo n.º 14
0
    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);
    }
Ejemplo n.º 15
0
 /**
  * @return Pap_Contexts_Action
  */
 public static function getContextInstance() {
     if (self::$instance == null) {
         self::$instance = new Pap_Contexts_Action();
     }
     return self::$instance;
 }
 /**
  * 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()));
 }
Ejemplo n.º 17
0
 private function setRecognizedParams(Pap_Contexts_Action $context) {
     $context->setUserObject($this->affiliate);
     $context->setBannerObject($this->banner);
     $context->setCampaignObject($this->campaign);
     $context->setAccountId($this->campaign->getAccountId(), Pap_Contexts_Tracking::ACCOUNT_RECOGNIZED_FROM_CAMPAIGN);
     $context->setTrackingMethod(Pap_Common_Transaction::TRACKING_METHOD_COUPON);
     $context->getTransaction()->setCouponId($this->coupon->getId());
     $context->getTransaction()->set(Pap_Db_Table_Transactions::BANNER_ID, $this->banner->getId());
 }
Ejemplo n.º 18
0
    public function readRequestVariables() {
        $request = Pap_Contexts_Action::getContextInstance()->getRequestObject();

        // assign posted variables to local variables
        $this->setCookie(stripslashes($request->getRequestParameter('M_aid')));
        $this->setTotalCost($request->getRequestParameter('amount'));
        $this->setTransactionID($request->getRequestParameter('transId'));
        $this->setProductID($request->getRequestParameter('M_ProductID'));
        $this->setDescription($request->getRequestParameter('desc'));
        $this->setCurrency($request->getRequestParameter('authCurrency'));
        if ($this->parseFuturePayIdFromDescription($request->getRequestParameter('desc'))===false) {
            $this->setData5($request->getRequestParameter('futurePayId'));
        } else {
            $this->setData4($this->parseFuturePayIdFromDescription($request->getRequestParameter('desc')));
            $this->setData3($this->parsePaymentNumberFromDescription($request->getRequestParameter('desc')));
        }
    }
    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("");
    }
Ejemplo n.º 20
0
    public function processRefundChargeback($id, $type, $note = '', $orderId = '', $fee = 0, $refundTiers = false) {
        Pap_Contexts_Action::getContextInstance()->debug('Process refund on transaction: '.$id);
        $childTansactions = $this->getTransactionsByParent($refundTiers, $id);    

        $transaction = $this->getTransaction($id);
        try {
            $transaction->refundChargeback($type, $note, $orderId, $fee);
        } catch (Gpf_Exception $e) {
            Pap_Contexts_Action::getContextInstance()->debug($e->getMessage());
        } 
        
        if (!$refundTiers) {
            Pap_Contexts_Action::getContextInstance()->debug('No MultiTier children transactions refunds set');            
            return;
        }      
        
        foreach ($childTansactions as $childTransaction) {
            $this->processRefundChargeback($childTransaction->getId(), $type, $note, $orderId, $fee, true);
        }        
    }
Ejemplo n.º 21
0
 	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");
 		}
 	}
Ejemplo n.º 22
0
 private function getTransactionType(Pap_Contexts_Action $context) {
     $actionCode = $context->getActionCodeFromRequest();
     if ($actionCode == null || $actionCode == '') {
         return Pap_Common_Constants::TYPE_SALE;
     } else {
         return Pap_Common_Constants::TYPE_ACTION;
     }
 }
Ejemplo n.º 23
0
    private function parseVisitorId($xml, $customFieldName) {
        $fieldName = '<fieldName>'.$customFieldName.'</fieldName>';

        if (strpos(strtolower($xml), strtolower($fieldName)) === false) { //no custom field found in this XML
            Pap_Contexts_Action::getContextInstance()->debug('BusinessCatalyst: no custom field found');
            return '';
        }

        if (!strstr($xml, '<fieldValue>') && strstr($xml, '<fieldValue/>')) {
            Pap_Contexts_Action::getContextInstance()->debug('BusinessCatalyst: custom field value is empty');
            return '';
        }

        $begin = strpos(strtolower($xml), strtolower($fieldName)) + strlen($fieldName);
        $begin = strpos(strtolower($xml), strtolower('<fieldValue>'), $begin) + strlen('<fieldValue>');
        $end = strpos(strtolower($xml), strtolower('</fieldValue>'), $begin);
        $fieldValue = substr($xml, $begin, $end - $begin);

        if (($visitorIdEnd = strpos($fieldValue, ';')) !== false) {
            $fieldValue = substr($fieldValue, 0, $visitorIdEnd);
        }

        return $fieldValue;
    }
    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);
    }
Ejemplo n.º 25
0
    private function process(Pap_Contexts_Action $context) {
        $currencyCode = $context->getCurrencyFromRequest();
        if ($currencyCode == '') {
            throw new Gpf_Exception('Currency code is not defined');
        }

        if ($currencyCode == $context->getDefaultCurrencyObject()->getName()) {
            throw new Gpf_Exception('Currency is the same as default currency');
        }

        $currency = new Gpf_Db_Currency();
        try {
            $currency = $currency->findCurrencyByCode($currencyCode);
        } catch (Gpf_DbEngine_NoRowException $e) {
            throw new Gpf_Exception('Currency does not exist');
        }
        return $currency;
    }
 protected function getContexts() {
     return Pap_Contexts_Action::getContextInstance();
 }
Ejemplo n.º 27
0
 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());
     }
 }
 /**
  * @param Pap_Contexts_Action $context
  * @return Pap_Db_CommissionType
  */
 protected function getCommissionType(Pap_Contexts_Action $context) {
     $campaign = $context->getCampaignObject();
     
     $actionCode = $context->getActionCodeFromRequest();
     if ($actionCode != '') {
         return $campaign->getCommissionTypeObject(Pap_Common_Constants::TYPE_ACTION, $actionCode, $context->getVisit()->getCountryCode());
     } else {
         return $campaign->getCommissionTypeObject(Pap_Common_Constants::TYPE_SALE, '', $context->getVisit()->getCountryCode());
     }
 }
Ejemplo n.º 29
0
 /**
  *  @return Pap_Tracking_Request
  */
 protected function getRequestObject() {
     return Pap_Contexts_Action::getContextInstance()->getRequestObject();
 }
  /**
  * 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("");
 }