From 7d3c543a83af71d1badccb1e1fe1129aee216ad3 Mon Sep 17 00:00:00 2001 From: Lucas C Date: Fri, 25 Aug 2023 14:56:05 +0200 Subject: [PATCH 1/6] RGOPS-4466: GatewayService, callback response and marker --- src/GatewayChecksum.php | 6 +++--- src/GatewayService.php | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index b112fa3..8afd986 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 = "c5a4aa418b6b2abcfc3025e04d438198"; + public static $versionNo = "P8.14"; ////////////////////////////////////////////////////////////////////// // @@ -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.14m"; } } } diff --git a/src/GatewayService.php b/src/GatewayService.php index 442efa5..a2f3b46 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. @@ -720,6 +725,14 @@ function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse // 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 // @@ -859,6 +872,13 @@ function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse // Execute the operation. // $results = curl_exec($handle);// Execute the operation +// +// Apply optional curlResponseCallback with 3 parameters (curlHeader, httpResults, sdkRequest) if available +// + if (is_callable($this->curlResponseCallback)) { + $results = call_user_func($this->curlResponseCallback, $handle, $results, $request); + } + if (!($results)) {// Did it fail? $errorCode = curl_errno($handle);// Get the error code if (!$errorCode) { From 0744df8b53b7cd362aa104fe60299f274864328c Mon Sep 17 00:00:00 2001 From: Lucas C Date: Fri, 25 Aug 2023 14:58:11 +0200 Subject: [PATCH 2/6] RGOPS-4466: GatewayChecksum, version --- src/GatewayChecksum.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index 8afd986..e643e08 100644 --- a/src/GatewayChecksum.php +++ b/src/GatewayChecksum.php @@ -12,7 +12,7 @@ class GatewayChecksum { public static $checksum = ""; public static $baseChecksum = "c5a4aa418b6b2abcfc3025e04d438198"; - public static $versionNo = "P8.14"; + 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.14m"; + GatewayChecksum::$versionNo = "P8.12m"; } } } From 62fa4a5d0b398056a01a6575d8cd62612b9e9ac1 Mon Sep 17 00:00:00 2001 From: Lucas C Date: Fri, 25 Aug 2023 17:38:31 +0200 Subject: [PATCH 3/6] RGOPS-4466: GatewayService, address code review --- src/GatewayChecksum.php | 2 +- src/GatewayService.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index e643e08..645993d 100644 --- a/src/GatewayChecksum.php +++ b/src/GatewayChecksum.php @@ -11,7 +11,7 @@ class GatewayChecksum { public static $checksum = ""; - public static $baseChecksum = "c5a4aa418b6b2abcfc3025e04d438198"; + public static $baseChecksum = "d11c0594f5549e01ca00319739e67909"; public static $versionNo = "P8.12"; ////////////////////////////////////////////////////////////////////// diff --git a/src/GatewayService.php b/src/GatewayService.php index a2f3b46..ba84a8c 100644 --- a/src/GatewayService.php +++ b/src/GatewayService.php @@ -431,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->curlCallback = $callback; + } + + ////////////////////////////////////////////////////////////////////// // // PerformTransaction() - Perform the transaction outlined @@ -873,7 +887,7 @@ function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse // $results = curl_exec($handle);// Execute the operation // -// Apply optional curlResponseCallback with 3 parameters (curlHeader, httpResults, sdkRequest) if available +// Apply optional curlResponseCallback with 3 parameters (curlHandler, httpResults, sdkRequest) if available // if (is_callable($this->curlResponseCallback)) { $results = call_user_func($this->curlResponseCallback, $handle, $results, $request); From c65cff5a98ca82a3112470a4530a7be74b22f9eb Mon Sep 17 00:00:00 2001 From: Lucas C Date: Fri, 25 Aug 2023 17:43:46 +0200 Subject: [PATCH 4/6] RGOPS-4466: GatewayService, address code review --- src/GatewayChecksum.php | 2 +- src/GatewayService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index 645993d..920490b 100644 --- a/src/GatewayChecksum.php +++ b/src/GatewayChecksum.php @@ -11,7 +11,7 @@ class GatewayChecksum { public static $checksum = ""; - public static $baseChecksum = "d11c0594f5549e01ca00319739e67909"; + public static $baseChecksum = "10a769977e4207744ca61dbea8eb1fd2"; public static $versionNo = "P8.12"; ////////////////////////////////////////////////////////////////////// diff --git a/src/GatewayService.php b/src/GatewayService.php index ba84a8c..b7cb6c1 100644 --- a/src/GatewayService.php +++ b/src/GatewayService.php @@ -441,7 +441,7 @@ function SetCurlCallback($callback) // function SetCurlResponseCallback($callback) { - $this->curlCallback = $callback; + $this->curlResponseCallback = $callback; } From f47c2acf8da42cc89edab78e558870a1e0f64801 Mon Sep 17 00:00:00 2001 From: Lucas C Date: Thu, 28 Sep 2023 14:02:46 -0400 Subject: [PATCH 5/6] RGOPS-4466: GatewayService, separate header and body of response sent to callback --- src/GatewayChecksum.php | 2 +- src/GatewayService.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index 920490b..3ead66b 100644 --- a/src/GatewayChecksum.php +++ b/src/GatewayChecksum.php @@ -11,7 +11,7 @@ class GatewayChecksum { public static $checksum = ""; - public static $baseChecksum = "10a769977e4207744ca61dbea8eb1fd2"; + public static $baseChecksum = "b29f11124ebbea1ce94da009dc40aad8"; public static $versionNo = "P8.12"; ////////////////////////////////////////////////////////////////////// diff --git a/src/GatewayService.php b/src/GatewayService.php index b7cb6c1..39eb4d3 100644 --- a/src/GatewayService.php +++ b/src/GatewayService.php @@ -886,11 +886,15 @@ function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse // Execute the operation. // $results = curl_exec($handle);// Execute the operation + + $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); + $results_header = substr($results, 0, $header_size); + $results_body = substr($results, $header_size); // -// Apply optional curlResponseCallback with 3 parameters (curlHandler, httpResults, sdkRequest) if available +// Apply optional curlResponseCallback if available // if (is_callable($this->curlResponseCallback)) { - $results = call_user_func($this->curlResponseCallback, $handle, $results, $request); + call_user_func($this->curlResponseCallback, $handle, $request, $response, $results_header, $results_body); } if (!($results)) {// Did it fail? From 52f34332e9c86a6412d529d0a5b2d54e9ef42173 Mon Sep 17 00:00:00 2001 From: Lucas C Date: Thu, 28 Sep 2023 16:47:21 -0400 Subject: [PATCH 6/6] RGOPS-4466: GatewayService, different implementation of header capture --- src/GatewayChecksum.php | 2 +- src/GatewayService.php | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/GatewayChecksum.php b/src/GatewayChecksum.php index 3ead66b..585dd59 100644 --- a/src/GatewayChecksum.php +++ b/src/GatewayChecksum.php @@ -11,7 +11,7 @@ class GatewayChecksum { public static $checksum = ""; - public static $baseChecksum = "b29f11124ebbea1ce94da009dc40aad8"; + public static $baseChecksum = "a25b794b7ab3ce7af7ef7d73c3aad975"; public static $versionNo = "P8.12"; ////////////////////////////////////////////////////////////////////// diff --git a/src/GatewayService.php b/src/GatewayService.php index 39eb4d3..263b95b 100644 --- a/src/GatewayService.php +++ b/src/GatewayService.php @@ -734,6 +734,8 @@ 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. @@ -880,6 +882,20 @@ 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; + } + ); } // @@ -887,14 +903,11 @@ function PerformCURLTransaction($host, GatewayRequest $request, GatewayResponse // $results = curl_exec($handle);// Execute the operation - $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); - $results_header = substr($results, 0, $header_size); - $results_body = substr($results, $header_size); // // Apply optional curlResponseCallback if available // if (is_callable($this->curlResponseCallback)) { - call_user_func($this->curlResponseCallback, $handle, $request, $response, $results_header, $results_body); + call_user_func($this->curlResponseCallback, $handle, $request, $response, $results_headers, $results); } if (!($results)) {// Did it fail?