Exemplo n.º 1
0
 /**
  * (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)
 {
     $nowDate = new Zend_Date();
     $dStartDate = clone $dStartDate;
     $dStartDate->setLocale('en');
     $dStartDate->setHour("00");
     $dStartDate->setMinute("00");
     $dStartDate->setSecond("00");
     $dEndDate = clone $dEndDate;
     $dEndDate->setLocale('en');
     $dEndDate->setHour("23");
     $dEndDate->setMinute("59");
     $dEndDate->setSecond("59");
     $valuesFromExport = Oara_Utilities::cloneArray($this->_exportTransactionParameters);
     $valuesFromExport[] = new Oara_Curl_Parameter('startDate', $dStartDate->toString("dd-MMM-yyyy"));
     $valuesFromExport[] = new Oara_Curl_Parameter('endDate', $dEndDate->toString("dd-MMM-yyyy"));
     $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 Zend_Date(self::findAttribute($transaction, 'TransactionDate'), "yyyy-MM-ddTHH:mm:ss");
                 if (in_array((int) self::findAttribute($transaction, 'ProgrammeID'), $merchantList) && $date->compare($dStartDate) >= 0 && $date->compare($dEndDate) <= 0) {
                     $obj = array();
                     $obj['merchantId'] = self::findAttribute($transaction, 'ProgrammeID');
                     $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss");
                     if (self::findAttribute($transaction, 'TrackingReference') != null) {
                         $obj['custom_id'] = self::findAttribute($transaction, 'TrackingReference');
                     }
                     $obj['unique_id'] = self::findAttribute($transaction, 'TransactionID');
                     if ($i == 0) {
                         if (Oara_Utilities::numberOfDaysBetweenTwoDates($date, $nowDate) > 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'] = self::findAttribute($transaction, 'SaleValue');
                     $obj['commission'] = self::findAttribute($transaction, 'SaleCommission');
                     $leadCommission = self::findAttribute($transaction, 'LeadCommission');
                     if ($leadCommission != 0) {
                         $obj['commission'] += $leadCommission;
                     }
                     $transactions[] = $obj;
                 }
             }
         }
     }
     return $transactions;
 }