/** * Do the main API request. * All API request to eWAY should call this function with appropriate parameters, after set all necessary data. * * @param string $action can be one of POST, GET, DELETE or PUT * @param string $method * @return Eway_Rapid31_Model_Response */ protected function _doRapidAPI($action, $method = 'POST') { $url = $this->_config->getRapidAPIUrl($action); $mode = $this->_config->isSandbox() ? '(Sandbox)' : '(Live)'; $this->_log('>>>>> START REQUEST ' . $mode . ' (' . $method . ') ' . ' : ' . $url); $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); curl_setopt($ch, CURLOPT_USERPWD, $this->_config->getBasicAuthenticationHeader()); switch ($method) { case 'POST': curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->jsonSerialize()); $this->_logPostJSON(); break; case 'GET': case 'DELETE': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); break; case 'PUT': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->jsonSerialize()); $this->_logPostJSON(); break; } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_config->isEnableSSLVerification()); $result = curl_exec($ch); $this->_log('<<<<< RESPONSE:'); $response = Mage::getModel('ewayrapid/response'); if (curl_errno($ch) != CURLE_OK) { $response->isSuccess(false); $response->setMessage(Mage::helper('ewayrapid')->__("There is an error in making API request: %s", curl_error($ch))); $this->_log("There is an error in making API request: %s", curl_error($ch)); } else { $info = curl_getinfo($ch); if ($info['http_code'] == 401 || $info['http_code'] == 404) { $response->isSuccess(false); $response->setMessage(Mage::helper('ewayrapid')->__("Please check the API Key and Password %s", $mode)); $this->_log('Access denied. HTTP_CODE = ' . $info['http_code']); } else { $response->isSuccess(true); $response->decodeJSON($result); if ($this->_config->isDebug()) { $this->_log('SUCCESS. Response body:'); $this->_log(print_r(json_decode($result, true), true)); } } curl_close($ch); } $this->_log('===== END REQUEST.'); return $response; }
private function __getTransaction($transId) { $ewayConfig = new Eway_Rapid31_Model_Config(); $url = 'https://api.sandbox.ewaypayments.com/Transaction/' . $transId; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader()); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification()); $result = curl_exec($ch); return $result; }