Skip to content

Commit

Permalink
Edit pullConfig function.
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardCardGate committed Feb 11, 2020
1 parent 408c336 commit e4164dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 38 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cardgate/cardgate-clientlib-php",
"description": "CardGate API client library for PHP",
"homepage": "https://github.com/cardgate/cardgate-clientlib-php",
"version": "1.1.12",
"version": "1.1.13",
"license": "MIT",
"authors": [
{
Expand Down
40 changes: 3 additions & 37 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class Client {
/**
* Client version.
*/
const CLIENT_VERSION = "1.1.12";
const CLIENT_VERSION = "1.1.13";

/**
* Url to use for production.
Expand Down Expand Up @@ -382,46 +382,12 @@ public function getLastResult() {
* @access public
* @api
*/
static public function pullConfig( $sToken_, $bTestmode_ = FALSE ) {
public function pullConfig( $sToken_ ) {
if ( ! is_string( $sToken_ ) ) {
throw new Exception( 'Client.Token.Invalid', 'invalid token for settings pull: ' . $sToken_ );
}

$sResource = "pullconfig/{$sToken_}/";
$sUrl = ( $bTestmode_ ? self::URL_STAGING : self::URL_PRODUCTION ) . $sResource;

$rCh = curl_init();
curl_setopt( $rCh, CURLOPT_URL, $sUrl );
curl_setopt( $rCh, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $rCh, CURLOPT_TIMEOUT, 60 );
curl_setopt( $rCh, CURLOPT_HEADER, FALSE );
curl_setopt( $rCh, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json'
] );
if ( $bTestmode_ ) {
curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 0 );
} else {
curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, TRUE ); // verify SSL peer
curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 2 ); // check for valid common name and verify host
}

if ( FALSE == ( $sResults = curl_exec( $rCh ) ) ) {
$sError = curl_error( $rCh );
curl_close( $rCh );
throw new Exception( 'Client.Request.Curl.Error', $sError );
} else {
curl_close( $rCh );
}
if ( NULL === ( $aResults = json_decode( $sResults, TRUE ) ) ) {
throw new Exception( 'Client.Request.JSON.Invalid', 'remote gave invalid JSON: ' . $sResults );
}
if ( isset( $aResults['error'] ) ) {
throw new Exception( 'Client.Request.Remote.' . $aResults['error']['code'], $aResults['error']['message'] );
}

return $aResults;
return $this->doRequest($sResource);
}

/**
Expand Down

0 comments on commit e4164dd

Please sign in to comment.