Exemplo n.º 1
0
 /**
  *  It returns the transactions for a payment
  * @see Oara_Network::paymentTransactions()
  */
 public function paymentTransactions($paymentId, $merchantList, $startDate)
 {
     $paymentTransactionList = array();
     $paymentHistory = Oara_Utilities::registerBubbleSort($this->_paymentHistory);
     $paymentStartDate = new Zend_Date($startDate, "yyyy-MM-dd HH:mm:ss");
     $paymentEndDate = null;
     $enc = false;
     $i = 0;
     $payment = null;
     while (!$enc && $i < count($paymentHistory)) {
         $payment = $paymentHistory[$i];
         if ($payment['pid'] == $paymentId) {
             $enc = true;
             $paymentEndDate = new Zend_Date($payment['date'], "yyyy-MM-dd HH:mm:ss");
         }
         $i++;
     }
     if ($enc && $paymentStartDate->compare($paymentEndDate) <= 0) {
         $totalTransactions = array();
         $dateArray = Oara_Utilities::monthsOfDifference(new Zend_Date($startDate, "yyyy-MM-dd HH:mm:ss"), $paymentEndDate);
         for ($i = 0; $i < count($dateArray); $i++) {
             $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 = $paymentEndDate;
             }
             $monthEndDate->setHour(23);
             $monthEndDate->setMinute(59);
             $monthEndDate->setSecond(59);
             echo "\n importing from " . $monthStartDate->toString("dd-MM-yyyy HH:mm:ss") . " to " . $monthEndDate->toString("dd-MM-yyyy HH:mm:ss") . "\n";
             $urls = array();
             $valuesFormExport = Oara_Utilities::cloneArray($this->_exportTransactionParameters);
             $valuesFormExport[] = new Oara_Curl_Parameter('DateFrom', $monthStartDate->toString("yyyy-MM-dd"));
             $valuesFormExport[] = new Oara_Curl_Parameter('DateTo', $monthEndDate->toString("yyyy-MM-dd"));
             $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++) {
                 $transactionExportArray = str_getcsv($exportData[$i], ",");
                 $paid = $transactionExportArray[7] == "YES" ? true : false;
                 if (in_array($transactionExportArray[0], $merchantList) && $paid) {
                     $transactionDate = new Zend_Date($transactionExportArray[8], "dd/MM/yyyy HH:mm:ss");
                     echo $paymentEndDate->toString("yyyy-MM-dd") . "  " . $transactionDate->toString("yyyy-MM-dd") . "\n\n";
                     if ($paymentEndDate->toString("yyyy-MM-dd") == $transactionDate->toString("yyyy-MM-dd")) {
                         $paymentTransactionList[] = $transactionExportArray[2];
                     }
                 }
             }
         }
     }
     return $paymentTransactionList;
 }