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);
    }
    protected function prepareContextForSave(Pap_Contexts_Action $context) {
        $transaction = $context->getTransaction();
        $transaction->setOrderId($context->getOrderIdFromRequest());
        $transaction->setProductId($context->getProductIdFromRequest());
        $transaction->setTotalCost($context->getRealTotalCost());
        $transaction->setFixedCost($context->getFixedCost());
        $transaction->setCountryCode($context->getCountryCode());

        if($context->getChannelObject() !== null) {
            $transaction->setChannel($context->getChannelObject()->getId());
        }
        if($context->getBannerObject() !== null) {
            $transaction->setBannerId($context->getBannerObject()->getId());
        }

        $transaction->setData1($context->getExtraDataFromRequest(1));
        $transaction->setData2($context->getExtraDataFromRequest(2));
        $transaction->setData3($context->getExtraDataFromRequest(3));
        $transaction->setData4($context->getExtraDataFromRequest(4));
        $transaction->setData5($context->getExtraDataFromRequest(5));

        $transaction->setDateInserted($context->getVisitDateTime());

        $transaction->setVisitorId($context->getVisitorId());
        $transaction->setTrackMethod($context->getTrackingMethod());
        $transaction->setIp($context->getIp());
        try {
            $transaction->setRefererUrl($context->getVisitorAffiliate()->getReferrerUrl());
        } catch (Gpf_Exception $e) {
            $transaction->setRefererUrl($context->getReferrerUrl());
        }

        try {
            $visitorId = $context->getVisitorAffiliate()->getVisitorId();
        } catch (Exception $e) {
            $visitorId = $this->_('unknown');
        }
        
        try {
            $this->setFirstAndLastClick($transaction, $this->getVisitorAffiliatesCollection($context));
        } catch (Gpf_Exception $e) {
            $context->debug('First and Last click can not be recognized for visitorId: ' . $visitorId . '. ' . $e->getMessage());
        }
    }
    /**
     * checks for duplicate records from same IP
     *
     * @param Pap_Contexts_Action $context
     * @return string
     */
    private function checkSalesFromBannedIP(Pap_Contexts_Action $context) {
        $checkIt = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SALES);
        if($checkIt != Gpf::YES) {
            $context->debug('    Check for sales / leads with banned IP is not turned on');
            return true;
        }

        $context->debug('    Checking banned IP address of sales / leads started');


        $bannedIPAddresses = Gpf_Net_Ip::getBannedIPAddresses(Pap_Settings::BANNEDIPS_LIST_SALES);

        if($bannedIPAddresses === false) {
            $context->debug("List of banned IP addresses is invalid or empty, stop checking");
            return true;
        }

        $checkAction = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SALES_ACTION);
        if($checkAction != self::ACTION_DECLINE && $checkAction != self::ACTION_DONTSAVE) {
            $context->debug("Action after check is not correct: '$checkAction'");
            return true;
        }

        $ip = $context->getIp();
        if(Gpf_Net_Ip::ipMatchRange($ip, $bannedIPAddresses)) {
            if($checkAction == self::ACTION_DONTSAVE) {
                $context->debug("    STOPPING (setting setDoCommissionsSave(false), IP: $ip is banned");
                $context->setDoCommissionsSave(false);
                $context->debug('      Checking banned IP of sales / leads endeded');
                return false;

            } else {
                $context->debug("  DECLINING, IP is banned: $ip");

                $message = Gpf_Settings::get(Pap_Settings::BANNEDIPS_SALES_MESSAGE);

                $this->declineAction($context, $message);

                $context->debug('      Checking banned IP of sales / leads endeded');
                return true;
            }
        } else {
            $context->debug("    IP $ip is not banned");
        }

        $context->debug('      Checking banned IP of sales / leads endeded');
        return true;
    }