/** * (non-PHPdoc) * * @see library/Oara/Network/Oara_Network_Publisher_Base#getTransactionList($merchantId, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $dEndDate->addDay(1); $valuesFormExport = Oara_Utilities::cloneArray($this->_exportTransactionParameters); $valuesFormExport[] = new Oara_Curl_Parameter('pDate1', $dStartDate->toString("MM/d/yyyy")); $valuesFormExport[] = new Oara_Curl_Parameter('pDate2', $dEndDate->toString("MM/d/yyyy")); $urls = array(); $urls[] = new Oara_Curl_Request('https://www.auto-europe.co.uk/afftools/iatareport_popup.cfm?', $valuesFormExport); $exportReport = $this->_client->post($urls); $xmlTransactionList = self::readTransactions($exportReport[0]); foreach ($xmlTransactionList as $xmlTransaction) { $transaction = array(); $transaction['merchantId'] = 1; $date = new Zend_date($xmlTransaction['Booked'], "MM/dd/yyyy"); $transaction['date'] = $date->toString("yyyy-MM-dd 00:00:00"); $transaction['amount'] = (double) $xmlTransaction['commissionValue']; $transaction['commission'] = (double) $xmlTransaction['commission']; $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $transaction['unique_id'] = $xmlTransaction['Res #']; if (isset($xmlTransaction['Affiliate1']) && isset($xmlTransaction['Affiliate2'])) { $customId = (string) $xmlTransaction['Affiliate1'] . (string) $xmlTransaction['Affiliate2']; $customId = "afal-" . current(unpack('H*', base64_decode(str_replace(array(".", "-"), array("/", "+"), $customId)))); $transaction['custom_id'] = $customId; } $totalTransactions[] = $transaction; } return $totalTransactions; }
/** * Constructor and Login * @param $credentials * @return Oara_Network_Publisher_Daisycon */ public function __construct($credentials) { $this->_credentials = $credentials; $dir = COOKIES_BASE_DIR . DIRECTORY_SEPARATOR . $credentials['cookiesDir'] . DIRECTORY_SEPARATOR . $credentials['cookiesSubDir'] . DIRECTORY_SEPARATOR; if (!Oara_Utilities::mkdir_recursive($dir, 0777)) { throw new Exception('Problem creating folder in Access'); } $cookies = $dir . $credentials["cookieName"] . '_cookies.txt'; unlink($cookies); $this->_options = array(CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_COOKIEJAR => $cookies, CURLOPT_COOKIEFILE => $cookies, CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTPHEADER => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: es,en-us;q=0.7,en;q=0.3', 'Accept-Encoding: gzip, deflate', 'Connection: keep-alive', 'Cache-Control: max-age=0'), CURLOPT_ENCODING => "gzip", CURLOPT_VERBOSE => false); }
/** * Constructor and Login. * * @param $url - * Url Login * @param $valuesLogin - * Array with the login parameters * @return none */ public function __construct($url, array $valuesLogin, $credentials) { if (!isset($credentials["cookiesDir"])) { $credentials["cookiesDir"] = "Oara"; } if (!isset($credentials["cookiesSubDir"])) { $credentials["cookiesSubDir"] = "Import"; } if (!isset($credentials["cookieName"])) { $credentials["cookieName"] = "default"; } // Setting cookies $isDianomi = $credentials['networkName'] == "Dianomi" ? true : false; $isTD = $credentials['networkName'] == "TradeDoubler" || $credentials['networkName'] == "Stream20" || $credentials['networkName'] == "Wehkamp" || $credentials['networkName'] == "Steak"; // $isAW = $credentials['networkName'] == "AffiliateWindow"; $dir = COOKIES_BASE_DIR . DIRECTORY_SEPARATOR . $credentials['cookiesDir'] . DIRECTORY_SEPARATOR . $credentials['cookiesSubDir'] . DIRECTORY_SEPARATOR; if (!Oara_Utilities::mkdir_recursive($dir, 0777)) { throw new Exception('Problem creating folder in Access'); } // Deleting the last cookie if ($handle = opendir($dir)) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if ($credentials['cookieName'] == strstr($file, '_', true)) { unlink($dir . $file); break; } } closedir($handle); } $cookieName = $credentials["cookieName"]; $cookies = $dir . $cookieName . '_cookies.txt'; $this->_cookiePath = $cookies; $this->_options = array(CURLOPT_USERAGENT => "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/32.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_COOKIEJAR => $cookies, CURLOPT_COOKIEFILE => $cookies, CURLOPT_HTTPAUTH => CURLAUTH_ANY, CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, CURLOPT_VERBOSE => false); // Init curl $ch = curl_init(); $options = $this->_options; $options[CURLOPT_URL] = $url; $options[CURLOPT_POST] = true; $options[CURLOPT_FOLLOWLOCATION] = true; // Login form fields $arg = self::getPostFields($valuesLogin); $options[CURLOPT_POSTFIELDS] = $arg; // problem with SMG about the redirects and headers if ($isTD) { $options[CURLOPT_HEADER] = true; $options[CURLOPT_FOLLOWLOCATION] = false; } curl_setopt_array($ch, $options); $result = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $info = curl_getinfo($ch); // Close curl session curl_close($ch); if ($isDianomi) { $result = true; } while ($isTD && ($info['http_code'] == 301 || $info['http_code'] == 302)) { // redirect manually, cookies must be set, which curl does not itself // extract new location preg_match_all('|Location: (.*)\\n|U', $result, $results); $location = implode(';', $results[1]); $ch = curl_init(); $options = $this->_options; $options[CURLOPT_URL] = str_replace("/publisher/..", "", $location); $options[CURLOPT_HEADER] = true; $options[CURLOPT_FOLLOWLOCATION] = false; curl_setopt_array($ch, $options); $result = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $info = curl_getinfo($ch); curl_close($ch); } $this->_constructResult = $result; if ($result == false) { throw new Exception("Failed to connect"); } else { $this->_connected = true; } }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $context = stream_context_create(array('http' => array('header' => "Authorization: Basic " . base64_encode("{$this->_user}:{$this->_pass}")))); $from = urlencode($dStartDate->toString("yyyy-MM-dd HH:mm:ss")); $data = file_get_contents("http://api.webepartners.pl/wydawca/Auctions?from={$from}", false, $context); $dataArray = json_decode($data, true); foreach ($dataArray as $transactionObject) { if (in_array($transactionObject["ProgramId"], $merchantList)) { $transaction = array(); $transaction['merchantId'] = $transactionObject["ProgramId"]; $transaction['date'] = $transactionObject["AuctionDate"]; if (isset($transactionObject["AuctionId"]) && $transactionObject["AuctionId"] != '') { $transaction['unique_id'] = $transactionObject["AuctionId"]; } if (isset($transactionObject["subID"]) && $transactionObject["subID"] != '') { $transaction['custom_id'] = $transactionObject["subID"]; } if ($transactionObject["AuctionStatusId"] == 3 || $transactionObject["AuctionStatusId"] == 4 || $transactionObject["AuctionStatusId"] == 5) { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } else { if ($transactionObject["AuctionStatusId"] == 1) { $transaction['status'] = Oara_Utilities::STATUS_PENDING; } else { if ($transactionObject["AuctionStatusId"] == 2) { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } else { if ($transactionObject["AuctionStatusId"] == 6) { $transaction['status'] = Oara_Utilities::STATUS_PAID; } } } } $transaction['amount'] = Oara_Utilities::parseDouble($transactionObject["OrderCost"]); $transaction['commission'] = Oara_Utilities::parseDouble($transactionObject["Commission"]); $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $valuesFormExport = array(); if ($this->_transactionList == null) { $urls = array(); $valuesExport = array(new Oara_Curl_Parameter('D', '{"C":"Pap_Affiliates_Reports_TransactionsGrid", "M":"getCSVFile", "S":"' . $this->_s . '", "FormResponse":"Y", "sort_col":"dateinserted", "sort_asc":false, "offset":0, "limit":30, "columns":[["id"],["id"],["commission"],["totalcost"],["fixedcost"],["t_orderid"],["productid"],["dateinserted"],["name"],["rtype"],["tier"],["commissionTypeName"],["rstatus"],["merchantnote"],["channel"]]}')); $urls[] = new Oara_Curl_Request('https://vpnaffiliates.com/affiliates/scripts/server.php?', $valuesExport); $exportReport = array(); $exportReport = $this->_client->post($urls); $this->_transactionList = str_getcsv($exportReport[0], "\n"); } $exportData = $this->_transactionList; $num = count($exportData); for ($i = 1; $i < $num; $i++) { $transactionExportArray = str_getcsv($exportData[$i], ","); // print_r($transactionExportArray); $transaction = array(); $transaction['merchantId'] = 1; $transaction['uniqueId'] = $transactionExportArray[3]; $transactionDate = new Zend_Date($transactionExportArray[5], 'yyyy-MM-dd HH:mm:ss', 'en'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); unset($transactionDate); $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $transaction['amount'] = Oara_Utilities::parseDouble($transactionExportArray[1]); $transaction['commission'] = Oara_Utilities::parseDouble($transactionExportArray[0]); // print_r($transaction); if ($transaction['date'] >= $dStartDate->toString("yyyy-MM-dd HH:mm:ss") && $transaction['date'] <= $dEndDate->toString("yyyy-MM-dd HH:mm:ss")) { $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($idMerchant, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $affiliate_id = $this->_id; $auth_key = $this->_apikey; $strUrl = 'https://www.avantlink.ca/api.php'; $strUrl .= "?affiliate_id={$affiliate_id}"; $strUrl .= "&auth_key={$auth_key}"; $strUrl .= "&module=AffiliateReport"; $strUrl .= "&output=" . urlencode('csv'); $strUrl .= "&report_id=8"; $strUrl .= "&date_begin=" . urlencode($dStartDate->toString("yyyy-MM-dd HH:mm:ss")); $strUrl .= "&date_end=" . urlencode($dEndDate->toString("yyyy-MM-dd HH:mm:ss")); $strUrl .= "&include_inactive_merchants=0"; $strUrl .= "&search_results_include_cpc=0"; $returnResult = self::makeCall($strUrl); $exportData = str_getcsv($returnResult, "\r\n"); $num = count($exportData); for ($i = 1; $i < $num; $i++) { $transactionExportArray = str_getcsv($exportData[$i], ","); if (count($transactionExportArray) > 1 && in_array((int) $transactionExportArray[17], $merchantList)) { $transaction = array(); $merchantId = (int) $transactionExportArray[17]; $transaction['merchantId'] = $merchantId; $transactionDate = new Zend_Date($transactionExportArray[11], 'MM-dd-yyyy HH:mm:ss'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); $transaction['unique_id'] = (int) $transactionExportArray[5]; if ($transactionExportArray[4] != null) { $transaction['custom_id'] = $transactionExportArray[4]; } $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $transaction['amount'] = Oara_Utilities::parseDouble(preg_replace("/[^0-9\\.,]/", "", $transactionExportArray[6])); $transaction['commission'] = Oara_Utilities::parseDouble(preg_replace("/[^0-9\\.,]/", "", $transactionExportArray[7])); $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Base#getTransactionList($merchantId, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $totalOverviews = array(); $urls = array(); $urls[] = new Oara_Curl_Request('http://book.terravision.eu/partner/my/stats', array()); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('input[name="form[_token]"]'); $token = null; foreach ($results as $result) { $token = $result->getAttribute("value"); } $valuesFormExport = array(); $valuesFormExport[] = new Oara_Curl_Parameter('form[year]', $dStartDate->toString("yyyy")); $valuesFormExport[] = new Oara_Curl_Parameter('fform[_token]', $token); $valuesFormExport[] = new Oara_Curl_Parameter('show', 'Show'); $urls = array(); $urls[] = new Oara_Curl_Request('http://book.terravision.eu/partner/my/stats?', $valuesFormExport); $exportReport = $this->_client->post($urls); $stringToFind = $dStartDate->toString("MM-yyyy"); /*** load the html into the object ***/ $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('.frame > table'); $exportData = self::htmlToCsv(self::DOMinnerHTML($results->current())); $num = count($exportData); $transactionCounter = 0; $valueCounter = 0; $commissionCounter = 0; for ($i = 1; $i < $num - 1; $i++) { $transactionArray = str_getcsv($exportData[$i], ";"); if ($transactionArray[0] == $stringToFind) { $transactionCounter = $transactionArray[12]; $valueCounter += $transactionArray[14]; $commissionCounter += $transactionArray[16]; } } if ($transactionCounter > 0) { $dateList = Oara_Utilities::daysOfDifference($dStartDate, $dEndDate); for ($i = 0; $i < count($dateList); $i++) { $transaction = array(); $transaction['merchantId'] = 1; $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $transaction['date'] = $dateList[$i]->toString("yyyy-MM-dd HH:mm:ss"); $transaction['amount'] = $valueCounter / count($dateList); $transaction['commission'] = $commissionCounter / count($dateList); $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Base#getTransactionList($merchantId,$dStartDate,$dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); //Set the webservice $publisherStatisticsServiceUrl = 'https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl'; $publisherStatisticsService = new Oara_Import_Soap_Client($publisherStatisticsServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1)); $iterationNumber = self::calculeIterationNumber(count($merchantList), 100); for ($currentIteration = 0; $currentIteration < $iterationNumber; $currentIteration++) { $merchantListSlice = array_slice($merchantList, 100 * $currentIteration, 100); $merchantListAux = array(); foreach ($merchantListSlice as $merchant) { $merchantListAux[] = (string) $merchant; } //Call the function $params = array('StartDate' => strtotime($dStartDate->toString("yyyy-MM-dd")), 'EndDate' => strtotime($dEndDate->toString("yyyy-MM-dd")), 'TransactionStatus' => 'All', 'ProgramIds' => $merchantListAux); $currentPage = 1; $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); while (isset($transactionList->TotalRecords) && $transactionList->TotalRecords > 0 && isset($transactionList->TransactionCollection->Transaction)) { $transactionCollection = array(); if (!is_array($transactionList->TransactionCollection->Transaction)) { $transactionCollection[] = $transactionList->TransactionCollection->Transaction; } else { $transactionCollection = $transactionList->TransactionCollection->Transaction; } $transactionList = Oara_Utilities::soapConverter($transactionCollection, $this->_transactionConverterConfiguration); foreach ($transactionList as $transaction) { //$transaction['merchantId'] = 3901; $tDate = new Zend_Date($transaction["date"], "yyyy-MM-ddTHH:mm:ss"); $transaction["date"] = $tDate->toString("yyyy-MM-dd HH:mm:ss"); if ($transaction['status'] == 'Confirmed') { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } else { if ($transaction['status'] == 'Open') { $transaction['status'] = Oara_Utilities::STATUS_PENDING; } else { if ($transaction['status'] == 'Cancelled') { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } } } $totalTransactions[] = $transaction; } $currentPage++; $transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); } } return $totalTransactions; }
/** * (non-PHPdoc) * * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $valuesFromExport = array(); $valuesFromExport[] = new Oara_Curl_Parameter('getExcel', '1'); $valuesFromExport[] = new Oara_Curl_Parameter('p_sSearchMode', 'custom'); $valuesFromExport[] = new Oara_Curl_Parameter('p_nType', 'sale'); $valuesFromExport[] = new Oara_Curl_Parameter('p_sPeriod', 'day'); $valuesFromExport[] = new Oara_Curl_Parameter('export', 'csv'); $valuesFromExport[] = new Oara_Curl_Parameter('p_nStatus', '3'); $valuesFromExport[] = new Oara_Curl_Parameter('p_nNbRowsByPage', '50'); $valuesFromExport[] = new Oara_Curl_Parameter('p_nProgId', ''); $valuesFromExport[] = new Oara_Curl_Parameter('p_sStartDate', $dStartDate->toString("dd/MM/yyyy")); $valuesFromExport[] = new Oara_Curl_Parameter('p_sEndDate', $dEndDate->toString("dd/MM/yyyy")); $valuesFromExport[] = new Oara_Curl_Parameter('p_nPage', '1'); $urls = array(); $urls[] = new Oara_Curl_Request('http://v2.afilio.com.br/include/lib/aff_lib_manage_sale.php?', $valuesFromExport); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $tableList = $dom->query('table'); $exportData = self::htmlToCsv(self::DOMinnerHTML($tableList->next())); $num = count($exportData); for ($i = 0; $i < $num; $i++) { $transactionExportArray = explode(";,", $exportData[$i]); if (isset($merchantMap[$transactionExportArray[0]]) && in_array($merchantMap[$transactionExportArray[0]], $merchantList)) { $transaction = array(); $transaction['merchantId'] = $merchantMap[$transactionExportArray[0]]; $transaction['unique_id'] = $transactionExportArray[4]; $transactionDate = new Zend_Date($transactionExportArray[1], 'dd/MM/yy HH:mm:dd', 'en'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); $transaction['customId'] = $transactionExportArray[5]; if ($transactionExportArray[7] == "Accepted" || $transactionExportArray[7] == "Accepté") { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } else { if ($transactionExportArray[7] == "Pending" || $transactionExportArray[7] == "En attente") { $transaction['status'] = Oara_Utilities::STATUS_PENDING; } else { if ($transactionExportArray[7] == "Rejected" || $transactionExportArray[7] == "Refusé" || $transactionExportArray[7] == "Refused") { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } else { throw new Exception("New status found {$transactionExportArray[7]}"); } } } $transaction['amount'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $transactionExportArray[6])); $transaction['commission'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $transactionExportArray[6])); $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * Get the merchant for an Id * @param integer $merchantId * @return array */ public function getMerchant(array $merchantIds = null) { $merchantList = array(); if ($merchantIds != null) { $iteration = 0; $arraySlice = array_slice($merchantIds, $this->_pageSize * $iteration, $this->_pageSize); while (!empty($arraySlice)) { $params = array(); $params['aMerchantIds'] = $arraySlice; $merchantApiList = $this->_apiClient->getMerchant($params)->getMerchantReturn; $merchantList = array_merge($merchantList, Oara_Utilities::soapConverter($merchantApiList, $this->_merchantConverterConfiguration)); $iteration++; $arraySlice = array_slice($merchantIds, $this->_pageSize * $iteration, $this->_pageSize); } } return $merchantList; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $urls = array(); $valuesFromExport = $this->_exportPaymentParameters; $urls[] = new Oara_Curl_Request('http://users.buy.at/ma/index.php/affiliatePayments/paymentsHistory?', $valuesFromExport); $exportReport = $this->_client->get($urls); $exportData = str_getcsv($exportReport[0], "\r\n"); $num = count($exportData); for ($j = 1; $j < $num; $j++) { $paymentData = str_getcsv($exportData[$j], ","); $obj = array(); $date = new Zend_Date($paymentData[0], "dd-MM-yyyy"); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['method'] = $paymentData[1]; $obj['value'] = Oara_Utilities::parseDouble($paymentData[2]); $obj['pid'] = $paymentData[4]; $paymentHistory[] = $obj; } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $urls = array(); $urls[] = new Oara_Curl_Request('https://publisher.ebaypartnernetwork.com/PublisherAccountPaymentHistory', array()); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('table .aruba_report_table'); if (count($results) > 0) { $exportData = self::htmlToCsv(self::DOMinnerHTML($results->current())); for ($j = 1; $j < count($exportData); $j++) { $paymentExportArray = str_getcsv($exportData[$j], ";"); $obj = array(); $paymentDate = new Zend_Date($paymentExportArray[0], "dd/MM/yy", "en"); $obj['date'] = $paymentDate->toString("yyyy-MM-dd HH:mm:ss"); $obj['pid'] = $paymentDate->toString("yyyyMMdd"); $obj['method'] = 'BACS'; if (preg_match("/[-+]?[0-9]*,?[0-9]*\\.?[0-9]+/", $paymentExportArray[2], $matches)) { $obj['value'] = Oara_Utilities::parseDouble($matches[0]); } else { throw new Exception("Problem reading payments"); } $paymentHistory[] = $obj; } } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara_Network::getTransactionList() */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $filter = new Zend_Filter_LocalizedToNormalized(array('precision' => 2)); self::login(); $valuesFormExport = Oara_Utilities::cloneArray($this->_exportTransactionParameters); $valuesFormExport[] = new Oara_Curl_Parameter('startDate', self::formatDate($dStartDate)); $valuesFormExport[] = new Oara_Curl_Parameter('endDate', self::formatDate($dEndDate)); $urls = array(); $urls[] = new Oara_Curl_Request('http://publisher.tradedoubler.com/pan/aReport3Internal.action?', $valuesFormExport); $exportReport = $this->_client->get($urls); $exportReport[0] = self::checkReportError($exportReport[0], $urls[0]); $exportData = str_getcsv($exportReport[0], "\r\n"); $num = count($exportData); for ($i = 2; $i < $num - 1; $i++) { $transactionExportArray = str_getcsv($exportData[$i], ","); if (!isset($transactionExportArray[2])) { throw new Exception('Problem getting transaction\\n\\n'); } if ($transactionExportArray[0] !== '') { $transaction = array(); $transaction['merchantId'] = 1; $transactionDate = self::toDate($transactionExportArray[4]); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); if ($transactionExportArray[8] != '') { $transaction['unique_id'] = $transactionExportArray[8]; } else { if ($transactionExportArray[7] != '') { $transaction['unique_id'] = $transactionExportArray[7]; } else { throw new Exception("No Identifier"); } } if ($transactionExportArray[9] != '') { $transaction['custom_id'] = $transactionExportArray[9]; } if ($transactionExportArray[11] == 'A') { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } else { if ($transactionExportArray[11] == 'P') { $transaction['status'] = Oara_Utilities::STATUS_PENDING; } else { if ($transactionExportArray[11] == 'D') { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } } } if ($transactionExportArray[18] != '') { $transaction['amount'] = Oara_Utilities::parseDouble($transactionExportArray[18]); } else { $transaction['amount'] = Oara_Utilities::parseDouble($transactionExportArray[19]); } $transaction['commission'] = Oara_Utilities::parseDouble($transactionExportArray[19]); $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); foreach ($this->_idBox as $id) { $urls = array(); $paymentExport = array(); $paymentExport[] = new Oara_Curl_Parameter('idbox_store_id', $id); $urls[] = new Oara_Curl_Request($this->_networkServer . "/gp/associates/network/your-account/payment-history.html?", $paymentExport); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('.paymenthistory'); $count = count($results); $yearArray = array(); if ($count == 1) { $paymentTable = $results->current(); $paymentReport = self::htmlToCsv(self::DOMinnerHTML($paymentTable)); for ($i = 2; $i < count($paymentReport) - 1; $i++) { $paymentExportArray = str_getcsv($paymentReport[$i], ";"); $obj = array(); $paymentDate = new Zend_Date($paymentExportArray[0], "M d yyyy", "en"); $obj['date'] = $paymentDate->toString("yyyy-MM-dd HH:mm:ss"); $obj['pid'] = $paymentDate->toString("yyyyMMdd") . substr((string) base_convert(md5($id), 16, 10), 0, 5); $obj['method'] = 'BACS'; if (preg_match("/[0-9]*,?[0-9]*\\.?[0-9]+/", $paymentExportArray[4], $matches)) { $obj['value'] = Oara_Utilities::parseDouble($matches[0]); $paymentHistory[] = $obj; } } } else { //throw new Exception('Problem getting the payments'); } } return $paymentHistory; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $dirDestination = realpath(dirname(__FILE__)) . '/../../data/pdf'; $now = new Zend_Date(); if ($now->toString("yyyy-MM") != $dStartDate->toString("yyyy-MM")) { $fileName = "S_M_{$this->_apiPassword}_" . $dStartDate->toString("yyyyMM") . ".txt.gz"; // Raising this value may increase performance $buffer_size = 4096; // read 4kb at a time $local_file = $dirDestination . "/" . $fileName; $url = "http://affjet.dc.fubra.net/tools/ItunesConnect/ic.php?user="******"&password="******"&apiPassword="******"&type=M&date=" . $dStartDate->toString("yyyyMM"); $context = \stream_context_create(array('http' => array('header' => "Authorization: Basic " . base64_encode("{$this->_httpLogin}")))); \file_put_contents($local_file, \file_get_contents($url, false, $context)); $out_file_name = \str_replace('.gz', '', $local_file); // Open our files (in binary mode) $file = \gzopen($local_file, 'rb'); if ($file != null) { $out_file = \fopen($out_file_name, 'wb'); // Keep repeating until the end of the input file while (!\gzeof($file)) { // Read buffer-size bytes // Both fwrite and gzread and binary-safe \fwrite($out_file, \gzread($file, $buffer_size)); } // Files are done, close files \fclose($out_file); \gzclose($file); unlink($local_file); $salesReport = file_get_contents($out_file_name); $salesReport = explode("\n", $salesReport); for ($i = 1; $i < count($salesReport) - 1; $i++) { $row = str_getcsv($salesReport[$i], "\t"); if ($row[15] != 0) { $sub = false; if ($row[7] < 0) { $sub = true; $row[7] = abs($row[7]); } for ($j = 0; $j < $row[7]; $j++) { $obj = array(); $obj['merchantId'] = "1"; $obj['date'] = $dEndDate->toString("yyyy-MM-dd") . " 00:00:00"; $obj['custom_id'] = $row[4]; $comission = 0.3; if ($row[2] == "FUBRA1PETROLPRICES1" || $row[2] == "com.fubra.petrolpricespro.subscriptionYear") { $value = 2.99; $obj['amount'] = Oara_Utilities::parseDouble($value); $obj['commission'] = Oara_Utilities::parseDouble($value - $value * $comission); } else { if ($row[2] == "FUBRA1WORLDAIRPORTCODES1") { if ($obj['date'] < "2013-04-23 00:00:00") { $value = 0.6899999999999999; $obj['amount'] = Oara_Utilities::parseDouble($value); $obj['commission'] = Oara_Utilities::parseDouble($value - $value * $comission); } else { $value = 1.49; $obj['amount'] = Oara_Utilities::parseDouble($value); $obj['commission'] = Oara_Utilities::parseDouble($value - $value * $comission); } } else { throw new Exception("APP not found {$row[2]}"); } } if ($sub) { $obj['amount'] = -$obj['amount']; $obj['commission'] = -$obj['commission']; } $obj['status'] = Oara_Utilities::STATUS_CONFIRMED; $totalTransactions[] = $obj; } } } unlink($out_file_name); } } else { $dateArray = Oara_Utilities::daysOfDifference($dStartDate, $dEndDate); $dateArraySize = sizeof($dateArray); for ($z = 0; $z < $dateArraySize; $z++) { $transactionDate = $dateArray[$z]; $fileName = "S_D_{$this->_apiPassword}_" . $transactionDate->toString("yyyyMMdd") . ".txt.gz"; // Raising this value may increase performance $buffer_size = 4096; // read 4kb at a time $local_file = $dirDestination . "/" . $fileName; $url = "http://affjet.dc.fubra.net/tools/ItunesConnect/ic.php?user="******"&password="******"&apiPassword="******"&type=D&date=" . $transactionDate->toString("yyyyMMdd"); $context = \stream_context_create(array('http' => array('header' => "Authorization: Basic " . base64_encode("{$this->_httpLogin}")))); \file_put_contents($local_file, \file_get_contents($url, false, $context)); $out_file_name = \str_replace('.gz', '', $local_file); // Open our files (in binary mode) $file = \gzopen($local_file, 'rb'); if ($file != null) { $out_file = \fopen($out_file_name, 'wb'); // Keep repeating until the end of the input file while (!\gzeof($file)) { // Read buffer-size bytes // Both fwrite and gzread and binary-safe \fwrite($out_file, \gzread($file, $buffer_size)); } // Files are done, close files \fclose($out_file); \gzclose($file); unlink($local_file); $salesReport = file_get_contents($out_file_name); $salesReport = explode("\n", $salesReport); for ($i = 1; $i < count($salesReport) - 1; $i++) { $row = str_getcsv($salesReport[$i], "\t"); if ($row[15] != 0) { $sub = false; if ($row[7] < 0) { $sub = true; $row[7] = abs($row[7]); } for ($j = 0; $j < $row[7]; $j++) { $obj = array(); $obj['merchantId'] = "1"; $obj['date'] = $transactionDate->toString("yyyy-MM-dd") . " 00:00:00"; $obj['custom_id'] = $row[4]; if ($row[2] == "FUBRA1PETROLPRICES1" || $row[2] == "com.fubra.petrolpricespro.subscriptionYear") { $value = 2.99; $comission = 0.3; $obj['amount'] = Oara_Utilities::parseDouble($value); $obj['commission'] = Oara_Utilities::parseDouble($value - $value * $comission); } else { if ($row[2] == "FUBRA1WORLDAIRPORTCODES1") { $comission = 0.3; if ($obj['date'] < "2013-04-23 00:00:00") { $value = 0.6899999999999999; $obj['amount'] = Oara_Utilities::parseDouble($value); $obj['commission'] = Oara_Utilities::parseDouble($value - $value * $comission); } else { $value = 1.49; $obj['amount'] = Oara_Utilities::parseDouble($value); $obj['commission'] = Oara_Utilities::parseDouble($value - $value * $comission); } } else { throw new Exception("APP not found {$row[2]}"); } } if ($sub) { $obj['amount'] = -$obj['amount']; $obj['commission'] = -$obj['commission']; } $obj['status'] = Oara_Utilities::STATUS_CONFIRMED; $totalTransactions[] = $obj; } } } unlink($out_file_name); } } } return $totalTransactions; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $startDate = new Zend_Date('01-01-2009', 'dd-MM-yyyy'); $endDate = new Zend_Date(); $dateArray = Oara_Utilities::monthsOfDifference($startDate, $endDate); for ($i = 0; $i < count($dateArray); $i++) { $dateMonth = $dateArray[$i]; $obj = array(); $obj['date'] = $dateMonth->toString("yyyy-MM-dd HH:mm:ss"); $value = rand(1, 1300); $obj['value'] = $value; $obj['method'] = 'BACS'; $obj['pid'] = $dateMonth->toString('yyyyMMdd'); $paymentHistory[] = $obj; } return $paymentHistory; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $urls = array(); $url = "https://foxtransfer.eu/index.php?q=prices.en.html&page=affiliate_orders&language=1&basedir=theme2&what=record_time&what=record_time&fy={$dStartDate->toString("yyyy")}&fm={$dStartDate->toString("M")}&fd={$dStartDate->toString("d")}&ty={$dEndDate->toString("yyyy")}&tm={$dEndDate->toString("M")}&td={$dEndDate->toString("d")}"; $urls[] = new Oara_Curl_Request($url, array()); $exportReport = array(); $exportReport = $this->_client->get($urls); $exportReport = str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "", $exportReport); $dom = new Zend_Dom_Query($exportReport[0]); $tableList = $dom->query('#tartalom-hatter table[cellspacing="0"][cellpadding="3"][border="0"]'); $exportData = self::htmlToCsv(self::DOMinnerHTML($tableList->current())); $num = count($exportData); for ($i = 3; $i < $num; $i++) { $transactionExportArray = str_getcsv($exportData[$i], ";"); $transaction = array(); $transaction['merchantId'] = 1; $transaction['unique_id'] = $transactionExportArray[0]; $transaction['date'] = "{$dStartDate->toString("yyyy")}-{$dStartDate->toString("MM")}-01 00:00:00"; if ($transactionExportArray[7] == "Confirmed") { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } else { if ($transactionExportArray[7] == "Cancelled") { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } else { throw new Exception("New status found"); } } $transaction['amount'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $transactionExportArray[10])); $transaction['commission'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $transactionExportArray[13])); $totalTransactions[] = $transaction; } return $totalTransactions; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Base#getTransactionList($merchantId, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $rch = curl_init(); $options = $this->_options; curl_setopt($rch, CURLOPT_URL, 'https://www.sportscoverdirect.com/promoters/earn'); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); $dom = new Zend_Dom_Query($html); $results = $dom->query('.performance'); if (count($results) > 0) { $exportData = self::htmlToCsv(self::DOMinnerHTML($results->current())); $num = count($exportData) - 1; //the last row is show-more show-less for ($i = 1; $i < $num; $i++) { $overviewExportArray = str_getcsv($exportData[$i], ";"); $transaction = array(); $transaction['merchantId'] = 1; $date = new Zend_Date($overviewExportArray[0], "dd/MM/yyyy"); $transaction['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $transaction['amount'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $overviewExportArray[1])); $transaction['commission'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $overviewExportArray[1])); $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $filter = new Zend_Filter_LocalizedToNormalized(array('precision' => 2)); $paymentHistory = array(); $urls = array(); $urls[] = new Oara_Curl_Request('https://affiliates.wehkamp.nl/pan/reportSelection/Payment?', array()); $exportReport = $this->_client->get($urls); /*** load the html into the object ***/ $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->validateOnParse = true; $doc->loadHTML($exportReport[0]); $selectList = $doc->getElementsByTagName('select'); $paymentSelect = null; if ($selectList->length > 0) { // looking for the payments select $it = 0; while ($it < $selectList->length) { $selectName = $selectList->item($it)->attributes->getNamedItem('name')->nodeValue; if ($selectName == 'payment_id') { $paymentSelect = $selectList->item($it); break; } $it++; } if ($paymentSelect != null) { $paymentLines = $paymentSelect->childNodes; for ($i = 0; $i < $paymentLines->length; $i++) { $pid = $paymentLines->item($i)->attributes->getNamedItem("value")->nodeValue; if (is_numeric($pid)) { $obj = array(); $paymentLine = $paymentLines->item($i)->nodeValue; $value = preg_replace("/[^0-9\\.,]/", "", substr($paymentLine, 10)); $date = self::toDate(substr($paymentLine, 0, 10)); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['pid'] = $pid; $obj['method'] = 'BACS'; $obj['value'] = Oara_Utilities::parseDouble($value); $paymentHistory[] = $obj; } } } } return $paymentHistory; }
/** * (non-PHPdoc) * * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $filter = new Zend_Filter_LocalizedToNormalized(array('precision' => 2)); $past = new Zend_Date("01-01-2010", "dd-MM-yyyy"); $now = new Zend_Date(); $dateList = Oara_Utilities::yearsOfDifference($past, $now); $dateList[] = $now; foreach ($this->_siteList as $site) { for ($i = 0; $i < count($dateList) - 1; $i++) { $bdate = clone $dateList[$i]; $edate = clone $dateList[$i + 1]; if ($i != count($dateList) - 1) { $edate->subDay(1); } echo "getting Payment for Site " . $site->id . " and year " . $bdate->toString("yyyy") . " \n\n"; // https://65.245.193.87 $url = "https://reportws.linksynergy.com/downloadreport.php?bdate=" . $bdate->toString("yyyyMMdd") . "&edate=" . $edate->toString("yyyyMMdd") . "&token=" . $site->secureToken . "&nid=" . $this->_nid . "&reportid=1"; $result = file_get_contents($url); if (preg_match("/You cannot request/", $result)) { throw new Exception("Reached the limit"); } $paymentLines = str_getcsv($result, "\n"); $number = count($paymentLines); for ($j = 1; $j < $number; $j++) { $paymentData = str_getcsv($paymentLines[$j], ","); $obj = array(); $date = new Zend_Date($paymentData[1], "yyyy-MM-dd"); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['value'] = $filter->filter($paymentData[5]); $obj['method'] = "BACS"; $obj['pid'] = $paymentData[0]; $paymentHistory[] = $obj; } } } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $paymentExport = array(); $paymentExport[] = new Oara_Curl_Parameter('session', $this->_sessionId); $urls = array(); $urls[] = new Oara_Curl_Request('http://affiliate.paidonresults.com/cgi-bin/invoice-status.pl?', $paymentExport); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('#tableID1 tr'); foreach ($results as $result) { $childrenList = $result->childNodes; $numberChildren = $childrenList->length; if ($numberChildren == 18) { $value = $childrenList->item(14)->nodeValue; if (preg_match('/[0-9]+(,[0-9]{3})*(\\.[0-9]{2})?$/', $value, $matches)) { $obj = array(); $obj['pid'] = $childrenList->item(4)->nodeValue; $date = new Zend_Date($childrenList->item(0)->nodeValue, "dd/MMM/yyyy"); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['value'] = Oara_Utilities::parseDouble($matches[0]); $obj['method'] = 'BACS'; $paymentHistory[] = $obj; } } } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $urls = array(); $urls[] = new Oara_Curl_Request('https://members.cj.com/member/cj/publisher/paymentStatus', array()); $exportReport = $this->_client->get($urls); if (preg_match("/\\/publisher\\/getpublisherpaymenthistory\\.do/", $exportReport[0], $matches)) { $urls = array(); $valuesFromExport = $this->_exportPaymentParameters; $urls[] = new Oara_Curl_Request('https://members.cj.com/member/' . $this->_memberId . '/publisher/getpublisherpaymenthistory.do?', $valuesFromExport); $exportReport = $this->_client->get($urls); $exportData = str_getcsv($exportReport[0], "\n"); $num = count($exportData); for ($j = 1; $j < $num; $j++) { $paymentData = str_getcsv($exportData[$j], ","); $obj = array(); $date = new Zend_Date($paymentData[0], "dd-MMM-yyyy HH:mm", 'en_US'); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['value'] = Oara_Utilities::parseDouble($paymentData[1]); $obj['method'] = $paymentData[2]; $obj['pid'] = $paymentData[6]; $paymentHistory[] = $obj; } } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $valuesFromExport = $this->_exportPaymentParameters; $urls = array(); $urls[] = new Oara_Curl_Request('https://admin.omgpm.com/v2/finance/affiliate/view_payments.aspx?', array()); $exportReport = $this->_client->get($urls); /*** load the html into the object ***/ $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->validateOnParse = true; $doc->loadHTML($exportReport[0]); $hiddenList = $doc->getElementsByTagName('input'); for ($i = 0; $i < $hiddenList->length; $i++) { $attrs = $hiddenList->item($i)->attributes; if ($attrs->getNamedItem("type")->nodeValue == 'hidden') { //we are adding the hidden parameters $valuesFromExport[] = new Oara_Curl_Parameter($attrs->getNamedItem("name")->nodeValue, $attrs->getNamedItem("value")->nodeValue); } } $yearSelect = $doc->getElementById('ctl00_ContentPlaceHolder1_ddlYear')->childNodes; $yearStart = (int) $yearSelect->item($yearSelect->length - 1)->attributes->getNamedItem("value")->nodeValue; $nowDays = new Zend_Date(); $yearEnd = (int) $nowDays->get(Zend_Date::YEAR); $urls = array(); for ($i = $yearStart; $i <= $yearEnd; $i++) { $requestValuesFromExport = Oara_Utilities::cloneArray($valuesFromExport); $requestValuesFromExport[] = new Oara_Curl_Parameter('ctl00$ContentPlaceHolder1$ddlYear', (string) $i); $urls[] = new Oara_Curl_Request('https://admin.omgpm.com/v2/finance/affiliate/view_payments.aspx?', $requestValuesFromExport); } $exportReport = $this->_client->post($urls); for ($i = 0; $i < count($exportReport); $i++) { if (!preg_match("/No Results for this criteria/i", $exportReport[$i])) { $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->validateOnParse = true; $doc->loadHTML($exportReport[$i]); $table = $doc->getElementById('ctl00_ContentPlaceHolder1_gvSummary'); $paymentList = $table->childNodes; for ($j = 1; $j < $paymentList->length; $j++) { $paymentData = $paymentList->item($j)->childNodes; $obj = array(); $obj['value'] = Oara_Utilities::parseDouble($paymentData->item(5)->nodeValue); if ($obj['value'] != null) { $date = new Zend_date($paymentData->item(8)->nodeValue, "dd/MM/yyyy HH:mm:ss"); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['pid'] = $paymentData->item(2)->nodeValue; $ass = $paymentData->item(5)->nodeValue; $obj['method'] = 'BACS'; $paymentHistory[] = $obj; } } } } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Base#getCreatives() */ public function getCreatives() { $creativesMap = array(); $merchantList = self::getMerchantList(); foreach ($merchantList as $merchant) { $websiteFirstId = null; $websiteMap = array(); if (isset($this->_websitesList[$merchant['cid']])) { $websiteMap = $this->_websitesList[$merchant['cid']]; } foreach ($websiteMap as $websiteid => $websiteName) { $websiteFirstId = $websiteid; break; } if ($websiteFirstId != null) { $urls = array(); $valuesFormExport = Oara_Utilities::cloneArray($this->_exportCreativeParameters); $valuesFormExport[] = new Oara_Curl_Parameter('programGEListParameterTransport.siteId', $websiteFirstId); $valuesFormExport[] = new Oara_Curl_Parameter('programGEListParameterTransport.programIdOrName', $merchant['cid']); $urls[] = new Oara_Curl_Request('http://www.tradedoubler.com/pan/aGEList.action?', $valuesFormExport); $exportReport = $this->_client->post($urls); for ($i = 0; $i < count($exportReport); $i++) { if (preg_match_all("/javascript: showCode\\((.+)?\\)/", $exportReport[$i], $matches)) { foreach ($matches[1] as $parameters) { $paramatersArray = explode(',', $parameters); $programId = $paramatersArray[1]; $graphicalElementId = $paramatersArray[0]; $affiliateId = $paramatersArray[3]; if (is_numeric($programId) && is_numeric($graphicalElementId) && is_numeric($affiliateId)) { /** $creativesMap[(string)$programId][] = "<script type=\"text/javascript\"> var uri = 'http://impgb.tradedoubler.com/imp?type(img)g($graphicalElementId)a($affiliateId)' + new String (Math.random()).substring (2, 11); document.write('<a href=\"http://clkuk.tradedoubler.com/click?p=$programId&a=$affiliateId&g=$graphicalElementId\" target=\"_BLANK\"><img src=\"'+uri+'\" border=0></a>'); </script>"; $creativesMap[(string)$programId][] = "<script type=\"text/javascript\"> var uri = 'http://impgb.tradedoubler.com/imp?type(iframe)g($graphicalElementId)a($affiliateId)' + new String (Math.random()).substring (2, 11); document.write('<iframe src=\"'+uri +'\" width=\"234\" height=\"60\" frameborder=\"0\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"></iframe>'); </script>"; **/ $creativesMap[(string) $programId][] = "<script type=\"text/javascript\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t var uri = 'http://impgb.tradedoubler.com/imp?type(js)g({$graphicalElementId})a({$affiliateId})' + new String (Math.random()).substring (2, 11);\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t document.write('<sc'+'ript type=\"text/javascript\" src=\"'+uri+'\" charset=\"\"></sc'+'ript>');\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t </script>"; } } } } } } return $creativesMap; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($idMerchant, $dStartDate, $dEndDate) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $returnResult = self::makeCall("transactiondetail", "&dateStart=" . $dStartDate->toString("MM/dd/yyyy") . "&dateEnd=" . $dEndDate->toString("MM/dd/yyyy")); $exportData = str_getcsv($returnResult, "\r\n"); $num = count($exportData); for ($i = 1; $i < $num; $i++) { $transactionExportArray = str_getcsv($exportData[$i], "|"); if (in_array((int) $transactionExportArray[1], $merchantList)) { $transaction = array(); $merchantId = (int) $transactionExportArray[1]; $transaction['merchantId'] = $merchantId; $transactionDate = new Zend_Date($transactionExportArray[2], 'MM-dd-yyyy HH:mm:ss'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); $transaction['unique_id'] = (int) $transactionExportArray[0]; if ($transactionExportArray[27] != null) { $transaction['custom_id'] = $transactionExportArray[27]; } if ($transactionExportArray[8] != null) { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } else { if ($transactionExportArray[9] != null) { $transaction['status'] = Oara_Utilities::STATUS_PENDING; } else { if ($transactionExportArray[7] != null) { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } else { $transaction['status'] = Oara_Utilities::STATUS_PENDING; } } } $transaction['amount'] = Oara_Utilities::parseDouble($transactionExportArray[3]); $transaction['commission'] = Oara_Utilities::parseDouble($transactionExportArray[4]); $totalTransactions[] = $transaction; } } return $totalTransactions; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); $urls = array(); $urls[] = new Oara_Curl_Request("{$this->_extension}/affiliate_invoice.html?", array()); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $tableList = $dom->query('.bluetable'); $exportData = self::htmlToCsv(self::DOMinnerHTML($tableList->current())); $num = count($exportData); for ($i = 4; $i < $num; $i++) { $paymentExportArray = str_getcsv($exportData[$i], ";"); if (count($paymentExportArray) > 7) { $obj = array(); $date = new Zend_Date($paymentExportArray[1], "dd/MM/yyyy"); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['pid'] = preg_replace('/[^0-9\\.,]/', "", $paymentExportArray[0]); $obj['method'] = 'BACS'; $value = preg_replace('/[^0-9\\.,]/', "", $paymentExportArray[8]); $obj['value'] = Oara_Utilities::parseDouble($value); $paymentHistory[] = $obj; } } return $paymentHistory; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory($currentPage = 1) { $paymentHistory = array(); $pdfToTextPath = ''; if (PHP_OS == "WIN32" || PHP_OS == "WINNT") { return $paymentHistory; } else { // some other platform $pdfToTextPath = 'pdftotext '; } $params = array(); if ($currentPage != 1) { $urls = array(); $urls[] = new Oara_Curl_Request($this->_serverUrl . '/Invoices/Default.aspx?', $params); $exportReport = $this->_client->post($urls); $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->validateOnParse = true; $doc->loadHTML($exportReport[0]); $viewState = $doc->getElementById('__VIEWSTATE')->attributes->getNamedItem("value")->nodeValue; $params = array(new Oara_Curl_Parameter('__EVENTTARGET', 'ctl00$ContentPlaceHolder1$gvInvoices'), new Oara_Curl_Parameter('__EVENTARGUMENT', 'Page$' . $currentPage), new Oara_Curl_Parameter('__VIEWSTATE', $viewState)); } $urls = array(); $urls[] = new Oara_Curl_Request($this->_serverUrl . '/Invoices/Default.aspx?', $params); $exportReport = $this->_client->post($urls); $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->validateOnParse = true; $doc->loadHTML($exportReport[0]); $registerTable = $doc->getElementById('ctl00_ContentPlaceHolder1_gvInvoices'); if ($registerTable !== null) { $registerLines = $registerTable->childNodes; $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $pagesNumber = 1; for ($i = 2; $i < $registerLines->length; $i++) { $registerLineClass = $registerLines->item($i)->attributes->getNamedItem("class")->nodeValue; if ($registerLineClass == 'pager') { $lenght = $registerLines->item($i)->childNodes->item(0)->childNodes->item(0)->childNodes->item(0)->childNodes->length; $pagesNumber = $registerLines->item($i)->childNodes->item(0)->childNodes->item(0)->childNodes->item(0)->childNodes->item($lenght - 2)->nodeValue; } else { $registerLine = $registerLines->item($i)->childNodes; $obj = array(); //get the pdf $parameters = array(); $parameters[] = new Oara_Curl_Parameter('id', $registerLine->item(0)->nodeValue); $urls = array(); $urls[] = new Oara_Curl_Request($this->_serverUrl . 'Invoices/ViewInvoice.aspx?', $parameters); $exportReport = $this->_client->get($urls); $exportReportUrl = $this->_client->get($urls, 'url'); $exportReportUrl = explode('/', $exportReportUrl[0]); $exportReportUrl = $exportReportUrl[count($exportReportUrl) - 1]; $dir = realpath(dirname(__FILE__)) . '/../../data/pdf/'; //writing temp pdf $fh = fopen($dir . $exportReportUrl, 'w') or die("can't open file"); fwrite($fh, $exportReport[0]); fclose($fh); //parsing the pdf $pipes = null; $pdfReader = proc_open($pdfToTextPath . $dir . $exportReportUrl . ' -', $descriptorspec, $pipes, null, null); if (is_resource($pdfReader)) { $pdfContent = ''; $error = ''; $stdin = $pipes[0]; $stdout = $pipes[1]; $stderr = $pipes[2]; while (!feof($stdout)) { $pdfContent .= fgets($stdout); } while (!feof($stderr)) { $error .= fgets($stderr); } fclose($stdin); fclose($stdout); fclose($stderr); $exit_code = proc_close($pdfReader); } if (preg_match_all("/[0-9]*,?[0-9]*\\.[0-9]+/", $pdfContent, $matches)) { $obj['value'] = Oara_Utilities::parseDouble($matches[0][count($matches[0]) - 1]); } else { throw new Exception('Problem getting value in payments'); } unlink($dir . $exportReportUrl); $date = new Zend_Date($registerLine->item(3)->nodeValue, "dd/MMM/yyyy", 'en_US'); $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss"); $obj['pid'] = $registerLine->item(0)->nodeValue; $obj['method'] = 'BACS'; $paymentHistory[] = $obj; } } if ($currentPage == 1) { for ($i = 2; $i <= $pagesNumber; $i++) { $paymentHistory = array_merge($paymentHistory, self::getPaymentHistory($i)); } } } return $paymentHistory; }
/** * The affjet cli , read the arguments and build the report requested * @param array arguments, Map of the cli arguments * * @param network, the affiliate network * @return none */ public static function affjetCli($arguments, $network) { //Start date, the first two months ago $startDate = new Zend_Date($arguments['s'], "dd/MM/yyyy"); $startDate->setHour(00); $startDate->setMinute(00); $startDate->setSecond(00); //Yesterday, some networks don't give us the data for the same day, then is the safer way to have our data $endDate = new Zend_Date($arguments['e'], "dd/MM/yyyy"); $endDate->setHour(23); $endDate->setMinute(59); $endDate->setSecond(59); //are we connected? fwrite(STDERR, "\nAccessing to your account \n\n"); if ($network->checkConnection()) { fwrite(STDERR, "Connected successfully \n\n"); if (!isset($arguments['t']) || $arguments['t'] == 'payment') { fwrite(STDERR, "Getting payments, please wait \n\n"); //Get all the payments for this network. $paymentsList = $network->getPaymentHistory(); fwrite(STDERR, "Number of payments: " . count($paymentsList) . "\n\n"); fwrite(STDERR, "------------------------------------------------------------------------\n"); fwrite(STDERR, "ID\t\t\tDATE\t\t\t\t\tVALUE\n"); fwrite(STDERR, "------------------------------------------------------------------------\n"); foreach ($paymentsList as $payment) { $paymentDate = new Zend_Date($payment['date'], "yyyy-MM-dd HH:mm:ss"); if ($paymentDate->compare($startDate) >= 0 && $paymentDate->compare($endDate) <= 0) { fwrite(STDERR, $payment['pid'] . "\t\t\t" . $payment['date'] . "\t\t\t" . $payment['value'] . " \n"); } } if (isset($arguments['t']) && $arguments['t'] == 'payment') { return null; } } //Get all the Merhcants fwrite(STDERR, "\nGetting merchants, please wait \n\n"); $merchantList = $network->getMerchantList(array()); if (!isset($arguments['t']) || $arguments['t'] == 'merchant') { fwrite(STDERR, "Number of merchants: " . count($merchantList) . "\n\n"); fwrite(STDERR, "--------------------------------------------------\n"); fwrite(STDERR, "ID\t\t\tNAME\n"); fwrite(STDERR, "--------------------------------------------------\n"); foreach ($merchantList as $merchant) { fwrite(STDERR, $merchant['cid'] . "\t\t\t" . $merchant['name'] . " \n"); } if (isset($arguments['t']) && $arguments['t'] == 'merchant') { return null; } } // Building the array of merchant Id we want to retrieve data from. $merchantIdList = array(); foreach ($merchantList as $merchant) { $merchantIdList[] = $merchant['cid']; } //If we have joined any merchant if (!empty($merchantIdList)) { $merchantMap = array(); foreach ($merchantList as $merchant) { $merchantMap[$merchant['name']] = $merchant['cid']; } //Split the dates monthly, Most of the network don't allow us to retrieve more than a month data $dateArray = Oara_Utilities::monthsOfDifference($startDate, $endDate); for ($i = 0; $i < count($dateArray); $i++) { // Calculating the start and end date for the current month $monthStartDate = clone $dateArray[$i]; $monthEndDate = null; if ($i != count($dateArray) - 1) { $monthEndDate = clone $dateArray[$i]; $monthEndDate->setDay(1); $monthEndDate->addMonth(1); $monthEndDate->subDay(1); } else { $monthEndDate = $endDate; } $monthEndDate->setHour(23); $monthEndDate->setMinute(59); $monthEndDate->setSecond(59); fwrite(STDERR, "\n*Importing data from " . $monthStartDate->toString("dd-MM-yyyy HH:mm:ss") . " to " . $monthEndDate->toString("dd-MM-yyyy HH:mm:ss") . "\n\n"); fwrite(STDERR, "Getting transactions, please wait \n\n"); $transactionList = $network->getTransactionList($merchantIdList, $monthStartDate, $monthEndDate, $merchantMap); if (!isset($arguments['t']) || $arguments['t'] == 'transaction') { fwrite(STDERR, "Number of transactions: " . count($transactionList) . "\n\n"); $totalAmount = 0; $totalCommission = 0; foreach ($transactionList as $transaction) { $totalAmount += $transaction['amount']; $totalCommission += $transaction['commission']; } fwrite(STDERR, "--------------------------------------------------\n"); fwrite(STDERR, "TOTAL AMOUNT\t\t{$totalAmount}\n"); fwrite(STDERR, "TOTAL COMMISSION\t{$totalCommission}\n"); fwrite(STDERR, "--------------------------------------------------\n\n"); } } } fwrite(STDERR, "Import finished \n\n"); } else { fwrite(STDERR, "Error connecting to the network, check credentials \n\n"); } }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $dateArray = Oara_Utilities::daysOfDifference($dStartDate, $dEndDate); $dateArraySize = sizeof($dateArray); for ($j = 0; $j < $dateArraySize; $j++) { $valuesFormExport = array(); $valuesFormExport[] = new Oara_Curl_Parameter('date', $dateArray[$j]->toString("yyyy-MM-dd")); $valuesFormExport[] = new Oara_Curl_Parameter('period', 'day'); $urls = array(); $urls[] = new Oara_Curl_Request('https://www.privateinternetaccess.com/affiliates/affiliate_dashboard?', $valuesFormExport); $exportReport = $this->_client->get($urls); $dom = new Zend_Dom_Query($exportReport[0]); $results = $dom->query('.coupon_code table'); if (count($results) > 0) { $exportData = self::htmlToCsv(self::DOMinnerHTML($results->current())); for ($z = 1; $z < count($exportData) - 2; $z++) { $transactionLineArray = str_getcsv($exportData[$z], ";"); $numberTransactions = (int) $transactionLineArray[1]; $commission = preg_replace("/[^0-9\\.,]/", "", $transactionLineArray[2]); $commission = (double) $commission / $numberTransactions; for ($y = 0; $y < $numberTransactions; $y++) { $transaction = array(); $transaction['merchantId'] = "1"; $transaction['date'] = $dateArray[$j]->toString("yyyy-MM-dd HH:mm:ss"); $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $transaction['amount'] = $commission; $transaction['commission'] = $commission; $totalTransactions[] = $transaction; } } } } return $totalTransactions; }
/** * @param null $merchantList * @param Zend_Date|null $dStartDate * @param Zend_Date|null $dEndDate * @param null $merchantMap * @return array */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $valuesFromExport = array(new Oara_Curl_Parameter('payment[from]', $dStartDate->toString("MM/dd/yyyy")), new Oara_Curl_Parameter('payment[to]', $dEndDate->toString("MM/dd/yyyy"))); $rch = curl_init(); $options = $this->_options; $arg = array(); foreach ($valuesFromExport as $parameter) { $arg[] = $parameter->getKey() . '=' . urlencode($parameter->getValue()); } $url = 'http://affiliates.shuttlefare.com/partners/payments/report.csv?' . implode('&', $arg); curl_setopt($rch, CURLOPT_URL, $url); curl_setopt_array($rch, $options); $html = curl_exec($rch); curl_close($rch); if (!preg_match("/No transaction in given date range/", $html) && $html) { $exportData = explode("\n", $html); $num = count($exportData); for ($i = 0; $i < $num - 1; $i++) { $transactionExportArray = explode(",", $exportData[$i]); $transaction = array(); $transaction['merchantId'] = 1; $transaction['unique_id'] = $transactionExportArray[0]; $transactionDate = new Zend_Date($transactionExportArray[7], 'MM/dd/yyyy'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; $transaction['amount'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $transactionExportArray[2])); $transaction['commission'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $transactionExportArray[3])); $totalTransactions[] = $transaction; } } return $totalTransactions; }