getMerchantIdMapFromMerchantList() публичный статический Метод

public static getMerchantIdMapFromMerchantList ( $merchantList ) : array
$merchantList
Результат array
Пример #1
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $limit = 100;
     $page = 1;
     $loop = true;
     while ($loop) {
         $apiURL = "http://api.hasoffers.com/v3/Affiliate_Report.json?limit={$limit}&page={$page}&Method=getConversions&api_key={$this->_apiPassword}&NetworkId={$this->_domain}&fields[]=Stat.offer_id&fields[]=Stat.datetime&fields[]=Offer.name&fields[]=Stat.conversion_status&fields[]=Stat.payout&fields[]=Stat.conversion_sale_amount&fields[]=Stat.ip&fields[]=Stat.ad_id&fields[]=Stat.affiliate_info1&sort[Stat.datetime]=desc&filters[Stat.date][conditional]=BETWEEN&filters[Stat.date][values][]={$dStartDate->format("Y-m-d")}&filters[Stat.date][values][]={$dEndDate->format("Y-m-d")}&data_start={$dStartDate->format("Y-m-d")}&data_end={$dEndDate->format("Y-m-d")}";
         $response = self::call($apiURL);
         foreach ($response["response"]["data"]["data"] as $transactionApi) {
             $transaction = array();
             $merchantId = (int) $transactionApi["Stat"]["offer_id"];
             if ($merchantList == null || isset($merchantIdList[$merchantId])) {
                 $transaction['merchantId'] = $merchantId;
                 $transaction['date'] = $transactionApi["Stat"]["datetime"];
                 if ($transactionApi["Stat"]["ad_id"] != null) {
                     $transaction['unique_id'] = $transactionApi["Stat"]["ad_id"];
                 }
                 if ($transactionApi["Stat"]["affiliate_info1"] != null) {
                     $transaction['custom_id'] = $transactionApi["Stat"]["affiliate_info1"];
                 }
                 if ($transactionApi["Stat"]["conversion_status"] == "approved") {
                     $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if ($transactionApi["Stat"]["conversion_status"] == "pending") {
                         $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                     } else {
                         if ($transactionApi["Stat"]["conversion_status"] == "rejected") {
                             $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                         }
                     }
                 }
                 $transaction['amount'] = $transactionApi["Stat"]["payout"];
                 if (isset($transactionApi["Stat"]["conversion_sale_amount"])) {
                     $transaction['amount'] = $transactionApi["Stat"]["conversion_sale_amount"];
                 }
                 $transaction['commission'] = $transactionApi["Stat"]["payout"];
                 $totalTransactions[] = $transaction;
             }
         }
         if ((int) $response["response"]["data"]["pageCount"] <= $page) {
             $loop = false;
         }
         $page++;
     }
     return $totalTransactions;
 }
Пример #2
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $transactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $transactionsExportList = self::request("https://api.commissionfactory.com.au/V1/Affiliate/Transactions?apiKey={$this->_apiKey}&fromDate={$dStartDate->format("Y-m-d")}&toDate={$dEndDate->format("Y-m-d")}");
     foreach ($transactionsExportList as $transaction) {
         if (isset($merchantIdList[$transaction["MerchantId"]])) {
             $obj = array();
             $obj['merchantId'] = $transaction["MerchantId"];
             $transactionDate = \DateTime::createFromFormat("Y-m-d\\TH:i:s", \substr($transaction["DateCreated"], 0, 19));
             $obj['date'] = $transactionDate->format("Y-m-d H:i:s");
             if ($transaction["UniqueId"] != null) {
                 $obj['custom_id'] = $transaction["UniqueId"];
             }
             $obj['unique_id'] = $transaction["Id"];
             if ($transaction["Status"] == "Approved") {
                 $obj['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if ($transaction["Status"] == "Pending") {
                     $obj['status'] = \Oara\Utilities::STATUS_PENDING;
                 } else {
                     if ($transaction["Status"] == "Void") {
                         $obj['status'] = \Oara\Utilities::STATUS_DECLINED;
                     }
                 }
             }
             $obj['amount'] = \Oara\Utilities::parseDouble($transaction["SaleValue"]);
             $obj['commission'] = \Oara\Utilities::parseDouble($transaction["Commission"]);
             $transactions[] = $obj;
         }
     }
     return $transactions;
 }
Пример #3
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $user = $this->_credentials['user'];
     $password = $this->_credentials['password'];
     foreach ($this->_publisherId as $publisherId) {
         $page = 1;
         $pageSize = 100;
         $finish = false;
         while (!$finish) {
             $url = "https://services.daisycon.com:443/publishers/{$publisherId}/transactions?page={$page}&per_page={$pageSize}&start=" . \urlencode($dStartDate->format("Y-m-d H:i:s")) . "&end=" . \urlencode($dEndDate->format("Y-m-d H:i:s"));
             // initialize curl resource
             $ch = \curl_init();
             // set the http request authentication headers
             $headers = array('Authorization: Basic ' . \base64_encode($user . ':' . $password));
             // set curl options
             \curl_setopt($ch, CURLOPT_URL, $url);
             \curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
             \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             // execute curl
             $response = \curl_exec($ch);
             $transactionList = \json_decode($response, true);
             if ($transactionList) {
                 foreach ($transactionList as $transaction) {
                     $merchantId = $transaction['program_id'];
                     if (isset($merchantIdList[$merchantId])) {
                         $transactionArray = array();
                         $transactionArray['unique_id'] = $transaction['affiliatemarketing_id'];
                         $transactionArray['merchantId'] = $merchantId;
                         $transactionDate = new \DateTime($transaction['date']);
                         $transactionArray['date'] = $transactionDate->format("Y-m-d H:i:s");
                         $parts = \current($transaction['parts']);
                         if ($parts['subid'] != null) {
                             $transactionArray['custom_id'] = $parts['subid'];
                         }
                         if ($parts['status'] == 'approved') {
                             $transactionArray['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                         } else {
                             if ($parts['status'] == 'pending' || $parts['status'] == 'potential' || $parts['status'] == 'open') {
                                 $transactionArray['status'] = \Oara\Utilities::STATUS_PENDING;
                             } else {
                                 if ($parts['status'] == 'disapproved' || $parts['status'] == 'incasso') {
                                     $transactionArray['status'] = \Oara\Utilities::STATUS_DECLINED;
                                 } else {
                                     throw new \Exception("New status {$parts['status']}");
                                 }
                             }
                         }
                         $transactionArray['amount'] = \Oara\Utilities::parseDouble($parts['revenue']);
                         $transactionArray['commission'] = \Oara\Utilities::parseDouble($parts['commission']);
                         $totalTransactions[] = $transactionArray;
                     }
                 }
             }
             if (\count($transactionList) != $pageSize) {
                 $finish = true;
             }
             $page++;
         }
     }
     return $totalTransactions;
 }
Пример #4
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws \Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $valuesFormExport = array();
     $urls = array();
     $urls[] = new \Oara\Curl\Request('http://system.fashiontraffic.com/stats/lead_report', $valuesFormExport);
     $exportReport = $this->_client->post($urls);
     $doc = new \DOMDocument();
     @$doc->loadHTML($exportReport[0]);
     $xpath = new \DOMXPath($doc);
     $results = $xpath->query('//input[@name="data[_Token][key]"]');
     foreach ($results as $values) {
         $valuesFormExport[] = new \Oara\Curl\Parameter($values->getAttribute("name"), $values->getAttribute("value"));
     }
     $results = $xpath->query('//input[@name="data[_Token][fields]"]');
     foreach ($results as $values) {
         $valuesFormExport[] = new \Oara\Curl\Parameter($values->getAttribute("name"), $values->getAttribute("value"));
     }
     $valuesFormExport[] = new \Oara\Curl\Parameter("_method", 'POST');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][page]", '');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.offer_id');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.datetime');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.ad_id');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.source');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.affiliate_info1');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.affiliate_info2');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.affiliate_info3');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.affiliate_info4');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.affiliate_info5');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.conversion_payout');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][fields][]", 'Stat.conversion_status');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][search][field]", '');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[Report][search][value]", '');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[DateRange][timezone]", 'America/New_York');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[DateRange][preset_date_range]", 'other');
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[DateRange][start_date]", $dStartDate->format("Y-m-d"));
     $valuesFormExport[] = new \Oara\Curl\Parameter("data[DateRange][end_date]", $dEndDate->format("Y-m-d"));
     $urls = array();
     $urls[] = new \Oara\Curl\Request('http://system.fashiontraffic.com/stats/lead_report', $valuesFormExport);
     $exportReport = $this->_client->post($urls);
     $csvUrl = null;
     if (\preg_match("/report:(.*).csv/", $exportReport[0], $match)) {
         $csvUrl = "http://system.fashiontraffic.com/stats/conversion_report/report:{$match[1]}.csv";
     }
     $valuesFormExport = array();
     $urls = array();
     $urls[] = new \Oara\Curl\Request($csvUrl, $valuesFormExport);
     $exportReport = $this->_client->get($urls);
     $exportData = \str_getcsv($exportReport[0], "\n");
     $num = \count($exportData);
     for ($i = 1; $i < $num; $i++) {
         $transactionExportArray = \str_getcsv($exportData[$i], ",");
         if (isset($merchantIdList[(int) $transactionExportArray[0]])) {
             $transaction = array();
             $merchantId = (int) $transactionExportArray[0];
             $transaction['merchantId'] = $merchantId;
             $transaction['date'] = $transactionExportArray[1];
             if ($transactionExportArray[5] != null) {
                 $transaction['custom_id'] = $transactionExportArray[5];
             }
             if ($transactionExportArray[10] == 'approved') {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if ($transactionExportArray[10] == 'rejected') {
                     $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                 } else {
                     throw new \Exception("Status {$transactionExportArray[10]} unknown");
                 }
             }
             $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[9]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[9]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #5
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $context = \stream_context_create(array('http' => array('header' => "Authorization: Basic " . \base64_encode("{$this->_user}:{$this->_pass}"))));
     $from = \urlencode($dStartDate->format("Y-m-d H:i:s"));
     $data = \file_get_contents("http://api.webepartners.pl/wydawca/Auctions?from={$from}", false, $context);
     $dataArray = \json_decode($data, true);
     foreach ($dataArray as $transactionObject) {
         if (isset($merchantIdList[$transactionObject["ProgramId"]])) {
             $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;
 }
Пример #6
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $totalTransactions = array();
     $valuesFormExport = array(new \Oara\Curl\Parameter('reportName', 'aAffiliateEventBreakdownReport'), new \Oara\Curl\Parameter('columns', 'programId'), new \Oara\Curl\Parameter('columns', 'timeOfVisit'), new \Oara\Curl\Parameter('columns', 'timeOfEvent'), new \Oara\Curl\Parameter('columns', 'timeInSession'), new \Oara\Curl\Parameter('columns', 'lastModified'), new \Oara\Curl\Parameter('columns', 'epi1'), new \Oara\Curl\Parameter('columns', 'eventName'), new \Oara\Curl\Parameter('columns', 'pendingStatus'), new \Oara\Curl\Parameter('columns', 'siteName'), new \Oara\Curl\Parameter('columns', 'graphicalElementName'), new \Oara\Curl\Parameter('columns', 'graphicalElementId'), new \Oara\Curl\Parameter('columns', 'productName'), new \Oara\Curl\Parameter('columns', 'productNrOf'), new \Oara\Curl\Parameter('columns', 'productValue'), new \Oara\Curl\Parameter('columns', 'affiliateCommission'), new \Oara\Curl\Parameter('columns', 'link'), new \Oara\Curl\Parameter('columns', 'leadNR'), new \Oara\Curl\Parameter('columns', 'orderNR'), new \Oara\Curl\Parameter('columns', 'pendingReason'), new \Oara\Curl\Parameter('columns', 'orderValue'), new \Oara\Curl\Parameter('isPostBack', ''), new \Oara\Curl\Parameter('metric1.lastOperator', '/'), new \Oara\Curl\Parameter('interval', ''), new \Oara\Curl\Parameter('favoriteDescription', ''), new \Oara\Curl\Parameter('event_id', '0'), new \Oara\Curl\Parameter('pending_status', '1'), new \Oara\Curl\Parameter('run_as_organization_id', ''), new \Oara\Curl\Parameter('minRelativeIntervalStartTime', '0'), new \Oara\Curl\Parameter('includeWarningColumn', 'true'), new \Oara\Curl\Parameter('metric1.summaryType', 'NONE'), new \Oara\Curl\Parameter('metric1.operator1', '/'), new \Oara\Curl\Parameter('latestDayToExecute', '0'), new \Oara\Curl\Parameter('showAdvanced', 'true'), new \Oara\Curl\Parameter('breakdownOption', '1'), new \Oara\Curl\Parameter('metric1.midFactor', ''), new \Oara\Curl\Parameter('reportTitleTextKey', 'REPORT3_SERVICE_REPORTS_AAFFILIATEEVENTBREAKDOWNREPORT_TITLE'), new \Oara\Curl\Parameter('setColumns', 'true'), new \Oara\Curl\Parameter('metric1.columnName1', 'orderValue'), new \Oara\Curl\Parameter('metric1.columnName2', 'orderValue'), new \Oara\Curl\Parameter('reportPrograms', ''), new \Oara\Curl\Parameter('metric1.midOperator', '/'), new \Oara\Curl\Parameter('dateSelectionType', '1'), new \Oara\Curl\Parameter('favoriteName', ''), new \Oara\Curl\Parameter('affiliateId', ''), new \Oara\Curl\Parameter('dateType', '1'), new \Oara\Curl\Parameter('period', 'custom_period'), new \Oara\Curl\Parameter('tabMenuName', ''), new \Oara\Curl\Parameter('maxIntervalSize', '0'), new \Oara\Curl\Parameter('favoriteId', ''), new \Oara\Curl\Parameter('sortBy', 'timeOfEvent'), new \Oara\Curl\Parameter('metric1.name', ''), new \Oara\Curl\Parameter('customKeyMetricCount', '0'), new \Oara\Curl\Parameter('metric1.factor', ''), new \Oara\Curl\Parameter('showFavorite', 'false'), new \Oara\Curl\Parameter('separator', ','), new \Oara\Curl\Parameter('format', 'CSV'));
     $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 (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[13], $this->_sitesAllowed)) {
             if ($transactionExportArray[0] !== '' && isset($merchantIdList[(int) $transactionExportArray[2]])) {
                 $transaction = array();
                 $transaction['merchantId'] = $transactionExportArray[2];
                 $transactionDate = self::toDate($transactionExportArray[4]);
                 $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
                 if ($transactionExportArray[8] != '') {
                     $transaction['unique_id'] = \substr($transactionExportArray[8], 0, 200);
                 } else {
                     if ($transactionExportArray[7] != '') {
                         $transaction['unique_id'] = \substr($transactionExportArray[7], 0, 200);
                     } 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[19] != '') {
                     $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[19]);
                 } else {
                     $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[20]);
                 }
                 $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[20]);
                 $totalTransactions[] = $transaction;
             }
         }
     }
     return $totalTransactions;
 }
Пример #7
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $transactions = array();
     $page = 1;
     $import = true;
     $merchantIdMap = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     while ($import) {
         $totalRows = $page * 300;
         $urls = array();
         $valuesFromExport = array();
         $valuesFromExport[] = new \Oara\Curl\Parameter('email', $this->_user);
         $valuesFromExport[] = new \Oara\Curl\Parameter('apikey', $this->_pass);
         $valuesFromExport[] = new \Oara\Curl\Parameter('from', $dStartDate->format("Y-m-d"));
         $valuesFromExport[] = new \Oara\Curl\Parameter('to', $dEndDate->format("Y-m-d"));
         $valuesFromExport[] = new \Oara\Curl\Parameter('limit', 300);
         $valuesFromExport[] = new \Oara\Curl\Parameter('page', $page);
         $urls[] = new \Oara\Curl\Request("http://api.affiliate4you.nl/1.0/orders.csv?", $valuesFromExport);
         try {
             $result = $this->_client->get($urls);
         } catch (\Exception $e) {
             return $transactions;
         }
         $exportData = \str_getcsv($result[0], "\n");
         for ($i = 1; $i < \count($exportData); $i++) {
             $transactionExportArray = \str_getcsv($exportData[$i], ";");
             if (isset($merchantIdMap[$transactionExportArray[12]])) {
                 $transaction = array();
                 $transaction['unique_id'] = $transactionExportArray[3];
                 $transaction['merchantId'] = $transactionExportArray[12];
                 $transaction['date'] = $transactionExportArray[0];
                 if ($transactionExportArray[8] != null) {
                     $transaction['custom_id'] = $transactionExportArray[8];
                 }
                 if ($transactionExportArray[5] == 'approved') {
                     $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if ($transactionExportArray[5] == 'new' || $transactionExportArray[5] == 'onhold') {
                         $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                     } else {
                         if ($transactionExportArray[5] == 'declined') {
                             $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                         }
                     }
                 }
                 $transaction['amount'] = $transactionExportArray[4];
                 $transaction['commission'] = $transactionExportArray[1];
                 $transactions[] = $transaction;
             }
         }
         if (\count($exportData) != $totalRows + 1) {
             $import = false;
         }
         $page++;
     }
     return $transactions;
 }
Пример #8
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $uniqueIdMap = array();
     foreach ($this->_siteList as $site) {
         if (empty($this->_sitesAllowed) || in_array($site->id, $this->_sitesAllowed)) {
             echo "getting Transactions for site " . $site->id . "\n\n";
             $url = "https://ran-reporting.rakutenmarketing.com/en/reports/individual-item-report/filters?start_date=" . $dStartDate->format("Y-m-d") . "&end_date=" . $dEndDate->format("Y-m-d") . "&include_summary=N" . "&network=" . $this->_nid . "&tz=GMT&date_type=transaction&token=" . urlencode($site->token);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
             curl_setopt($ch, CURLOPT_TIMEOUT, 50);
             $result = curl_exec($ch);
             $info = curl_getinfo($ch);
             if ($info['http_code'] != 200) {
                 return $totalTransactions;
             }
             curl_close($ch);
             $url = "https://ran-reporting.rakutenmarketing.com/en/reports/signature-orders-report/filters?start_date=" . $dStartDate->format("Y-m-d") . "&end_date=" . $dEndDate->format("Y-m-d") . "&include_summary=N" . "&network=" . $this->_nid . "&tz=GMT&date_type=transaction&token=" . urlencode($site->token);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
             curl_setopt($ch, CURLOPT_TIMEOUT, 50);
             $resultSignature = curl_exec($ch);
             $info = curl_getinfo($ch);
             if ($info['http_code'] != 200) {
                 return $totalTransactions;
             }
             curl_close($ch);
             $signatureMap = array();
             $exportData = str_getcsv($resultSignature, "\n");
             $num = count($exportData);
             for ($j = 1; $j < $num; $j++) {
                 $signatureData = str_getcsv($exportData[$j], ",");
                 $signatureMap[$signatureData[3]] = $signatureData[0];
             }
             $exportData = \str_getcsv($result, "\n");
             $num = \count($exportData);
             for ($j = 1; $j < $num; $j++) {
                 $transactionData = \str_getcsv($exportData[$j], ",");
                 if (isset($merchantIdList[$transactionData[3]]) && count($transactionData) == 10) {
                     $transaction = array();
                     $transaction['merchantId'] = (int) $transactionData[3];
                     $transactionDate = \DateTime::createFromFormat("m/d/y H:i:s", $transactionData[1] . " " . $transactionData[2]);
                     $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
                     if (isset($signatureMap[$transactionData[0]])) {
                         $transaction['custom_id'] = $signatureMap[$transactionData[0]];
                     }
                     if (!isset($uniqueIdMap[$transactionData[0]])) {
                         $uniqueIdMap[$transactionData[0]] = 1;
                     } else {
                         $uniqueIdMap[$transactionData[0]]++;
                     }
                     $transaction['unique_id'] = $transactionData[0] . '_' . $uniqueIdMap[$transactionData[0]];
                     $sales = \Oara\Utilities::parseDouble($transactionData[7]);
                     if ($sales != 0) {
                         $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                     } else {
                         if ($sales == 0) {
                             $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                         }
                     }
                     $transaction['amount'] = $sales;
                     $transaction['commission'] = \Oara\Utilities::parseDouble($transactionData[9]);
                     $totalTransactions[] = $transaction;
                 }
             }
         }
     }
     return $totalTransactions;
 }
Пример #9
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdMap = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $result = $this->_client->getEventList(null, null, null, null, null, $dStartDate->format("Y-m-d"), $dEndDate->format("Y-m-d"), null, null, null, null, 0);
     foreach ($result->handler->events as $event) {
         if (isset($merchantIdMap[$event["programid"]])) {
             $transaction = array();
             $transaction['unique_id'] = $event["eventid"];
             $transaction['merchantId'] = $event["programid"];
             $transaction['date'] = $event["eventdate"];
             if ($event["subid"] != null) {
                 $transaction['custom_id'] = $event["subid"];
                 if (\preg_match("/subid1=/", $transaction['custom_id'])) {
                     $transaction['custom_id'] = str_replace("subid1=", "", $transaction['custom_id']);
                 }
             }
             if ($event["eventstatus"] == 'APPROVED') {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if ($event["eventstatus"] == 'PENDING') {
                     $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                 } else {
                     if ($event["eventstatus"] == 'REJECTED') {
                         $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                     }
                 }
             }
             $transaction['amount'] = \Oara\Utilities::parseDouble($event["netvalue"]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($event["eventcommission"]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #10
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $dStartDate = clone $dStartDate;
     $dStartDate->setTime(0, 0, 0);
     $dEndDate = clone $dEndDate;
     $dEndDate->setTime(23, 59, 59);
     $params = array();
     $params['sDateType'] = 'transaction';
     if ($merchantList != null) {
         $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
         $params['aMerchantIds'] = \array_keys($merchantIdList);
     }
     if ($dStartDate != null) {
         $params['dStartDate'] = $dStartDate->format("Y-m-d\\TH:i:s");
     }
     if ($dEndDate != null) {
         $params['dEndDate'] = $dEndDate->format("Y-m-d\\TH:i:s");
     }
     $params['iOffset'] = null;
     $params['iLimit'] = $this->_pageSize;
     $transactionList = $this->_apiClient->getTransactionList($params);
     if (\sizeof($transactionList->getTransactionListReturn) > 0) {
         $iteration = self::getIterationNumber($transactionList->getTransactionListCountReturn->iRowsAvailable, $this->_pageSize);
         unset($transactionList);
         for ($j = 0; $j < $iteration; $j++) {
             $params['iOffset'] = $this->_pageSize * $j;
             $transactionList = $this->_apiClient->getTransactionList($params);
             foreach ($transactionList->getTransactionListReturn as $transactionObject) {
                 if ($transactionObject->sType != 'bonus' || $transactionObject->sType == 'bonus' && $this->_includeBonus) {
                     $transaction = array();
                     $transaction['unique_id'] = $transactionObject->iId;
                     $transaction['merchantId'] = $transactionObject->iMerchantId;
                     $date = new \DateTime($transactionObject->dTransactionDate);
                     $transaction['date'] = $date->format("Y-m-d H:i:s");
                     if (isset($transactionObject->sClickref) && $transactionObject->sClickref != null) {
                         $transaction['custom_id'] = $transactionObject->sClickref;
                     }
                     $transaction['type'] = $transactionObject->sType;
                     $transaction['status'] = $transactionObject->sStatus;
                     $transaction['amount'] = $transactionObject->mSaleAmount->dAmount;
                     $transaction['commission'] = $transactionObject->mCommissionAmount->dAmount;
                     if (isset($transactionObject->aTransactionParts)) {
                         $transactionPart = \current($transactionObject->aTransactionParts);
                         $transaction['currency'] = $transactionPart->mCommissionAmount->sCurrency;
                     }
                     $totalTransactions[] = $transaction;
                 }
             }
             unset($transactionList);
             \gc_collect_cycles();
         }
     }
     return $totalTransactions;
 }
Пример #11
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws \Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $merchantIdMap = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $nowDate = new \DateTime();
     $dStartDate = clone $dStartDate;
     $dStartDate->setTime(0, 0, 0);
     $dEndDate = clone $dEndDate;
     $dEndDate->setTime(23, 59, 59);
     $valuesFromExport = array();
     $valuesFromExport[] = new \Oara\Curl\Parameter('username', $this->_credentials["user"]);
     $valuesFromExport[] = new \Oara\Curl\Parameter('password', $this->_credentials["password"]);
     $valuesFromExport[] = new \Oara\Curl\Parameter('startDate', $dStartDate->format("d-M-Y"));
     $valuesFromExport[] = new \Oara\Curl\Parameter('endDate', $dEndDate->format("d-M-Y"));
     $transactions = array();
     $urls = array();
     $urls[] = new \Oara\Curl\Request('http://ws-external.afnt.co.uk/apiv1/AFFILIATES/affiliatefuture.asmx/GetTransactionListbyDate?', $valuesFromExport);
     $urls[] = new \Oara\Curl\Request('http://ws-external.afnt.co.uk/apiv1/AFFILIATES/affiliatefuture.asmx/GetCancelledTransactionListbyDate?', $valuesFromExport);
     $exportReport = $this->_client->get($urls);
     for ($i = 0; $i < \count($urls); $i++) {
         $xml = self::loadXml($exportReport[$i]);
         if (isset($xml->error)) {
             throw new \Exception('Error connecting with the server');
         }
         if (isset($xml->TransactionList)) {
             foreach ($xml->TransactionList as $transaction) {
                 $date = new \DateTime(self::findAttribute($transaction, 'TransactionDate'));
                 if (isset($merchantIdMap[(int) self::findAttribute($transaction, 'ProgrammeID')]) && $date->format("Y-m-d H:i:s") >= $dStartDate->format("Y-m-d H:i:s") && $date->format("Y-m-d H:i:s") <= $dEndDate->format("Y-m-d H:i:s")) {
                     $obj = array();
                     $obj['merchantId'] = self::findAttribute($transaction, 'ProgrammeID');
                     $obj['date'] = $date->format("Y-m-d H:i:s");
                     if (self::findAttribute($transaction, 'TrackingReference') != null) {
                         $obj['custom_id'] = self::findAttribute($transaction, 'TrackingReference');
                     }
                     $obj['unique_id'] = self::findAttribute($transaction, 'TransactionID');
                     if ($i == 0) {
                         $interval = $date->diff($nowDate);
                         if ($interval->format('%a') > 5) {
                             $obj['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                         } else {
                             $obj['status'] = \Oara\Utilities::STATUS_PENDING;
                         }
                     } else {
                         if ($i == 1) {
                             $obj['status'] = \Oara\Utilities::STATUS_DECLINED;
                         }
                     }
                     $obj['amount'] = \Oara\Utilities::parseDouble(self::findAttribute($transaction, 'SaleValue'));
                     $obj['commission'] = \Oara\Utilities::parseDouble(self::findAttribute($transaction, 'SaleCommission'));
                     $leadCommission = \Oara\Utilities::parseDouble(self::findAttribute($transaction, 'LeadCommission'));
                     if ($leadCommission != 0) {
                         $obj['commission'] += $leadCommission;
                     }
                     $transactions[] = $obj;
                 }
             }
         }
     }
     return $transactions;
 }
Пример #12
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $urls = array();
     $urls[] = new \Oara\Curl\Request($this->_url . "publisher/report/transaction-details?apiKey={$this->_password}&startDate={$dStartDate->format("Y-m-d")}&endDate={$dEndDate->format("Y-m-d")}&joined&format=json", array());
     $exportReport = $this->_client->get($urls);
     $transactionList = \json_decode($exportReport[0], true);
     foreach ($transactionList["data"] as $transactionExportArray) {
         if (isset($merchantIdList[(int) $transactionExportArray["program_id"]])) {
             $transaction = array();
             $merchantId = (int) $transactionExportArray["program_id"];
             $transaction['merchantId'] = $merchantId;
             $transaction['date'] = $transactionExportArray["date"];
             $transaction['unique_id'] = $transactionExportArray["transaction_id"];
             if ($transactionExportArray["sid"] != null) {
                 $transaction['custom_id'] = $transactionExportArray["sid"];
             }
             $status = $transactionExportArray["status"];
             if ($status == 'pending' || $status == 'delayed' || $status == 'unconfirmed') {
                 $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
             } elseif ($status == 'locked') {
                 $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
             } elseif ($status == 'paid') {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 throw new \Exception("Status {$status} unknown");
             }
             $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray["sale_amount"]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray["commission"]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #13
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantListIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     foreach ($this->_campaignMap as $campaignKey => $campaignValue) {
         try {
             $transactionList = $this->_soapClient->getFullEarningsWithCurrency($dStartDate->format("Y-m-d\\TH:i:s"), $dEndDate->format("Y-m-d\\TH:i:s"), $campaignKey, $this->_user, $this->_password);
         } catch (\Exception $e) {
             if (\preg_match("/60 requests/", $e->getMessage())) {
                 \sleep(60);
                 $transactionList = $this->_soapClient->getFullEarningsWithCurrency($dStartDate->format("Y-m-d\\TH:i:s"), $dEndDate->format("Y-m-d\\TH:i:s"), $campaignKey, $this->_user, $this->_password);
             }
         }
         foreach ($transactionList as $transactionObject) {
             if (isset($merchantListIdList[$transactionObject->programID])) {
                 $transaction = array();
                 $transaction['merchantId'] = $transactionObject->programID;
                 $transactionDate = \DateTime::createFromFormat("Y-m-d\\TH:i:s", $transactionObject->date);
                 $transaction["date"] = $transactionDate->format("Y-m-d H:i:s");
                 $transaction['unique_id'] = $transactionObject->transactionID;
                 if ($transactionObject->clickRef != null) {
                     $transaction['custom_id'] = $transactionObject->clickRef;
                 }
                 $transaction['status'] = null;
                 $transaction['amount'] = $transactionObject->saleValue;
                 $transaction['commission'] = $transactionObject->commission;
                 if ($transactionObject->paymentStatus == 'cleared' || $transactionObject->paymentStatus == 'paid') {
                     $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if ($transactionObject->paymentStatus == 'notcleared') {
                         $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                     } else {
                         if ($transactionObject->paymentStatus == 'cancelled') {
                             $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                         } else {
                             throw new \Exception('Error in the transaction status ' . $transactionObject->paymentStatus);
                         }
                     }
                 }
                 $transaction['currency'] = $transactionObject->currency;
                 $totalTransactions[] = $transaction;
             }
         }
     }
     return $totalTransactions;
 }
Пример #14
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $url = 'http://api.effiliation.com/apiv2/transaction.csv?key=' . $this->_credentials["apipassword"] . '&start=' . $dStartDate->format("d/m/Y") . '&end=' . $dEndDate->format("d/m/Y") . '&type=date';
     $content = \utf8_encode(\file_get_contents($url));
     $exportData = \str_getcsv($content, "\n");
     $num = \count($exportData);
     for ($i = 1; $i < $num; $i++) {
         $transactionExportArray = \str_getcsv($exportData[$i], "|");
         if (isset($merchantIdList[(int) $transactionExportArray[2]])) {
             $transaction = array();
             $merchantId = (int) $transactionExportArray[2];
             $transaction['merchantId'] = $merchantId;
             $transaction['date'] = $transactionExportArray[10];
             $transaction['unique_id'] = $transactionExportArray[0];
             if ($transactionExportArray[15] != null) {
                 $transaction['custom_id'] = $transactionExportArray[15];
             }
             if ($transactionExportArray[9] == 'Valide') {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if ($transactionExportArray[9] == 'Attente') {
                     $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                 } else {
                     if ($transactionExportArray[9] == 'Refusé' || $transactionExportArray[9] == 'Refuse') {
                         $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                     } else {
                         throw new \Exception("New status {$transactionExportArray[9]}");
                     }
                 }
             }
             $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[7]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[8]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #15
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $dEndDate->add(new \DateInterval('P1D'));
     $publisherStatisticsServiceUrl = 'https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl';
     $publisherStatisticsService = new \SoapClient($publisherStatisticsServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1));
     $iterationNumber = self::calculeIterationNumber(\count($merchantIdList), 100);
     for ($currentIteration = 0; $currentIteration < $iterationNumber; $currentIteration++) {
         $merchantListSlice = \array_slice(\array_keys($merchantIdList), 100 * $currentIteration, 100);
         $merchantListAux = array();
         foreach ($merchantListSlice as $merchant) {
             $merchantListAux[] = (string) $merchant;
         }
         $params = array('StartDate' => \strtotime($dStartDate->format("Y-m-d")), 'EndDate' => \strtotime($dEndDate->format("Y-m-d")), '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;
             }
             foreach ($transactionCollection as $transactionObject) {
                 $transaction = array();
                 $transaction["status"] = $transactionObject->TransactionStatus;
                 $transaction["unique_id"] = $transactionObject->TransactionId;
                 $transaction["commission"] = $transactionObject->PublisherCommission;
                 $transaction["amount"] = $transactionObject->NetPrice;
                 $dateString = \explode(".", $transactionObject->RegistrationDate);
                 $transactionDate = \DateTime::createFromFormat("Y-m-d\\TH:i:s", $dateString[0]);
                 $transaction["date"] = $transactionDate->format("Y-m-d H:i:s");
                 $transaction["merchantId"] = $transactionObject->ProgramId;
                 $transaction["custom_id"] = $transactionObject->SubId;
                 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;
 }
Пример #16
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $startDate = $dStartDate->format('d/m/Y');
     $endDate = $dEndDate->format('d/m/Y');
     $marchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $valueIndex = 9;
     $commissionIndex = 16;
     $statusIndex = 17;
     $valuesFormExport = array(new \Oara\Curl\Parameter('user', $this->_exportUser), new \Oara\Curl\Parameter('pwd', $this->_exportPassword), new \Oara\Curl\Parameter('report', 'AMSCommission_Breakdown'), new \Oara\Curl\Parameter('groupby', 'Programme'), new \Oara\Curl\Parameter('groupdate', 'Day'), new \Oara\Curl\Parameter('creative', ''), new \Oara\Curl\Parameter('CommOnly', '1'), new \Oara\Curl\Parameter('showimpressions', 'True'), new \Oara\Curl\Parameter('showclicks', 'True'), new \Oara\Curl\Parameter('showreferrals', 'True'), new \Oara\Curl\Parameter('showtransactionvalues', 'True'), new \Oara\Curl\Parameter('sort', 'Date asc'), new \Oara\Curl\Parameter('format', 'csv'));
     $valuesFormExport[] = new \Oara\Curl\Parameter('datefrom', $startDate);
     $valuesFormExport[] = new \Oara\Curl\Parameter('dateto', $endDate);
     $urls = array();
     $urls[] = new \Oara\Curl\Request($this->_serverUrl . 'reports/remote.aspx?', $valuesFormExport);
     $exportReport = $this->_client->get($urls);
     $exportData = \str_getcsv($exportReport[0], "\r\n");
     $num = \count($exportData);
     for ($i = 1; $i < $num; $i++) {
         $transactionExportArray = \str_getcsv($exportData[$i], ",");
         if (isset($marchantIdList[$transactionExportArray[4]])) {
             $transaction = array();
             $transaction['unique_id'] = \preg_replace('/\\D/', '', $transactionExportArray[0]);
             $transaction['merchantId'] = $transactionExportArray[4];
             $transactionDate = \DateTime::createFromFormat("d/m/Y H:i:s", $transactionExportArray[2]);
             $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
             if ($transactionExportArray[7] != null) {
                 $transaction['custom_id'] = $transactionExportArray[7];
             }
             if (\preg_match('/Unpaid Confirmed/', $transactionExportArray[$statusIndex]) || \preg_match('/Paid Confirmed/', $transactionExportArray[$statusIndex])) {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if (\preg_match('/Unpaid Unconfirmed/', $transactionExportArray[$statusIndex])) {
                     $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                 } else {
                     if (\preg_match('/Unpaid Rejected/', $transactionExportArray[$statusIndex])) {
                         $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                     } else {
                         throw new \Exception("No Status supported " . $transactionExportArray[$statusIndex]);
                     }
                 }
             }
             $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[$valueIndex]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[$commissionIndex]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #17
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $mechantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $returnResult = self::makeCall("activity", "&dateStart=" . $dStartDate->format("m/d/Y") . "&dateEnd=" . $dEndDate->format("m/d/Y"));
     $exportData = \str_getcsv($returnResult, "\r\n");
     $num = \count($exportData);
     for ($i = 1; $i < $num; $i++) {
         $transactionExportArray = \str_getcsv($exportData[$i], "|");
         if (\count($transactionExportArray) > 1 && isset($mechantIdList[(int) $transactionExportArray[2]])) {
             $transaction = array();
             $merchantId = (int) $transactionExportArray[2];
             $transaction['merchantId'] = $merchantId;
             $dateString = str_replace(array(" AM", " PM"), "", $transactionExportArray[3]);
             $transactionDate = \DateTime::createFromFormat("m/d/Y H:i:s", $dateString);
             $transaction['date'] = $transactionDate->format("yyyy-MM-dd HH:mm:ss");
             $transaction['unique_id'] = (int) $transactionExportArray[0];
             if ($transactionExportArray[1] != null) {
                 $transaction['custom_id'] = $transactionExportArray[1];
             }
             if ($transactionExportArray[9] != null) {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if ($transactionExportArray[8] != 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[4]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[5]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #18
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $diff = $dStartDate->diff($dEndDate)->days;
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $auxDate = clone $dStartDate;
     for ($i = 0; $i <= $diff; $i++) {
         $totalAuxTransactions = array();
         $transactionList = $this->getSales($auxDate->format("Y-m-d"), 0, $this->_pageSize);
         if ($transactionList->total > 0) {
             $iteration = self::calculeIterationNumber($transactionList->total, $this->_pageSize);
             $totalAuxTransactions = \array_merge($totalAuxTransactions, $transactionList->saleItems->saleItem);
             for ($j = 1; $j < $iteration; $j++) {
                 $transactionList = $this->getSales($auxDate->format("Y-m-d"), $j, $this->_pageSize);
                 $totalAuxTransactions = \array_merge($totalAuxTransactions, $transactionList->saleItems->saleItem);
                 unset($transactionList);
                 \gc_collect_cycles();
             }
         }
         $leadList = $this->_apiClient->getLeads($auxDate->format("Y-m-d"), 'trackingDate', null, null, null, 0, $this->_pageSize);
         if ($leadList->total > 0) {
             $iteration = self::calculeIterationNumber($leadList->total, $this->_pageSize);
             $totalAuxTransactions = \array_merge($totalAuxTransactions, $leadList->leadItems->leadItem);
             for ($j = 1; $j < $iteration; $j++) {
                 $leadList = $this->_apiClient->getLeads($auxDate->format("Y-m-d"), 'trackingDate', null, null, null, $j, $this->_pageSize);
                 $totalAuxTransactions = \array_merge($totalAuxTransactions, $leadList->leadItems->leadItem);
                 unset($leadList);
                 \gc_collect_cycles();
             }
         }
         foreach ($totalAuxTransactions as $transaction) {
             if ($merchantList == null || isset($merchantIdList[$transaction->program->id])) {
                 $obj = array();
                 $obj['currency'] = $transaction->currency;
                 if ($transaction->reviewState == 'confirmed') {
                     $obj['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if ($transaction->reviewState == 'open' || $transaction->reviewState == 'approved') {
                         $obj['status'] = \Oara\Utilities::STATUS_PENDING;
                     } else {
                         if ($transaction->reviewState == 'rejected') {
                             $obj['status'] = \Oara\Utilities::STATUS_DECLINED;
                         }
                     }
                 }
                 if (!isset($transaction->amount) || $transaction->amount == 0) {
                     $obj['amount'] = $transaction->commission;
                 } else {
                     $obj['amount'] = $transaction->amount;
                 }
                 if (isset($transaction->gpps) && $transaction->gpps != null) {
                     foreach ($transaction->gpps->gpp as $gpp) {
                         if ($gpp->id == "zpar0") {
                             if (\strlen($gpp->_) > 150) {
                                 $gpp->_ = \substr($gpp->_, 0, 150);
                             }
                             $obj['custom_id'] = $gpp->_;
                         }
                     }
                 }
                 if (isset($transaction->trackingCategory->_) && $transaction->trackingCategory->_ != null) {
                     $obj['title'] = $transaction->trackingCategory->_;
                 }
                 $obj['unique_id'] = $transaction->id;
                 $obj['commission'] = $transaction->commission;
                 $dateString = \explode(".", $transaction->trackingDate);
                 $dateString = \explode("+", $dateString[0]);
                 $transactionDate = \DateTime::createFromFormat("Y-m-d\\TH:i:s", $dateString[0]);
                 $obj["date"] = $transactionDate->format("Y-m-d H:i:s");
                 $obj['merchantId'] = $transaction->program->id;
                 $obj['approved'] = $transaction->reviewState == 'approved' ? true : false;
                 $totalTransactions[] = $obj;
             }
         }
         unset($totalAuxTransactions);
         \gc_collect_cycles();
         $interval = new \DateInterval('P1D');
         $auxDate->add($interval);
     }
     return $totalTransactions;
 }
Пример #19
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $options = array('registrationDateFrom' => $dStartDate->format('Y-m-d'), 'registrationDateTo' => $dEndDate->add(new \DateInterval('P1D'))->format('Y-m-d'));
     $affiliateSitesList = $this->_apiClient->getAffiliateSites();
     foreach ($affiliateSitesList as $affiliateSite) {
         foreach ($this->_apiClient->getConversionTransactions($affiliateSite->ID, $options) as $transaction) {
             if ($merchantList == null || isset($merchantIdList[(int) $transaction->campaign->ID])) {
                 $object = array();
                 $object['unique_id'] = $transaction->ID;
                 $object['merchantId'] = $transaction->campaign->ID;
                 $transactionDate = new \DateTime($transaction->registrationDate);
                 $object['date'] = $transactionDate->format("Y-m-d H:i:s");
                 if ($transaction->reference != null) {
                     $object['custom_id'] = $transaction->reference;
                 }
                 if ($transaction->transactionStatus == 'accepted') {
                     $object['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if ($transaction->transactionStatus == 'pending') {
                         $object['status'] = \Oara\Utilities::STATUS_PENDING;
                     } else {
                         if ($transaction->transactionStatus == 'rejected') {
                             $object['status'] = \Oara\Utilities::STATUS_DECLINED;
                         }
                     }
                 }
                 $object['amount'] = \Oara\Utilities::parseDouble($transaction->orderAmount);
                 $object['commission'] = \Oara\Utilities::parseDouble($transaction->commission);
                 $totalTransactions[] = $object;
             }
         }
     }
     return $totalTransactions;
 }
Пример #20
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $rowIndex = 0;
     $rowCount = 0;
     $apiURL = "http://{$this->_domain}/affiliates/api/5/reports.asmx/Conversions?api_key={$this->_apiPassword}&affiliate_id={$this->_user}&start_date=" . \urlencode($dStartDate->format("Y-m-d H:i:s")) . "&end_date=" . \urlencode($dEndDate->format("Y-m-d H:i:s")) . "&offer_id=0&start_at_row={$rowIndex}&row_limit={$rowCount}";
     $response = self::call($apiURL);
     if (isset($response["conversions"]["conversion"])) {
         foreach ($response["conversions"]["conversion"] as $transactionApi) {
             $transaction = array();
             $merchantId = (int) $transactionApi["offer_id"];
             if (isset($merchantIdList[$merchantId])) {
                 $transaction['merchantId'] = $merchantId;
                 $transactionDate = new \DateTime($transactionApi["conversion_date"]);
                 $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
                 if (!isset($transactionApi["order_id"])) {
                     $transaction['unique_id'] = $transactionApi["conversion_id"];
                 } else {
                     $transaction['unique_id'] = $transactionApi["order_id"];
                 }
                 if (\count($transactionApi["subid_1"]) > 0) {
                     $transaction['custom_id'] = $transactionApi["subid_1"];
                 }
                 if ($transactionApi["disposition"] == "Approved") {
                     $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if ($transactionApi["disposition"] == "Pending" || $transactionApi["disposition"] == null) {
                         $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                     } else {
                         if ($transactionApi["disposition"] == "Rejected") {
                             $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                         }
                     }
                 }
                 $transaction['amount'] = $transactionApi["price"];
                 $transaction['commission'] = $transactionApi["price"];
                 $totalTransactions[] = $transaction;
             }
         }
     }
     return $totalTransactions;
 }
Пример #21
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $affiliate_id = $this->_id;
     $auth_key = $this->_apikey;
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $strUrl = "https://classic." . $this->_domain . '/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->format("Y-m-d H:i:s"));
     $strUrl .= "&date_end=" . \urlencode($dEndDate->format("Y-m-d H:i:s"));
     $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 && isset($merchantIdList[(int) $transactionExportArray[17]])) {
             $transaction = array();
             $merchantId = (int) $transactionExportArray[17];
             $transaction['merchantId'] = $merchantId;
             $transactionDate = \DateTime::createFromFormat("m-d-Y H:i:s", $transactionExportArray[11]);
             if (!$transactionDate) {
                 $transactionDate = \DateTime::createFromFormat("Y-m-d H:i:s", $transactionExportArray[11]);
             }
             $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
             $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($transactionExportArray[6]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[7]);
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #22
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $transactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     foreach ($this->_publisherList as $publisherId => $publisherName) {
         $page = 0;
         $import = true;
         while ($import) {
             $offset = $page * 300;
             $url = "https://{$this->_pass}@itunes-api.performancehorizon.com/reporting/report_publisher/publisher/{$publisherId}/conversion.json?";
             $url .= "status=approved|mixed|pending|rejected";
             $url .= "&start_date=" . \urlencode($dStartDate->format("Y-m-d H:i"));
             $url .= "&end_date=" . \urlencode($dEndDate->format("Y-m-d H:i"));
             $url .= "&offset=" . $offset;
             $result = \file_get_contents($url);
             $conversionList = \json_decode($result, true);
             foreach ($conversionList["conversions"] as $conversion) {
                 $conversion = $conversion["conversion_data"];
                 $conversion["campaign_id"] = \str_replace("l", "", $conversion["campaign_id"]);
                 if (isset($merchantIdList[$conversion["campaign_id"]])) {
                     $transaction = array();
                     $transaction['unique_id'] = $conversion["conversion_id"];
                     $transaction['merchantId'] = $conversion["campaign_id"];
                     $transaction['date'] = $conversion["conversion_time"];
                     if ($conversion["publisher_reference"] != null) {
                         $transaction['custom_id'] = $conversion["publisher_reference"];
                     }
                     if ($conversion["conversion_value"]["conversion_status"] == 'approved') {
                         $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                     } else {
                         if ($conversion["conversion_value"]["conversion_status"] == 'pending' || $conversion["conversion_value"]["conversion_status"] == 'mixed') {
                             $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                         } else {
                             if ($conversion["conversion_value"]["conversion_status"] == 'rejected') {
                                 $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                             }
                         }
                     }
                     $transaction['amount'] = $conversion["conversion_value"]["value"];
                     $transaction['currency'] = $conversion["currency"];
                     $transaction['commission'] = $conversion["conversion_value"]["publisher_commission"];
                     $transactions[] = $transaction;
                 }
             }
             if ((int) $conversionList["count"] < $offset) {
                 $import = false;
             }
             $page++;
         }
     }
     return $transactions;
 }
Пример #23
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $urls = array();
     $valuesFormExport = array(new \Oara\Curl\Parameter('apikey', $this->_apiPassword), new \Oara\Curl\Parameter('Format', 'CSV'), new \Oara\Curl\Parameter('FieldSeparator', 'comma'), new \Oara\Curl\Parameter('Fields', 'MerchantID,OrderDate,NetworkOrderID,CustomTrackingID,OrderValue,AffiliateCommission,TransactionType,PaidtoAffiliate,DatePaidToAffiliate'), new \Oara\Curl\Parameter('AffiliateID', $this->_user), new \Oara\Curl\Parameter('DateFormat', 'DD/MM/YYYY+HH:MN:SS'), new \Oara\Curl\Parameter('PendingSales', 'YES'), new \Oara\Curl\Parameter('ValidatedSales', 'YES'), new \Oara\Curl\Parameter('VoidSales', 'YES'), new \Oara\Curl\Parameter('GetNewSales', 'YES'));
     $valuesFormExport[] = new \Oara\Curl\Parameter('DateFrom', $dStartDate->format("Y-m-d"));
     $valuesFormExport[] = new \Oara\Curl\Parameter('DateTo', $dEndDate->format("Y-m-d"));
     $urls[] = new \Oara\Curl\Request('http://affiliate.paidonresults.com/api/transactions?', $valuesFormExport);
     $exportReport = $this->_client->get($urls);
     $exportData = \str_getcsv($exportReport[0], "\r\n");
     $num = \count($exportData);
     for ($i = 1; $i < $num; $i++) {
         $exportData[$i] = preg_replace("/\n/", "", $exportData[$i]);
         $transactionExportArray = \str_getcsv($exportData[$i], ",");
         if (isset($merchantIdList[$transactionExportArray[0]])) {
             $transaction = array();
             $transaction['merchantId'] = $transactionExportArray[0];
             $transactionDate = \DateTime::createFromFormat("d/m/Y H:i:s", $transactionExportArray[1]);
             $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
             $transaction['unique_id'] = $transactionExportArray[2];
             if ($transactionExportArray[3] != null) {
                 $transaction['custom_id'] = $transactionExportArray[3];
             }
             $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[4]);
             $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[5]);
             if ($transactionExportArray[6] == 'VALIDATED') {
                 $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             } else {
                 if ($transactionExportArray[6] == 'PENDING') {
                     $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                 } else {
                     if ($transactionExportArray[6] == 'VOID') {
                         $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                     }
                 }
             }
             $totalTransactions[] = $transaction;
         }
     }
     return $totalTransactions;
 }
Пример #24
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $merchantMap = \Oara\Utilities::getMerchantNameMapFromMerchantList($merchantList);
     $valuesFromExport = array();
     $valuesFromExport[] = new \Oara\Curl\Parameter('api_key', $this->_apiPassword);
     $valuesFromExport[] = new \Oara\Curl\Parameter('start_date', $dStartDate->format("Y-m-d"));
     $valuesFromExport[] = new \Oara\Curl\Parameter('end_date', $dEndDate->format("Y-m-d"));
     $valuesFromExport[] = new \Oara\Curl\Parameter('filter[Stat.offer_id]', \implode(",", $merchantIdList));
     $urls = array();
     $urls[] = new \Oara\Curl\Request('http://p.wowtrk.com/stats/lead_report.xml?', $valuesFromExport);
     $exportReport = $this->_exportClient->get($urls);
     $exportData = self::loadXml($exportReport[0]);
     foreach ($exportData->stats->stat as $transaction) {
         if (isset($merchantMap[(string) $transaction->offer])) {
             $obj = array();
             $obj['merchantId'] = $merchantMap[(string) $transaction->offer];
             $obj['date'] = (string) $transaction->date_time;
             $obj['status'] = \Oara\Utilities::STATUS_CONFIRMED;
             $obj['customId'] = (string) $transaction->sub_id;
             $obj['amount'] = \Oara\Utilities::parseDouble((string) $transaction->payout);
             $obj['commission'] = \Oara\Utilities::parseDouble((string) $transaction->payout);
             if ($obj['amount'] != 0 || $obj['commission'] != 0) {
                 $totalTransactions[] = $obj;
             }
         }
     }
     return $totalTransactions;
 }
Пример #25
0
 /**
  * @param $restUrl
  * @param $merchantList
  * @return array
  */
 private function getTransactionsXml($restUrl, $merchantList)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $response = self::apiCall($restUrl);
     $xml = \simplexml_load_string($response, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     if (isset($xml->commissions->commission)) {
         foreach ($xml->commissions->commission as $singleTransaction) {
             if (\count($this->_sitesAllowed) == 0 || \in_array((int) self::findAttribute($singleTransaction, 'website-id'), $this->_sitesAllowed)) {
                 if (isset($merchantIdList[(int) self::findAttribute($singleTransaction, 'cid')])) {
                     $type = self::findAttribute($singleTransaction, 'action-type');
                     if (!$this->_includeBonus && $type == "bonus") {
                         continue;
                     }
                     $transaction = array();
                     $transaction['unique_id'] = self::findAttribute($singleTransaction, 'original-action-id');
                     $transaction['action'] = self::findAttribute($singleTransaction, 'action-type');
                     $transaction['merchantId'] = self::findAttribute($singleTransaction, 'cid');
                     $transactionDate = \DateTime::createFromFormat("Y-m-d\\TH:i:s", \substr(self::findAttribute($singleTransaction, 'event-date'), 0, 19));
                     $transaction['date'] = $transactionDate->format("Y-m-d H:i:s");
                     if (self::findAttribute($singleTransaction, 'sid') != null) {
                         $transaction['custom_id'] = self::findAttribute($singleTransaction, 'sid');
                     }
                     $transaction['amount'] = \Oara\Utilities::parseDouble(self::findAttribute($singleTransaction, 'sale-amount'));
                     $transaction['commission'] = \Oara\Utilities::parseDouble(self::findAttribute($singleTransaction, 'commission-amount'));
                     if (self::findAttribute($singleTransaction, 'action-status') == 'locked' || self::findAttribute($singleTransaction, 'action-status') == 'closed') {
                         $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                     } else {
                         if (self::findAttribute($singleTransaction, 'action-status') == 'extended' || self::findAttribute($singleTransaction, 'action-status') == 'new') {
                             $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                         } else {
                             if (self::findAttribute($singleTransaction, 'action-status') == 'corrected') {
                                 $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                             }
                         }
                     }
                     if ($transaction['commission'] == 0) {
                         $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                     }
                     if ($transaction['amount'] < 0 || $transaction['commission'] < 0) {
                         $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                         $transaction['amount'] = \abs($transaction['amount']);
                         $transaction['commission'] = \abs($transaction['commission']);
                     }
                     $totalTransactions[] = $transaction;
                 }
             }
         }
     }
     return $totalTransactions;
 }
Пример #26
0
 /**
  * @param null $merchantList
  * @param \DateTime|null $dStartDate
  * @param \DateTime|null $dEndDate
  * @return array
  * @throws Exception
  */
 public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null)
 {
     $totalTransactions = array();
     $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList);
     $valuesFormExport = array();
     $valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]);
     $valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apipassword"]);
     $valuesFormExport[] = new \Oara\Curl\Parameter('champs', 'idprogramme,date,etat,argann,montant,gains,monnaie,idsite');
     $valuesFormExport[] = new \Oara\Curl\Parameter('debut', $dStartDate->format("Y-m-d"));
     $valuesFormExport[] = new \Oara\Curl\Parameter('fin', $dEndDate->format("Y-m-d"));
     $urls = array();
     $urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport);
     $exportReport = $this->_client->get($urls);
     //sales
     $exportData = str_getcsv($exportReport[0], "\n");
     $num = count($exportData);
     for ($i = 1; $i < $num; $i++) {
         $transactionExportArray = str_getcsv($exportData[$i], ";");
         if (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[7], $this->_sitesAllowed)) {
             if (isset($merchantIdList[$transactionExportArray[0]])) {
                 $transaction = array();
                 $transaction['merchantId'] = $transactionExportArray[0];
                 \preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $transactionExportArray[1], $date);
                 $transaction['date'] = $date[0];
                 if ($transactionExportArray[3] != null) {
                     $transaction['custom_id'] = $transactionExportArray[3];
                 }
                 if (\strstr($transactionExportArray[2], 'v')) {
                     $transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED;
                 } else {
                     if (\strstr($transactionExportArray[2], 'r')) {
                         $transaction['status'] = \Oara\Utilities::STATUS_DECLINED;
                     } else {
                         if (\strstr($transactionExportArray[2], 'a')) {
                             $transaction['status'] = \Oara\Utilities::STATUS_PENDING;
                         } else {
                             throw new \Exception("Status not found");
                         }
                     }
                 }
                 $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[5]);
                 $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[5]);
                 $totalTransactions[] = $transaction;
             }
         }
     }
     return $totalTransactions;
 }