Пример #1
0
 protected function processAccountIdAndVisitorId(Pap_Tracking_ActionTracker $saleTracker, $cookie) {
     parent::processAccountIdAndVisitorId($saleTracker, $cookie);
     if (Gpf_Settings::get(PayPal_Config::APPROVE_AFFILIATE) == Gpf::YES) {
         $this->debug('Automatic approval of affiliates with sale is enabled');
         $userId = $this->computeAffiliateId($saleTracker->getVisitorId(), $saleTracker->getAccountId());
         try {
             $affiliate = new Pap_Common_User();
             $affiliate->setId($userId);
             $affiliate->load();
             if ($affiliate->getStatus() == Pap_Common_Constants::STATUS_PENDING) {
                 $affiliate->setStatus(Pap_Common_Constants::STATUS_APPROVED);
                 $affiliate->update();
             }
         } catch (Gpf_Exception $e) {
             $this->debug('Error occured during approving affiliate with id=' . $userId);
         }
     }
 }
   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;
    }
Пример #3
0
	/**
	 * gets user by user id
	 * @param $userId
	 * @return Pap_Common_User
	 */
	protected function getUserById($context, $id) {
		if($id == '') {
			return null;
		}

		// try to get user by userid
		$user = new Pap_Common_User();
		$user->setPrimaryKeyValue($id);
		try {
			$user->load();
			if($user->getStatus() == Pap_Common_Constants::STATUS_DECLINED) {
				$context->debug("    User with UserId: $id found, but he is declined. We'll not use him.");
				return null;
			}

			$context->debug("    User with UserId: $id found and valid (approved or pending)");
			return $user;
		} catch (Gpf_DbEngine_NoRowException $e) {
			$context->debug("    User with UserId: $id doesn't exist");
			return null;
		}
	}