コード例 #1
0
 public function testStrGetCSV()
 {
     $string = 'header1,header2' . "\n";
     $string .= 'val1,val2' . "\n";
     $array = CybersourceHelper::str_getcsv($string);
     $array = $array[0];
     $this->assertArrayHasKey('header1', $array);
     $this->assertArrayHasKey('header2', $array);
     $this->assertEquals('val1', $array['header1']);
     $this->assertEquals('val2', $array['header2']);
 }
コード例 #2
0
 /**
  * @param $report_name
  * @param $date
  * @return array
  * @throws Exceptions\CybersourceException
  */
 private function sendReportRequest($report_name, $date)
 {
     $merchant_id = $this->configs->getMerchantId();
     $reportsArray = $this->configs->getReports();
     $endpoint = $reportsArray['endpoint'];
     $username = $reportsArray['username'];
     $password = $reportsArray['password'];
     if (!$date instanceof \DateTime) {
         $date = new \DateTime($date);
     }
     // get the right host and substitute in our username and password for http basic authentication
     $url = 'https://' . $username . ':' . $password . '@' . $endpoint . '/DownloadReport/' . $date->format('Y/m/d/') . $merchant_id . '/' . $report_name . '.csv';
     $result = file_get_contents($url);
     if ($result === false) {
         // this would be a lot easier if we could just have an error handler that throws exceptions, but here it is...
         $error = error_get_last();
         if (isset($error['message'])) {
             // try to parse out the specific message, minus the function and crap
             $message = $error['message'];
             preg_match('/failed to open stream: (.*)/', $message, $matches);
             if (isset($matches[1])) {
                 $message = $matches[1];
             }
             if (strpos($message, 'The report requested cannot be found on this server') !== false) {
                 throw new CybersourceException($message, 400);
                 // code 400? it's an HTTP 400 error. get it?
             } else {
                 // we don't know exactly what type of error, throw a generic error
                 throw new CybersourceException($message);
             }
         }
         // something happened, but we dont' know what - die!
         throw new CybersourceException();
     }
     // parse out the results
     // but first, remove the first line - it's a header
     $result = substr($result, strpos($result, "\n") + strlen("\n"));
     $records = CybersourceHelper::str_getcsv($result);
     return $records;
 }