-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Pieters
committed
Jul 19, 2017
1 parent
cc2583e
commit af3e577
Showing
178 changed files
with
3,289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
class Pay_Api { | ||
|
||
const REQUEST_TYPE_POST = 1; | ||
const REQUEST_TYPE_GET = 0; | ||
|
||
protected $_apiUrl = 'https://rest-api.pay.nl'; | ||
protected $_version = 'v3'; | ||
protected $_controller = ''; | ||
protected $_action = ''; | ||
protected $_serviceId = ''; | ||
protected $_apiToken = ''; | ||
protected $_requestType = self::REQUEST_TYPE_POST; | ||
protected $_postData = array(); | ||
|
||
|
||
/** | ||
* Set the serviceid | ||
* The serviceid always starts with SL- and can be found on: https://admin.pay.nl/programs/programs | ||
* | ||
* @param string $serviceId | ||
*/ | ||
public function setServiceId($serviceId) { | ||
$this->_serviceId = $serviceId; | ||
} | ||
|
||
/** | ||
* Set the API token | ||
* The API token is used to identify your company. | ||
* The API token can be found on: https://admin.pay.nl/my_merchant on the bottom | ||
* | ||
* @param string $apiToken | ||
*/ | ||
public function setApiToken($apiToken) { | ||
$this->_apiToken = $apiToken; | ||
} | ||
|
||
protected function _getPostData() { | ||
|
||
return $this->_postData; | ||
} | ||
|
||
protected function _processResult($data) { | ||
return $data; | ||
} | ||
|
||
private function _getApiUrl() { | ||
if ($this->_version == '') { | ||
throw new Pay_Exception('version not set', 1); | ||
} | ||
if ($this->_controller == '') { | ||
throw new Pay_Exception('controller not set', 1); | ||
} | ||
if ($this->_action == '') { | ||
throw new Pay_Exception('action not set', 1); | ||
} | ||
|
||
return $this->_apiUrl . '/' . $this->_version . '/' . $this->_controller . '/' . $this->_action . '/json/'; | ||
} | ||
|
||
public function getPostData(){ | ||
return $this->_getPostData(); | ||
} | ||
public function doRequest() { | ||
if ($this->_getPostData()) { | ||
|
||
$url = $this->_getApiUrl(); | ||
$data = $this->_getPostData(); | ||
|
||
$strData = http_build_query($data); | ||
|
||
$apiUrl = $url; | ||
|
||
$ch = curl_init(); | ||
if ($this->_requestType == self::REQUEST_TYPE_GET) { | ||
$apiUrl .= '?' . $strData; | ||
} else { | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $strData); | ||
} | ||
|
||
|
||
curl_setopt($ch, CURLOPT_URL, $apiUrl); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
|
||
$result = curl_exec($ch); | ||
|
||
|
||
if ($result == false) { | ||
$error = curl_error($ch); | ||
throw new Pay_Api_Exception("Curl error: ".$error); | ||
} | ||
curl_close($ch); | ||
|
||
$arrResult = json_decode($result, true); | ||
|
||
if ($this->validateResult($arrResult)) { | ||
return $this->_processResult($arrResult); | ||
} | ||
} | ||
} | ||
|
||
protected function validateResult($arrResult) { | ||
if ($arrResult['request']['result'] == 1) { | ||
return true; | ||
} else { | ||
if(isset($arrResult['request']['errorId']) && isset($arrResult['request']['errorMessage']) ){ | ||
throw new Pay_Api_Exception($arrResult['request']['errorId'] . ' - ' . $arrResult['request']['errorMessage']); | ||
} elseif(isset($arrResult['error'])){ | ||
throw new Pay_Api_Exception($arrResult['error']); | ||
} else { | ||
throw new Pay_Api_Exception('Unexpected api result'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
class Pay_Api_Exception extends Pay_Exception{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
class Pay_Api_Getservice extends Pay_Api { | ||
|
||
protected $_version = 'v3'; | ||
protected $_controller = 'transaction'; | ||
protected $_action = 'getService'; | ||
|
||
protected function _getPostData() { | ||
$data = parent::_getPostData(); | ||
|
||
// Checken of alle verplichte velden geset zijn | ||
if ($this->_apiToken == '') { | ||
throw new Pay_Exception('apiToken not set', 1); | ||
} else { | ||
$data['token'] = $this->_apiToken; | ||
} | ||
if (empty($this->_serviceId)) { | ||
throw new Pay_Exception('serviceId not set', 1); | ||
} else { | ||
$data['serviceId'] = $this->_serviceId; | ||
} | ||
return $data; | ||
} | ||
protected function _processResult($arrReturn) { | ||
if (!$arrReturn['request']['result']) { | ||
return $arrReturn; | ||
} | ||
|
||
$arrReturn['paymentOptions'] = array(); | ||
|
||
$countryOptionList = $arrReturn['countryOptionList']; | ||
unset($arrReturn['countryOptionList']); | ||
if (isset($countryOptionList) && is_array($countryOptionList)) { | ||
foreach ($countryOptionList AS $strCountrCode => $arrCountry) { | ||
foreach ($arrCountry['paymentOptionList'] AS $arrPaymentProfile) { | ||
|
||
if (!isset($arrReturn['paymentOptions'][$arrPaymentProfile['id']])) { | ||
$arrReturn['paymentOptions'][$arrPaymentProfile['id']] = array( | ||
'id' => $arrPaymentProfile['id'], | ||
'name' => $arrPaymentProfile['name'], | ||
'visibleName' => $arrPaymentProfile['name'], | ||
'img' => $arrPaymentProfile['img'], | ||
'path' => $arrPaymentProfile['path'], | ||
'paymentOptionSubList' => array(), | ||
'countries' => array(), | ||
); | ||
} | ||
|
||
if (!empty($arrPaymentProfile['paymentOptionSubList'])) { | ||
$arrReturn['paymentOptions'][$arrPaymentProfile['id']]['paymentOptionSubList'] = $arrPaymentProfile['paymentOptionSubList']; | ||
} | ||
|
||
|
||
$arrReturn['paymentOptions'][$arrPaymentProfile['id']]['countries'][$strCountrCode] = array( | ||
'id' => $strCountrCode, | ||
'name' => $arrCountry['visibleName'], | ||
); | ||
} | ||
} | ||
} | ||
return $arrReturn; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
class Pay_Api_Info extends Pay_Api { | ||
|
||
protected $_version = 'v3'; | ||
protected $_controller = 'transaction'; | ||
protected $_action = 'info'; | ||
|
||
public function setTransactionId($transactionId){ | ||
$this->_postData['transactionId'] = $transactionId; | ||
} | ||
protected function _getPostData() { | ||
$data = parent::_getPostData(); | ||
if ($this->_apiToken == '') { | ||
throw new Pay_Exception('apiToken not set', 1); | ||
} else { | ||
$data['token'] = $this->_apiToken; | ||
} | ||
if(!isset($this->_postData['transactionId'])){ | ||
throw new Pay_Exception('transactionId is not set', 1); | ||
} | ||
return $data; | ||
} | ||
} |
Oops, something went wrong.