From 114ee347d07fa7853a6b7bfda1cb2ee5ada76818 Mon Sep 17 00:00:00 2001 From: Tim Everts Date: Thu, 28 Jun 2018 12:45:44 +0800 Subject: [PATCH 1/2] Added the `Timeout` property. The `Timeout` property defines the maximum number of seconds processing request is allowed to take (default is 60 seconds). --- securepay.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/securepay.php b/securepay.php index b75f4e9..e0e3587 100755 --- a/securepay.php +++ b/securepay.php @@ -302,6 +302,15 @@ class SecurePay { */ public $RepeatTrigger; + /** + * Maximum number of seconds a processing request is allowed to take + * The default is 60 seconds + * + * @access public + * @var integer + */ + public $Timeout; + // End of Variable Declarations }}} // General use functionality {{{ @@ -318,6 +327,7 @@ function __construct($AccountName = null, $AccountPassword = null, $TestMode = F $this->ChargeCurrency = 'USD'; // Default currency to USD $this->Repeat = SECUREPAY_REPEAT_NEVER; $this->RepeatTrigger = TRUE; + $this->Timeout = 60; } /** @@ -828,6 +838,7 @@ function _Dispatch($xml) { curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // Return the HTTP response from the curl_exec function + curl_setopt($curl, CURLOPT_TIMEOUT, $this->Timeout); if (defined('CURL_SSLVERSION_TLSv1_2')) { //Always use TLS v1.2 if its available. curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); @@ -860,7 +871,7 @@ function _ComposeEcho() { $message .= "\t\n"; $message .= "\t\t{$this->LastMessageId}\n"; $message .= "\t\t$timestamp\n"; - $message .= "\t\t60\n"; + $message .= "\t\t{$this->Timeout}\n"; $message .= "\t\txml-4.2\n"; $message .= "\t\n"; $message .= "\t\n"; @@ -888,7 +899,7 @@ function _ComposeTrigger() { $message .= "\t\n"; $message .= "\t\t{$this->LastMessageId}\n"; $message .= "\t\t$timestamp\n"; - $message .= "\t\t60\n"; + $message .= "\t\t{$this->Timeout}\n"; $message .= "\t\tspxml-3.0\n"; $message .= "\t\n"; $message .= "\t\n"; @@ -927,7 +938,7 @@ function _ComposePayment() { $message .= "\t\n"; $message .= "\t\t{$this->LastMessageId}\n"; $message .= "\t\t$timestamp\n"; - $message .= "\t\t60\n"; + $message .= "\t\t{$this->Timeout}\n"; $message .= "\t\tspxml-3.0\n"; $message .= "\t\n"; $message .= "\t\n"; @@ -967,7 +978,7 @@ function _ComposePayment() { $message .= "\t\n"; $message .= "\t\t{$this->LastMessageId}\n"; $message .= "\t\t$timestamp\n"; - $message .= "\t\t60\n"; + $message .= "\t\t{$this->Timeout}\n"; $message .= "\t\txml-4.2\n"; $message .= "\t\n"; $message .= "\t\n"; @@ -1020,7 +1031,7 @@ function _ComposeRefund() { $message .= "\t\n"; $message .= "\t\t{$this->LastMessageId}\n"; $message .= "\t\t$timestamp\n"; - $message .= "\t\t60\n"; + $message .= "\t\t{$this->Timeout}\n"; $message .= "\t\txml-4.2\n"; $message .= "\t\n"; $message .= "\t\n"; From 1c908dcd20823f246d1b837e2922ef250eca46ba Mon Sep 17 00:00:00 2001 From: Tim Everts Date: Thu, 28 Jun 2018 13:03:04 +0800 Subject: [PATCH 2/2] An empty XML response from processing is now treated as a processor time out. --- securepay.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/securepay.php b/securepay.php index e0e3587..a51b8ae 100755 --- a/securepay.php +++ b/securepay.php @@ -391,6 +391,12 @@ function Process($ChargeAmount = null, $ChargeCurrency = null, $Cc = null, $Expi $this->Cvv = str_pad($this->Cvv, 3, '0', STR_PAD_LEFT); $this->RequestXml = $this->_ComposePayment(); $this->ResponseXml = $this->_Dispatch($this->RequestXml); + + // If no XML response, assume processing timed out. + if ((false === $this->ResponseXml) || (false == is_string($this->ResponseXml))) { + return $this->_TranslateServerCode(512); + } + $this->ResponseTree = simplexml_load_string($this->ResponseXml); $this->StatusCode = $this->ResponseTree->Status->statusCode; $this->StatusCodeText = $this->ResponseTree->Status->statusDescription; @@ -438,6 +444,12 @@ function Refund($TransactionId = null,$OrderId = null,$ChargeAmount=null){ $this->RequestXml = $this->_ComposeRefund(); $this->ResponseXml = $this->_Dispatch($this->RequestXml); + + // If no XML response, assume processing timed out. + if ((false === $this->ResponseXml) || (false == is_string($this->ResponseXml))) { + return $this->_TranslateServerCode(512); + } + $this->ResponseTree = simplexml_load_string($this->ResponseXml); $this->StatusCode = $this->ResponseTree->Status->statusCode; $this->StatusCodeText = $this->ResponseTree->Status->statusDescription; @@ -469,6 +481,12 @@ function Trigger($OrderId = null) { if ($OrderId) $this->OrderId = $OrderId; $this->RequestXml = $this->_ComposeTrigger(); $this->ResponseXml = $this->_Dispatch($this->RequestXml); + + // If no XML response, assume processing timed out. + if ((false === $this->ResponseXml) || (false == is_string($this->ResponseXml))) { + return $this->_TranslateServerCode(512); + } + $this->ResponseTree = simplexml_load_string($this->ResponseXml); $server_code = $this->_TranslateServerCode($this->ResponseTree->Status->statusCode); if (isset($this->ResponseTree->Payment->TxnList->Txn->responseCode)) { // Has a response code @@ -485,6 +503,14 @@ function Trigger($OrderId = null) { function TestConnection() { $this->RequestXml = $this->_ComposeEcho(); $this->ResponseXml = $this->_Dispatch($this->RequestXml); + + // If no XML response, assume processing timed out. + if ((false === $this->ResponseXml) || (false == is_string($this->ResponseXml))) { + $this->_TranslateServerCode(512); + + return false; + } + $this->ResponseTree = simplexml_load_string($this->ResponseXml); return ($this->_TranslateServerCode($this->ResponseTree->Status->statusCode) == SECUREPAY_STATUS_OK); }