/**
  * @return Gpf_Settings_AccountSettings
  */
 protected function createAccountSettings() {
 	$campaign = new Pap_Common_Campaign();
 	$campaign->setId($this->transaction->getCampaignId());
 	try {
 		$campaign->load();
 		return Gpf_Settings::getAccountSettings($campaign->getAccountId());
 	} catch (Gpf_Exception $e) {
 	}
 	return Gpf_Settings::getAccountSettings(Gpf_Db_Account::DEFAULT_ACCOUNT_ID);
 }
Exemplo n.º 2
0
 public function updateCommission(Pap_Common_Transaction $transaction) {
 	if ($transaction->getType() != Pap_Db_Transaction::TYPE_SALE) {
 	    return;
 	}
     try {
         $minTotalCost = $this->createCampaignAttribute()->getSetting(SaleFilter_Definition::NAME_MINIMUM_TOTALCOST, $transaction->getCampaignId());
         if ($transaction->getTotalCost() < $minTotalCost) {
             $transaction->setCommission(0);
         }
     } catch (Gpf_DbEngine_NoRowException $e) {
     }
     try {
         $maxTotalCost = $this->createCampaignAttribute()->getSetting(SaleFilter_Definition::NAME_MAXIMUM_TOTALCOST, $transaction->getCampaignId());
         if ($maxTotalCost > 0 && $transaction->getTotalCost() > $maxTotalCost) {
             $transaction->setCommission(0);
         }
     } catch (Gpf_DbEngine_NoRowException $e) {
     }
 }
    public function getTransactionFieldValue($code) {
        if($this->transaction == null) {
            throw new Gpf_Exception("You have to set Transaction before getting transaction fields value!");
        }

        if($code == self::TRANSACTIONID) {
            return $this->transaction->get(Pap_Db_Table_Transactions::TRANSACTION_ID);
        } else if($code == self::COMMISSION) {
            return $this->transaction->getCommissionAsText();
        } else if($code == self::TOTALCOST) {
            return $this->transaction->getTotalCostAsText();
        } else if($code == self::ORDERID) {
            return $this->transaction->getOrderId();
        } else if($code == self::PRODUCTID) {
            return $this->transaction->getProductId();
        } else if($code == self::TIER) {
            return $this->transaction->getTier();
        } else if($code == self::CAMPAIGNID) {
            return $this->transaction->getCampaignId();
        } else if($code == self::CAMPAIGNNAME) {
            return $this->getCampaignName($this->transaction->getCampaignId());
        } else if($code == self::STATUS) {
            return $this->getStatus($this->transaction->getStatus());
        } else if($code == self::STATUSCODE) {
            return $this->transaction->getStatus();
        } else if($code == self::TYPE) {
            return $this->getType($this->transaction->getType());
        } else if($code == self::RAWTYPE) {
            return $this->transaction->getType();
        } else if($code == self::ACTIONNAME) {
            return $this->getActionName($this->transaction->getType(), $this->transaction->getCommissionTypeId());
        } else if($code == self::SALEDATA1) {
            return $this->transaction->getData1();
        } else if($code == self::SALEDATA2) {
            return $this->transaction->getData2();
        } else if($code == self::SALEDATA3) {
            return $this->transaction->getData3();
        } else if($code == self::SALEDATA4) {
            return $this->transaction->getData4();
        } else if($code == self::SALEDATA5) {
            return $this->transaction->getData5();
        } else if($code == self::ORIGINALCURRENCY) {
            return $this->getOriginalCurrencyName($this->transaction->get(Pap_Db_Table_Transactions::ORIGINAL_CURRENCY_ID));
        }
        try {
            return $this->transaction->get($code);
        } catch (Gpf_Exception $e) {
        }
        return '';
    }
Exemplo n.º 4
0
 public function checkRules(Pap_Common_Transaction $transaction) {
     Gpf_Log::debug('Performance reward started');
     foreach($this->getRules($transaction->getCampaignId()) as $ruleRecord) {
         $rule = new Pap_Features_PerformanceRewards_Rule_Transaction($transaction);
         $rule->fillFromRecord($ruleRecord);
         try {
             Gpf_Log::debug('Processing rule ' . $rule->getId() . ': ' . $rule->getAction());
             $rule->executeAction();
             Gpf_Log::debug('Rule completed');
         } catch (Exception $e) {
             Gpf_Log::error(sprintf('Rule %s failed. Reason: %s', $rule->getId(), $e->getMessage()));
         }
     }
     Gpf_Log::debug('Performance reward ended');
 }
 /**
  * @return String
  */
 private function recognizeCommissionTypeId(Pap_Common_Transaction $transaction) {
     if ($transaction->getCommissionTypeId() != null && $transaction->getCommissionTypeId() != '') {
         return $transaction->getCommissionTypeId();
     }
      
     $campaignId = $transaction->getCampaignId();
     if ($campaignId == null || $campaignId == '') {
         return null;
     }
     $commissionTypeObject = $this->getCommissionType($campaignId, $transaction->getType());
     return $commissionTypeObject->getId();
 }
Exemplo n.º 6
0
    public function readRequestVariables() {
        $input = $this->readXmlData();

        if (Gpf_Settings::get(Recurly_Config::RESEND_URL) != "") {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, Gpf_Settings::get(Recurly_Config::RESEND_URL));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
            //curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
            curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
            curl_exec($ch);

            /*
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, Gpf_Settings::get(Recurly_Config::RESEND_URL));
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, 60);
             curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
             curl_exec($ch);
             */
        }

        $this->debug("Input get: " . $input);
        try {
            $xml = new SimpleXMLElement($input);
        } catch (Exception $e) {
            $this->setPaymentStatus("Failed");
            $this->debug('Wrong XML format!');
            return false;
        }

        // read last tag to find out what kind of request this is, e.g. </new_subscription_notification>
        $status = strrpos($input,"</");
        $status = substr($input,$status+2,strlen($input)-1);
        $status = substr($status,0,strrpos($status,">"));

        $this->setType($status);

        if ($this->getType() == self::NEWPAYMENT) {
            $totalcost_name = "amount_in_cents";
            $this->setData1((string)$xml->{"transaction"}->{"invoice_number"});
        }
        else {
            $totalcost_name = "total_amount_in_cents";
            $this->setProductID((string)$xml->{"transaction"}->{"plan_code"});
        }
        $this->setTransactionID((string)$xml->{"account"}->{"account_code"});
        $this->setTotalCost((string)$xml->{"transaction"}->{$totalcost_name}/100)*(((string)$xml->{"transaction"}->{"quantity"})?(string)$xml->{"transaction"}->{"quantity"}:1);

        // get original Affiliate
        $status = array(Pap_Common_Constants::STATUS_APPROVED, Pap_Common_Constants::STATUS_PENDING);
        $types = array(Pap_Common_Constants::TYPE_SALE, Pap_Common_Constants::TYPE_ACTION, Pap_Common_Constants::TYPE_LEAD);

        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->addAll(Pap_Db_Table_Transactions::getInstance());
        $select->from->add(Pap_Db_Table_Transactions::getName());
        $select->where->add(Pap_Db_Table_Transactions::ORDER_ID, "=", $this->getOrderID());
        $select->where->add(Pap_Db_Table_Transactions::R_TYPE, "IN", $types);
        $select->where->add(Pap_Db_Table_Transactions::R_STATUS, "IN", $status);
        $transaction = new Pap_Common_Transaction();
        $transaction->fillFromSelect($select);

        if (($transaction->getUserId() == null) OR ($transaction->getUserId() == "")) {
            $this->debug('No affiliate found for order ID: '.$this->getOrderID());
        }
        else {
            $this->setAccountId($transaction->getAccountId());
            $this->setAffiliateID($transaction->getUserId());
            $this->setProductID($transaction->getProductId());
            $this->setCampaignId($transaction->getCampaignId());
        }
    }
    private function setAccountIdFromCampaign(Pap_Common_Transaction $transaction) {
        try {
            $campaign = $this->createCampaign($transaction->getCampaignId());
        } catch (Gpf_Exception $e) {
        }

        if ($campaign === null) {
            return;
        }

        $transaction->setAccountId($campaign->getAccountId());
    }
 private function hashTransaction(Pap_Common_Transaction $transaction) {
     return $transaction->getUserId(). $transaction->getCampaignId(). $transaction->getBannerId(). $transaction->getChannel() .
     $transaction->getStatus() . $transaction->getTier(). $transaction->getType(). $transaction->getPayoutStatus() . $this->dateTimeToDate($transaction->getDateInserted() . $transaction->getCountryCode());
 }