/**
  * returns API response array()
  */
 public static function restApi($action = null, $data = null)
 {
     try {
         $hipay = new HiPay_Tpp();
         HipayLogger::addLog($hipay->l('API call initiated', 'hipay'), HipayLogger::APICALL, 'Action : ' . $action . ' - Data : ' . Tools::jsonEncode($data));
         if ($action == null) {
             Tools::redirect('index.php?controller=order&xer=6');
         }
         if ($data == null) {
             Tools::redirect('index.php?controller=order&xer=7');
         }
         define('API_ENDPOINT', HipayClass::getAPIURL());
         define('API_USERNAME', HipayClass::getAPIUsername());
         define('API_PASSWORD', HipayClass::getAPIPassword());
         $credentials = API_USERNAME . ':' . API_PASSWORD;
         $resource = API_ENDPOINT . $action;
         // create a new cURL resource
         $curl = curl_init();
         // set appropriate options
         $options = array(CURLOPT_URL => $resource, CURLOPT_USERPWD => $credentials, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false);
         foreach ($options as $option => $value) {
             curl_setopt($curl, $option, $value);
         }
         $result = curl_exec($curl);
         $status = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
         $response = Tools::jsonDecode($result);
         // execute the given cURL session
         if (false === $result) {
             $errorCurl = curl_error($curl);
             throw new Exception('Curl error: ' . $errorCurl);
         }
         if (floor($status / 100) != 2) {
             throw new Exception('Hipay message: ' . $response->message, $response->code);
         }
         curl_close($curl);
         HipayLogger::addLog($hipay->l('API call success', 'hipay'), HipayLogger::APICALL, 'Appel vers API avec success : ' . Tools::jsonEncode($response));
         return $response;
     } catch (Exception $e) {
         HipayLogger::addLog($hipay->l('API call error', 'hipay'), HipayLogger::ERROR, $e->getMessage());
         return $e;
     }
 }
 /**
  * returns API response array()
  */
 public static function restMaintenanceApi($transaction_reference = null, $data = null)
 {
     try {
         $hipay = new HiPay_Tpp();
         HipayLogger::addLog($hipay->l('API Refund call initiated', 'hipay'), HipayLogger::APICALL, 'Transaction_reference : ' . $transaction_reference . ' - Data : ' . Tools::jsonEncode($data));
         if ($transaction_reference == null) {
             return 'Error - No transaction reference';
         }
         if ($data == null) {
             return 'Error - No data';
         }
         define('API_ENDPOINT', HipayClass::getAPIURL());
         define('API_USERNAME', HipayClass::getAPIUsername());
         define('API_PASSWORD', HipayClass::getAPIPassword());
         $credentials = API_USERNAME . ':' . API_PASSWORD;
         $resource = API_ENDPOINT . 'maintenance/transaction/' . $transaction_reference;
         // create a new cURL resource
         $curl = curl_init();
         // set appropriate options
         $options = array(CURLOPT_URL => $resource, CURLOPT_USERPWD => $credentials, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => false, CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false);
         foreach ($options as $option => $value) {
             curl_setopt($curl, $option, $value);
         }
         $result = curl_exec($curl);
         $status = (int) curl_getinfo($curl, CURLINFO_HTTP_CODE);
         $response = Tools::jsonDecode($result);
         // execute the given cURL session
         if (false === $result) {
             throw new Exception(curl_error($curl));
         }
         if (floor($status / 100) != 2) {
             throw new Exception('Err Msg : ' . $response->message . ', Err Desc : ' . $response->description . ', Err Code : ' . $response->code);
         }
         curl_close($curl);
         HipayLogger::addLog($hipay->l('API call success', 'hipay'), HipayLogger::APICALL, 'Appel vers API avec success : ' . mysql_real_escape_string(Tools::jsonEncode($response)));
         return $response;
     } catch (Exception $e) {
         HipayLogger::addLog($hipay->l('API call error', 'hipay'), HipayLogger::ERROR, mysql_real_escape_string($e->getMessage()));
         return false;
     }
 }