Skip to content

Commit f85d9c7

Browse files
author
Richard
committed
Merge remote-tracking branch 'origin'
2 parents 9e8d5dc + fef1582 commit f85d9c7

49 files changed

Lines changed: 1555 additions & 86 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ final class Address extends Entity {
104104

105105
/**
106106
* Sets the gender.
107-
* @param string $sGender The gender to set.
107+
* @param string $sGender_ The gender to set.
108108
* @return Address Returns this, makes the call chainable.
109109
* @throws Exception
110110
* @access public

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class Cart {
4747
* @param string $iPrice_ The price of the cart item.
4848
* @param string $sLink_ An optional link to the product.
4949
* @return Item Returns the item that was added.
50-
* @throws Exception
50+
* @throws Exception|\ReflectionException
5151
* @access public
5252
* @api
5353
*/

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Client.php

Lines changed: 118 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class Client {
3535
/**
3636
* Client version.
3737
*/
38-
const CLIENT_VERSION = "1.1.7";
38+
const CLIENT_VERSION = "1.1.10";
3939

4040
/**
4141
* Url to use for production.
@@ -117,6 +117,25 @@ final class Client {
117117
*/
118118
private $_oMethods = NULL;
119119

120+
/**
121+
* Debug level. 0 = None, 1 = Include result in errors, 2 = Verbose CURL calls.
122+
* @var int
123+
* @access private
124+
*/
125+
const DEBUG_NONE = 0;
126+
const DEBUG_RESULTS = 1;
127+
const DEBUG_VERBOSE = 2;
128+
129+
private $_iDebugLevel = 0;
130+
131+
/**
132+
* Last request and result for debugging.
133+
* @var string
134+
* @access private
135+
*/
136+
private $_sLastRequest = NULL;
137+
private $_sLastResult = NULL;
138+
120139
/**
121140
* The constructor.
122141
* @param int $iMerchantId_ The merchant id for the client.
@@ -130,6 +149,22 @@ function __construct( $iMerchantId_, $sKey_, $bTestmode_ = FALSE ) {
130149
$this->setMerchantId( $iMerchantId_ )->setKey( $sKey_ )->setTestmode( $bTestmode_ );
131150
}
132151

152+
/**
153+
* Prevent leaking info in dumps.
154+
* @ignore
155+
*/
156+
public function __debugInfo() {
157+
return [
158+
'Version' => $this->_oVersion,
159+
'Testmode' => $this->_bTestmode,
160+
'DebugLevel' => $this->_iDebugLevel,
161+
'iMerchantId' => $this->_iMerchantId,
162+
'API_URL' => $this->getUrl(),
163+
'LastRequest' => $this->_sLastRequest,
164+
'LastResult' => $this->_sLastResult
165+
];
166+
}
167+
133168
/**
134169
* Toggle testmode.
135170
* @param bool $bTestmode_ Enable or disable testmode for this client.
@@ -156,6 +191,49 @@ public function getTestmode() {
156191
return $this->_bTestmode;
157192
}
158193

194+
/**
195+
* Set debug level.
196+
* @param int $iDebugLevel_ Level: 0 = None, 1 = Include request/resule in errors, 2 = Verbose cURL calls.
197+
* @return $this
198+
* @access public
199+
* @api
200+
*/
201+
public function setDebugLevel( $iLevel_ ) {
202+
$this->_iDebugLevel = $iLevel_;
203+
return $this;
204+
}
205+
206+
/**
207+
* Get current debug level setting.
208+
* @return int The current debug level.
209+
* @access public
210+
* @api
211+
*/
212+
public function getDebugLevel() {
213+
return $this->_iDebugLevel;
214+
}
215+
216+
/**
217+
* Get debug information according to debug level.
218+
* @param bool $bStartWithNewLine_ Optional flag to indicate the info should start with a new-line.
219+
* @param bool $bAddResult_ Optional flag to indicate the result should be included too.
220+
* @return string Debug info or empty if level = 0.
221+
* @access public
222+
* @api
223+
*/
224+
public function getDebugInfo( $bStartWithNewLine_ = TRUE, $bAddResult_ = TRUE ) {
225+
if ( $this->getDebugLevel() > self::DEBUG_NONE ) {
226+
$sResult = ( $bStartWithNewLine_ ? PHP_EOL : '' );
227+
$sResult .= 'Request: ' . $this->getLastRequest();
228+
if ( $bAddResult_ ) {
229+
$sResult .= PHP_EOL . 'Result: ' . $this->getLastResult();
230+
}
231+
return $sResult;
232+
} else {
233+
return '';
234+
}
235+
}
236+
159237
/**
160238
* Configure the client object with a merchant id.
161239
* @param int $iMerchantId_ Merchant id to set.
@@ -277,6 +355,26 @@ public function getUrl() {
277355
}
278356
}
279357

358+
/**
359+
* Get the last request sent to the API.
360+
* @return string The request string.
361+
* @access public
362+
* @api
363+
*/
364+
public function getLastRequest() {
365+
return (string) $this->_sLastRequest;
366+
}
367+
368+
/**
369+
* Get the last result from an API call.
370+
* @return string The result string.
371+
* @access public
372+
* @api
373+
*/
374+
public function getLastResult() {
375+
return (string) $this->_sLastResult;
376+
}
377+
280378
/**
281379
* Pull the config from the API using a token provided by the site setup button in the backoffice.
282380
* @return array Returns an array with settings.
@@ -409,10 +507,6 @@ public function doRequest( $sResource_, $aData_ = NULL, $sHttpMethod_ = 'POST' )
409507
if ( is_array( $aData_ ) ) {
410508
$aData_['ip'] = $this->getIp();
411509
$aData_['language_id'] = $this->getLanguage();
412-
if ( 'GET' == $sHttpMethod_ ) {
413-
$sDelim = ( FALSE === strchr( $sUrl, '?' ) ? '?' : '&' );
414-
$sUrl .= $sDelim . http_build_query( $aData_ );
415-
}
416510
} elseif ( is_null( $aData_ ) ) {
417511
$aData_ = [ 'ip' => $this->getIp(), 'language_id' => $this->getLanguage() ];
418512
} else {
@@ -424,7 +518,6 @@ public function doRequest( $sResource_, $aData_ = NULL, $sHttpMethod_ = 'POST' )
424518
}
425519

426520
$rCh = curl_init();
427-
curl_setopt( $rCh, CURLOPT_URL, $sUrl );
428521
curl_setopt( $rCh, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
429522
curl_setopt( $rCh, CURLOPT_USERPWD, $this->_iMerchantId . ':' . $this->_sKey );
430523
curl_setopt( $rCh, CURLOPT_RETURNTRANSFER, 1 );
@@ -443,22 +536,36 @@ public function doRequest( $sResource_, $aData_ = NULL, $sHttpMethod_ = 'POST' )
443536
}
444537

445538
if ( 'POST' == $sHttpMethod_ ) {
539+
$this->_sLastRequest = json_encode( $aData_ );
540+
curl_setopt( $rCh, CURLOPT_URL, $sUrl );
446541
curl_setopt( $rCh, CURLOPT_POST, TRUE );
447-
curl_setopt( $rCh, CURLOPT_POSTFIELDS, json_encode( $aData_ ) );
542+
curl_setopt( $rCh, CURLOPT_POSTFIELDS, $this->_sLastRequest );
543+
$this->_sLastRequest = "[POST $sUrl] " . $this->_sLastRequest;
544+
} else {
545+
$this->_sLastRequest = $sUrl
546+
. ( FALSE === strchr( $sUrl, '?' ) ? '?' : '&' )
547+
. http_build_query( $aData_ )
548+
;
549+
curl_setopt( $rCh, CURLOPT_URL, $this->_sLastRequest );
448550
}
449551

450-
if ( FALSE == ( $sResults = curl_exec( $rCh ) ) ) {
552+
if ( self::DEBUG_VERBOSE == $this->_iDebugLevel ) {
553+
curl_setopt( $rCh, CURLOPT_VERBOSE, TRUE );
554+
}
555+
556+
$this->_sLastResult = curl_exec( $rCh );
557+
if ( FALSE == $this->_sLastResult ) {
451558
$sError = curl_error( $rCh );
452559
curl_close( $rCh );
453560
throw new Exception( 'Client.Request.Curl.Error', $sError );
454561
} else {
455562
curl_close( $rCh );
456563
}
457-
if ( NULL === ( $aResults = json_decode( $sResults, TRUE ) ) ) {
458-
throw new Exception( 'Client.Request.JSON.Invalid', 'remote gave invalid JSON: ' . $sResults );
564+
if ( NULL === ( $aResults = json_decode( $this->_sLastResult, TRUE ) ) ) {
565+
throw new Exception( 'Client.Request.JSON.Invalid', 'remote gave invalid JSON: ' . $this->_sLastResult );
459566
}
460567
if ( isset( $aResults['error'] ) ) {
461-
throw new Exception( 'Client.Request.Remote.' . $aResults['error']['code'], $aResults['error']['message'] );
568+
throw new Exception( 'Client.Request.Remote.' . $aResults['error']['code'], $aResults['error']['message'] . $this->getDebugInfo() );
462569
}
463570

464571
return $aResults;

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Entity.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class Entity {
4242
* @ignore
4343
* @internal To make the data in an Entity available through magic functions (setName, getAmount, unsetName,
4444
* hasCart) populate the _aFields property below. To make autocompletion work in Zend, use the @method phpdoc
45-
* directove like this: @method null setId( int $iId ).
45+
* directive like this: @method null setId( int $iId ).
4646
* Example: [ 'MerchantId' => 'merchant_id', 'Name' => 'name' ]
4747
*/
4848
static protected $_aFields = [];
@@ -52,15 +52,16 @@ abstract class Entity {
5252
* @param string $sPrefix_ Optionally prefix all the data entries.
5353
* @return array Returns an array with the data in the entity.
5454
*/
55-
public function getData( $sPrefix_ = FALSE ) {
56-
$aResult = [];
57-
foreach( $this->_aData as $sKey => $mValue ) {
58-
if ( is_string( $sPrefix_ ) ) {
59-
$sKey = $sPrefix_ . $sKey;
55+
public function getData( $sPrefix_ = NULL ) {
56+
if ( is_string( $sPrefix_ ) ) {
57+
$aResult = [];
58+
foreach( $this->_aData as $sKey => $mValue ) {
59+
$aResult[$sPrefix_ . $sKey] = $mValue;
6060
}
61-
$aResult[$sKey] = $mValue;
61+
return $aResult;
62+
} else {
63+
return $this->_aData;
6264
}
63-
return $aResult;
6465
}
6566

6667
/**

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Item.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ final class Item extends Entity {
134134
* @param int $iType_ The cart item type.
135135
* @param string $sSKU_ The SKU of the cart item.
136136
* @param string $sName_ The name of the cart item (productname).
137+
* @param $iQuantity_
137138
* @param int $iPrice_ The price of the cart item.
138139
* @param string $sLink_ An optional link to the product.
139-
* @throws Exception
140+
* @throws Exception|\ReflectionException
140141
* @access public
141142
* @api
142143
*/
@@ -184,7 +185,6 @@ function setVat( $fVat_ ) {
184185
* Sets the vat included flag.
185186
* @param bool $bVatIncluded_ The vat included flag to set.
186187
* @return Item Returns this, makes the call chainable.
187-
* @throws Exception
188188
* @access public
189189
* @api
190190
*/

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Method.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ final class Method {
112112
*/
113113
const BILLINK = 'billink';
114114

115+
/**
116+
* IDEALQR
117+
*/
118+
const IDEALQR = 'idealqr';
119+
120+
/**
121+
* Paysafecash
122+
*/
123+
const PAYSAFECASH = 'paysafecash';
124+
125+
/**
126+
* SofortPay
127+
*/
128+
const SOFORTPAY = 'sofortpay';
129+
130+
/**
131+
* Gift Card
132+
*/
133+
const GIFTCARD = 'giftcard';
134+
115135
/**
116136
* The client associated with this payment method.
117137
* @var Client
@@ -137,17 +157,19 @@ final class Method {
137157
* The constructor.
138158
* @param Client $oClient_ The client associated with this transaction.
139159
* @param string $sId_ The payment method identifier to create a method instance for.
140-
* @throws Exception
160+
* @throws Exception|\ReflectionException
141161
* @access public
142162
* @api
163+
* @throws
143164
*/
144165
function __construct( Client $oClient_, $sId_, $sName_ ) {
166+
static $aValidMethods; // use static cache for this
167+
168+
if ( ! isset( $aValidMethods ) ) {
169+
$aValidMethods = ( new \ReflectionClass( '\cardgate\api\Method' ) )->getConstants();
170+
}
145171
$this->_oClient = $oClient_;
146-
try {
147-
if ( ! in_array( $sId_, ( new \ReflectionClass( '\cardgate\api\Method' ) )->getConstants() ) ) {
148-
throw new Exception('Method.PaymentMethod.Invalid', 'invalid payment method: ' . $sId_);
149-
}
150-
} catch ( \ReflectionException $oException_ ) {
172+
if ( ! in_array( $sId_, $aValidMethods ) ) {
151173
throw new Exception('Method.PaymentMethod.Invalid', 'invalid payment method: ' . $sId_);
152174
}
153175
$this->setId( $sId_ );
@@ -220,10 +242,23 @@ public function getName() {
220242
* @api
221243
*/
222244
public function getIssuers() {
223-
$sResource = $this->_sId . '/issuers/';
224-
225-
$aResult = $this->_oClient->doRequest( $sResource, NULL, 'GET' );
226245

246+
if ( TRUE ) {
247+
// Use the static version which is automatically updated every day
248+
$aResult = [
249+
'issuers' => $this->_oClient->doRequest(
250+
$this->_oClient->getTestMode()
251+
? '../../../cache/idealDirectoryCUROPayments-TEST.json'
252+
: '../../../cache/idealDirectoryCUROPayments.json'
253+
, NULL, 'GET'
254+
)
255+
];
256+
} else {
257+
// Retrieve using API call.
258+
// TODO: The response should be cached on the local system for 24 hours!
259+
$sResource = $this->_sId . '/issuers/';
260+
$aResult = $this->_oClient->doRequest( $sResource, NULL, 'GET' );
261+
}
227262
if ( empty( $aResult['issuers'] ) ) {
228263
throw new Exception( 'Method.Issuers.Invalid', 'invalid issuer data returned' );
229264
}

xtcommerce-cardgate-master/cardgate/classes/cardgate-clientlib-php/src/Subscription.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ final class Subscription extends Transaction {
104104
*/
105105
private $_sEndDate;
106106

107+
/**
108+
* The status of the subscription.
109+
* @var string
110+
* @access private
111+
*/
112+
private $_sStatus;
113+
107114
/**
108115
* The constructor.
109116
* @param Client $oClient_ The client associated with this subscription.
@@ -118,7 +125,11 @@ final class Subscription extends Transaction {
118125
*/
119126
function __construct( Client $oClient_, $iSiteId_, $iPeriod_, $sPeriodType_, $iPeriodAmount_, $sCurrency_ = 'EUR' ) {
120127
$this->_oClient = $oClient_;
121-
$this->setSiteId( $iSiteId_ )->setPeriod( $iPeriod_ )->setPeriodType( $sPeriodType_ )->setPeriodPrice( $iPeriodAmount_ )->setCurrency( $sCurrency_ );
128+
$this->setSiteId( $iSiteId_ )
129+
->setPeriod( $iPeriod_ )
130+
->setPeriodType( $sPeriodType_ )
131+
->setPeriodPrice( $iPeriodAmount_ )
132+
->setCurrency( $sCurrency_ );
122133
}
123134

124135
/**
@@ -450,7 +461,7 @@ public function register() {
450461
empty( $aResult )
451462
|| empty( $aResult['subscription'] )
452463
) {
453-
throw new Exception( 'Subscription.Request.Invalid', 'invalid payment data returned' );
464+
throw new Exception( 'Subscription.Request.Invalid', 'unexpected result: ' . $this->_oClient->getLastResult() . $this->_oClient->getDebugInfo( TRUE, FALSE ) );
454465
}
455466
$this->_sId = $aResult['subscription'];
456467
if (
@@ -491,7 +502,8 @@ public function changeStatus( $sStatus_ ) {
491502
$aResult = $this->_oClient->doRequest( $sResource, $aData, 'POST' );
492503

493504
if ( FALSE == $aResult['success'] ) {
494-
throw new Exception( 'Subscription.Request.Invalid', 'error changing status' );
505+
// oClient will have thrown an error if there was a proper error from the API, so this is weird!
506+
throw new Exception( 'Subscription.Request.Invalid', 'unexpected result: ' . $this->_oClient->getLastResult() . $this->_oClient->getDebugInfo( TRUE, FALSE ) );
495507
}
496508

497509
return TRUE;

0 commit comments

Comments
 (0)