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 '';
    }
예제 #2
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());
        }
    }