示例#1
0
 public function PerformCURLTransaction($host, $request, $response)
 {
     //
     //	Reset the response object and turn the request into
     //	a string that can be transmitted.
     //
     $response->Reset();
     // Clear old contents
     $requestBytes = $request->ToXMLString();
     // Change to XML request
     //
     //	Gather override attibutes used for the connection URL.
     //
     $urlServlet = $request->Get("gatewayServlet");
     $urlProtocol = $request->Get("gatewayProtocol");
     $urlPortNo = $request->Get("gatewayPortNo");
     //
     //	If the parameters were not set in the request,
     //	use the system defaults.
     //
     if ($urlServlet == NULL) {
         $urlServlet = $this->rocketGateServlet;
     }
     if ($urlProtocol == NULL) {
         $urlProtocol = $this->rocketGateProtocol;
     }
     if ($urlPortNo == NULL) {
         $urlPortNo = $this->rocketGatePortNo;
     }
     //
     //	Build the URL for the gateway service.
     //
     $url = $urlProtocol . "://" . $host . ":" . $urlPortNo . "/" . $urlServlet;
     // Add servlet path
     //
     //	Gather the override timeout values that will be used
     //	for the connection.
     //
     $connectTimeout = $request->Get("gatewayConnectTimeout");
     $readTimeout = $request->Get("gatewayReadTimeout");
     //
     //	Use default values if the parameters were not set.
     //
     if ($connectTimeout == NULL) {
         // No connect timeout specified?
         $connectTimeout = $this->rocketGateConnectTimeout;
     }
     if ($readTimeout == NULL) {
         $readTimeout = $this->rocketGateReadTimeout;
     }
     //
     //	Create a handle that can be used for the URL operation.
     //
     if (!($handle = curl_init())) {
         // Failed to initialize?
         $response->Set(GatewayResponse::EXCEPTION(), "curl_init() error");
         $response->SetResults(GatewayCodes__RESPONSE_REQUEST_ERROR, GatewayCodes__REASON_INVALID_URL);
         return GatewayCodes__RESPONSE_REQUEST_ERROR;
     }
     //
     //	Set timeout values used in the operation.
     //
     curl_setopt($handle, CURLOPT_NOSIGNAL, TRUE);
     curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
     curl_setopt($handle, CURLOPT_TIMEOUT, $readTimeout);
     //
     //	Setup verification for SSL connections.
     //
     curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, FALSE);
     //
     //	Setup the call to the URL.
     //
     curl_setopt($handle, CURLOPT_POST, TRUE);
     curl_setopt($handle, CURLOPT_POSTFIELDS, $requestBytes);
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($handle, CURLOPT_URL, $url);
     curl_setopt($handle, CURLOPT_FAILONERROR, TRUE);
     //////////////////////////////////////////////////////////////////////
     //
     //	04-30-2013	darcy
     //
     //	Updated user agent.
     //
     //	12-20-2011	darcy
     //
     //	Updated user agent.
     //
     //	08-25-2011	darcy
     //
     //	Updated user agent.
     //
     //	05-31-2009	darcy
     //
     //	Updated the user agent.
     //
     //	04-27-2009	darcy
     //
     //	Set the user-agent.
     //
     //    curl_setopt($handle, CURLOPT_USERAGENT, "RG PHP Client 2.0");
     //    curl_setopt($handle, CURLOPT_USERAGENT, "RG PHP Client 2.1");
     //
     curl_setopt($handle, CURLOPT_USERAGENT, "RG PHP Client 3.0");
     //
     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////
     //
     // 2/21/2010 Jason. Set content-type.
     //
     curl_setopt($handle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
     //////////////////////////////////////////////////////////////////////
     //
     //	Execute the operation.
     //
     $results = curl_exec($handle);
     // Execute the operation
     if (!$results) {
         // Did it fail?
         $errorCode = curl_errno($handle);
         // Get the error code
         $errorString = curl_error($handle);
         // Get the error text
         curl_close($handle);
         // Done with handle
         //
         //	Translate the CURL error code into a Gateway code.
         //
         switch ($errorCode) {
             // Classify error code
             case CURLE_SSL_CONNECT_ERROR:
                 // Connection failures
             // Connection failures
             case CURLE_COULDNT_CONNECT:
                 $internalCode = GatewayCodes__REASON_UNABLE_TO_CONNECT;
                 break;
                 // Done with request
             // Done with request
             case CURLE_SEND_ERROR:
                 // Failed sending data
                 $internalCode = GatewayCodes__REASON_REQUEST_XMIT_ERROR;
                 break;
                 // Done with request
             // Done with request
             case CURLE_OPERATION_TIMEOUTED:
                 // Time-out reached
                 $internalCode = GatewayCodes__REASON_RESPONSE_READ_TIMEOUT;
                 break;
                 // Done with request
             // Done with request
             case CURLE_RECV_ERROR:
                 // Failed reading data
             // Failed reading data
             case CURLE_READ_ERROR:
             default:
                 $internalCode = GatewayCodes__REASON_RESPONSE_READ_ERROR;
         }
         //
         //	If the operation failed, return an error code.
         //
         if (strlen($errorString) != 0) {
             // Have an error?
             $response->Set(GatewayResponse::EXCEPTION(), $errorString);
         }
         $response->SetResults(GatewayCodes__RESPONSE_SYSTEM_ERROR, $internalCode);
         return GatewayCodes__RESPONSE_SYSTEM_ERROR;
     }
     //
     //	Parse the returned message into the response
     //	object.
     //
     curl_close($handle);
     // Done with handle
     $response->SetFromXML($results);
     // Set response
     return $response->Get(GatewayResponse::RESPONSE_CODE());
 }
示例#2
0
 public function SetFromXML($xmlString)
 {
     //
     //	Create a parser for the XML.
     //
     $parser = xml_parser_create('');
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     //
     //	Parse the input string.  If there is an error,
     //	note it in the response.
     //
     if (xml_parse_into_struct($parser, $xmlString, $vals, $index) == 0) {
         $this->Set(GatewayResponse::EXCEPTION(), xml_error_string(xml_get_error_code($parser)));
         $this->SetResults(GatewayCodes__RESPONSE_SYSTEM_ERROR, GatewayCodes__REASON_XML_ERROR);
         xml_parser_free($parser);
         // Release the parser
         return;
         // And we're done
     }
     //
     //	Loop over the items in the XML document and
     //	save them in the response.
     //
     foreach ($vals as $val) {
         // Loop over elements
         if (isset($val['value'])) {
             // Is value set?
             $this->Set($val['tag'], $val['value']);
         }
         // Save in parameters
     }
     //
     //	Release the parser and quit.
     //
     xml_parser_free($parser);
     // Release the parser
 }