diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index b112fa3..585dd59 100644 --- a/src/GatewayChecksum.php +++ b/src/GatewayChecksum.php @@ -11,8 +11,8 @@ class GatewayChecksum { public static $checksum = ""; - public static $baseChecksum = "8f5eedd22eee69780abd2eb4d7ca7f1f"; - public static $versionNo = "P8.11"; + public static $baseChecksum = "a25b794b7ab3ce7af7ef7d73c3aad975"; + public static $versionNo = "P8.12"; ////////////////////////////////////////////////////////////////////// // @@ -30,7 +30,7 @@ static function SetVersion() md5_file($dirName . "/GatewayCodes.php"); GatewayChecksum::$checksum = md5($baseString); if (GatewayChecksum::$checksum != GatewayChecksum::$baseChecksum) { - GatewayChecksum::$versionNo = "P8.11m"; + GatewayChecksum::$versionNo = "P8.12m"; } } } diff --git a/src/GatewayService.php b/src/GatewayService.php index 442efa5..263b95b 100644 --- a/src/GatewayService.php +++ b/src/GatewayService.php @@ -61,6 +61,11 @@ class GatewayService // private $curlCallback; +// +// Optional curl response callback function after curl_exec() +// + private $curlResponseCallback; + ////////////////////////////////////////////////////////////////////// // // GatewayService() - Constructor for class. @@ -426,6 +431,20 @@ function SetCurlCallback($callback) $this->curlCallback = $callback; } +////////////////////////////////////////////////////////////////////// +// +// SetCurlResponseCallback() - Set optional curl response callback +// that will allow to manipulate +// with CURL instance after curl_exec(). +// +////////////////////////////////////////////////////////////////////// +// + function SetCurlResponseCallback($callback) + { + $this->curlResponseCallback = $callback; + } + + ////////////////////////////////////////////////////////////////////// // // PerformTransaction() - Perform the transaction outlined @@ -715,11 +734,21 @@ function PerformConfirmation(GatewayRequest $request, GatewayResponse $response) // function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse $response) { + + $results_headers = []; // // Reset the response object and turn the request into // a string that can be transmitted. // $response->Reset();// Clear old contents +// +// indicate in version that a user function has been used +// + if (is_callable($this->curlCallback) || is_callable($this->curlResponseCallback)) { + $request->Set(GatewayRequest::VERSION_INDICATOR(), + GatewayChecksum::$versionNo. "c"); + } + $requestBytes = $request->ToXMLString();// Change to XML request // @@ -853,12 +882,34 @@ function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse // if (is_callable($this->curlCallback)) { $handle = call_user_func($this->curlCallback, $handle); + + curl_setopt($handle, CURLOPT_HEADERFUNCTION, + function($curl, $header) use (&$results_headers) + { + $len = strlen($header); + $header = explode(':', $header, 2); + if (count($header) < 2) // ignore invalid headers + return $len; + + $results_headers[strtolower(trim($header[0]))][] = trim($header[1]); + + return $len; + } + ); } // // Execute the operation. // $results = curl_exec($handle);// Execute the operation + +// +// Apply optional curlResponseCallback if available +// + if (is_callable($this->curlResponseCallback)) { + call_user_func($this->curlResponseCallback, $handle, $request, $response, $results_headers, $results); + } + if (!($results)) {// Did it fail? $errorCode = curl_errno($handle);// Get the error code if (!$errorCode) {