From 8747f4584e4b5955d8b2242b124bbaebc1697c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Naczy=C5=84ski?= Date: Mon, 15 Oct 2018 17:29:57 +0100 Subject: [PATCH] TradeDoubler paymentTransactions() Update paymentTransactions to return full transactions not just IDs --- Oara/Network/Publisher/TradeDoubler.php | 50 +++++++++++++++++++------ 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/Oara/Network/Publisher/TradeDoubler.php b/Oara/Network/Publisher/TradeDoubler.php index 1dc9e40b..83f70a55 100755 --- a/Oara/Network/Publisher/TradeDoubler.php +++ b/Oara/Network/Publisher/TradeDoubler.php @@ -641,10 +641,8 @@ public function paymentTransactions($paymentId) $exportReport = $this->_client->get($urls); - $doc = new \DOMDocument(); - @$doc->loadHTML(\Oara\Utilities::DOMinnerHTML($exportReport[0])); - $xpath = new \DOMXPath($doc); - $results = $xpath->query('//a'); + $dom = new \Zend\Dom\Query($exportReport[0]); + $results = $dom->execute('//a'); $urls = array(); foreach ($results as $result) { @@ -656,15 +654,45 @@ public function paymentTransactions($paymentId) $exportReportData = \str_getcsv($exportReport, "\r\n"); $num = \count($exportReportData); for ($i = 2; $i < $num - 1; $i++) { - $transactionArray = \str_getcsv($exportReportData[$i], ";"); - if ($transactionArray[8] != '') { - $transactionList[] = $transactionArray[8]; - } else - if ($transactionArray[7] != '') { - $transactionList[] = $transactionArray[7]; + $transactionExportArray = \str_getcsv($exportReportData[$i], ";"); + if (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[2], $this->_sitesAllowed)) { + $transaction = Array(); + $transaction['merchantId'] = $transactionExportArray[2]; + $transactionDate = self::toDate($transactionExportArray[6]); + $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[13] != '') { + $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[13]); } else { - throw new \Exception("No Identifier"); + $transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[14]); } + + $transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[15]); + $transactionList[] = $transaction; + } } }