/** * Parse the response from the server * * @param array * @return object */ private function _parse_response($response) { $details = (object) array(); if (is_object($response)) { if ($response->code == '1') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { $details->reason = $response->message; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } } elseif (strstr($response, '<response>')) { $response = Payment_Utility::parse_xml($response); $response = Payment_Utility::arrayize_object($response); $details->gateway_response = $response; if ($response['code'] == '1') { return Payment_Response::instance()->gateway_response('Success', $this->_lib_method . '_success', $details); } else { $details->reason = $response['message']; return Payment_Response::instance()->gateway_response('Failure', $this->_lib_method . '_gateway_failure', $details); } } else { $results = explode('&', urldecode($response)); foreach ($results as $result) { list($key, $value) = explode('=', $result); $gateway_response[$key] = $value; } $details->gateway_response = $gateway_response; $details->timestamp = isset($gateway_response['trnDate']) ? $gateway_response['trnDate'] : gmdate('c'); if (isset($gateway_response['trnApproved']) && $gateway_response['trnApproved'] == '1') { $details->identifier = isset($gateway_response['trnId']) ? $gateway_response['trnId'] : null; if (isset($gateway_response['rbAccountId'])) { $details->identifier = $gateway_response['rbAccountId']; } return Payment_Response::instance()->gateway_response('success', $this->_lib_method . '_success', $details); } else { $details->reason = isset($gateway_response['messageText']) ? $gateway_response['messageText'] : null; return Payment_Response::instance()->gateway_response('failure', $this->_lib_method . '_gateway_failure', $details); } } }
/** * Makes the actual request to the gateway * * @param string This is the API endpoint currently being used * @param string The data to be passed to the API * @param string A specific content type to define for cURL request * @return object response object */ public static function curl_request($query_string, $payload = NULL, $content_type = NULL, $custom_headers = NULL) { $headers = is_null($custom_headers) ? array() : $custom_headers; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $query_string); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, 0); if (is_null($payload)) { $request = curl_exec($curl); if ($request[0] == '<') { return Payment_Utility::parse_xml($request); } else { return $request; } } else { if (is_null($content_type)) { $xml = TRUE; $headers[] = "Content-Type: text/xml"; } else { if (strpos($content_type, 'xml') !== FALSE) { $xml = TRUE; } $headers[] = "Content-Type: {$content_type}"; } curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $payload); $request = curl_exec($curl); if (isset($xml) && $xml === TRUE) { return Payment_Utility::parse_xml($request); } else { return $request; } } }