Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/GatewayChecksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";

//////////////////////////////////////////////////////////////////////
//
Expand All @@ -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";
}
}
}
51 changes: 51 additions & 0 deletions src/GatewayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class GatewayService
//
private $curlCallback;

//
// Optional curl response callback function after curl_exec()
//
private $curlResponseCallback;

//////////////////////////////////////////////////////////////////////
//
// GatewayService() - Constructor for class.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

//
Expand Down Expand Up @@ -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) {
Expand Down