-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functions to manage tradeNames
Created tests
- Loading branch information
Andy Pieters
committed
Nov 1, 2017
1 parent
ca7b913
commit 762cd3b
Showing
18 changed files
with
544 additions
and
114 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,5 @@ | ||
<?php | ||
require_once '../../vendor/autoload.php'; | ||
require_once '../config.php'; | ||
|
||
\Paynl\Merchant::addTradeName('pay.be'); |
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,7 @@ | ||
<?php | ||
require_once '../../vendor/autoload.php'; | ||
require_once '../config.php'; | ||
|
||
$result = \Paynl\Merchant::deleteTradeName('TM-3311-7380'); | ||
|
||
var_dump($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,5 @@ | ||
<?php | ||
require_once '../../vendor/autoload.php'; | ||
require_once '../config.php'; | ||
|
||
$tradeNames = \Paynl\Merchant::getTradeNames('M-3421-2120'); |
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,5 @@ | ||
<?php | ||
require_once '../../vendor/autoload.php'; | ||
require_once '../config.php'; | ||
|
||
$result = \Paynl\Merchant::info('M-1234-5678'); |
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 |
---|---|---|
|
@@ -27,118 +27,122 @@ | |
* | ||
* @author Andy Pieters <[email protected]> | ||
*/ | ||
class Api | ||
{ | ||
/** | ||
* @var int the version of the api | ||
*/ | ||
protected $version = 1; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $data = array(); | ||
|
||
/** | ||
* @var bool Is the ApiToken required for this API | ||
*/ | ||
protected $apiTokenRequired = false; | ||
/** | ||
* @var bool Is the serviceId required for this API | ||
*/ | ||
protected $serviceIdRequired = false; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isApiTokenRequired() | ||
{ | ||
return $this->apiTokenRequired; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isServiceIdRequired() | ||
{ | ||
return $this->serviceIdRequired; | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws Error\Required\ApiToken | ||
* @throws Error\Required\ServiceId | ||
*/ | ||
protected function getData() | ||
{ | ||
if($this->isApiTokenRequired()) { | ||
Helper::requireApiToken(); | ||
$this->data['token'] = Config::getApiToken(); | ||
} | ||
if($this->isServiceIdRequired()){ | ||
Helper::requireServiceId(); | ||
$this->data['serviceId'] = Config::getServiceId(); | ||
} | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* @param object|array $result | ||
* @return array | ||
* @throws Error\Api | ||
*/ | ||
protected function processResult($result) | ||
{ | ||
$output = Helper::objectToArray($result); | ||
|
||
if(!is_array($output)){ | ||
throw new Error\Api($output); | ||
} | ||
|
||
if ($output['request']['result'] != 1 && $output['request']['result'] !== 'TRUE') { | ||
throw new Error\Api($output['request']['errorId'] . ' - ' . $output['request']['errorMessage']); | ||
} | ||
return $output; | ||
} | ||
|
||
/** | ||
* @param $endpoint | ||
* @param null|int $version | ||
* @return array | ||
* | ||
* @throws Error\Api | ||
* @throws Error\Error | ||
*/ | ||
public function doRequest($endpoint, $version = null) | ||
{ | ||
if($version === null){ | ||
$version = $this->version; | ||
} | ||
|
||
$data = $this->getData(); | ||
|
||
$uri = Config::getApiUrl($endpoint, (int) $version); | ||
|
||
$curl = Config::getCurl(); | ||
|
||
if(Config::getCAInfoLocation()){ | ||
// set a custom CAInfo file | ||
$curl->setOpt(CURLOPT_CAINFO, Config::getCAInfoLocation()); | ||
} | ||
|
||
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, Config::getVerifyPeer()); | ||
|
||
$result = $curl->post($uri, $data); | ||
|
||
if($curl->error){ | ||
if(!empty($result)) { | ||
if ($result->status === 'FALSE') { | ||
throw new Error\Api($result->error); | ||
} | ||
} | ||
throw new Error\Error($curl->errorMessage); | ||
} | ||
|
||
return $this->processResult($result); | ||
} | ||
class Api { | ||
/** | ||
* @var int the version of the api | ||
*/ | ||
protected $version = 1; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $data = array(); | ||
|
||
/** | ||
* @var bool Is the ApiToken required for this API | ||
*/ | ||
protected $apiTokenRequired = false; | ||
/** | ||
* @var bool Is the serviceId required for this API | ||
*/ | ||
protected $serviceIdRequired = false; | ||
|
||
/** | ||
* @param $endpoint | ||
* @param null|int $version | ||
* | ||
* @return array | ||
* | ||
* @throws Error\Api | ||
* @throws Error\Error | ||
*/ | ||
public function doRequest( $endpoint, $version = null ) { | ||
if ( $version === null ) { | ||
$version = $this->version; | ||
} | ||
|
||
$data = $this->getData(); | ||
|
||
$uri = Config::getApiUrl( $endpoint, (int) $version ); | ||
|
||
$curl = Config::getCurl(); | ||
|
||
if ( Config::getCAInfoLocation() ) { | ||
// set a custom CAInfo file | ||
$curl->setOpt( CURLOPT_CAINFO, Config::getCAInfoLocation() ); | ||
} | ||
|
||
$curl->setOpt( CURLOPT_SSL_VERIFYPEER, Config::getVerifyPeer() ); | ||
|
||
$result = $curl->post( $uri, $data ); | ||
|
||
if ( isset( $result->status ) && $result->status === 'FALSE' ) { | ||
throw new Error\Api( $result->error ); | ||
} | ||
|
||
if ( $curl->error ) { | ||
throw new Error\Error( $curl->errorMessage ); | ||
} | ||
|
||
return $this->processResult( $result ); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws Error\Required\ApiToken | ||
* @throws Error\Required\ServiceId | ||
*/ | ||
protected function getData() { | ||
if ( $this->isApiTokenRequired() ) { | ||
Helper::requireApiToken(); | ||
$this->data['token'] = Config::getApiToken(); | ||
} | ||
if ( $this->isServiceIdRequired() ) { | ||
Helper::requireServiceId(); | ||
$this->data['serviceId'] = Config::getServiceId(); | ||
} | ||
|
||
return $this->data; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isApiTokenRequired() { | ||
return $this->apiTokenRequired; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isServiceIdRequired() { | ||
return $this->serviceIdRequired; | ||
} | ||
|
||
/** | ||
* @param object|array $result | ||
* | ||
* @return array | ||
* @throws Error\Api | ||
*/ | ||
protected function processResult( $result ) { | ||
$output = Helper::objectToArray( $result ); | ||
|
||
if ( ! is_array( $output ) ) { | ||
throw new Error\Api( $output ); | ||
} | ||
|
||
if ( isset( $output['result'] ) ) { | ||
return $output; | ||
} | ||
|
||
if ( | ||
isset( $output['request'] ) && | ||
$output['request']['result'] != 1 && | ||
$output['request']['result'] !== 'TRUE' ) { | ||
throw new Error\Api( $output['request']['errorId'] . ' - ' . $output['request']['errorMessage'] ); | ||
} | ||
|
||
return $output; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
|
||
namespace Paynl\Api\Merchant; | ||
|
||
|
||
|
||
use Paynl\Error; | ||
|
||
class AddTrademark extends Merchant { | ||
protected $trademark; | ||
|
||
/** | ||
* @param string $trademark | ||
*/ | ||
public function setTrademark( $trademark ) { | ||
$this->trademark = $trademark; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getData() { | ||
if(empty($this->trademark)){ | ||
throw new Error\Required('Trade Name is required'); | ||
} | ||
$this->data['trademark'] = $this->trademark; | ||
|
||
return parent::getData(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function doRequest( $endpoint = null, $version = null ) { | ||
return parent::doRequest( 'Merchant/addTrademark' ); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
|
||
namespace Paynl\Api\Merchant; | ||
|
||
|
||
use Paynl\Error; | ||
|
||
class DeleteTrademark extends Merchant { | ||
protected $trademarkId; | ||
|
||
/** | ||
* @param string $trademarkId | ||
*/ | ||
public function setTrademarkId( $trademarkId ) { | ||
$this->trademarkId = $trademarkId; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getData() { | ||
if(empty($this->trademarkId)){ | ||
throw new Error\Required('trademarkId is required'); | ||
} | ||
$this->data['trademarkId'] = $this->trademarkId; | ||
|
||
return parent::getData(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function doRequest( $endpoint = null, $version = null ) { | ||
return parent::doRequest( 'Merchant/deleteTrademark' ); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
|
||
namespace Paynl\Api\Merchant; | ||
|
||
|
||
class Info extends Merchant { | ||
protected $merchantId; | ||
|
||
/** | ||
* @param string $merchantId | ||
*/ | ||
public function setMerchantId( $merchantId ) { | ||
$this->merchantId = $merchantId; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getData() { | ||
if(!empty($this->merchantId)){ | ||
$this->data['merchantId'] = $this->merchantId; | ||
} | ||
|
||
return parent::getData(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function doRequest( $endpoint = null, $version = null ) { | ||
return parent::doRequest( 'Merchant/info' ); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
|
||
namespace Paynl\Api\Merchant; | ||
|
||
|
||
use Paynl\Api\Api; | ||
|
||
class Merchant extends Api { | ||
protected $version = 2; | ||
protected $apiTokenRequired = true; | ||
|
||
} |
Oops, something went wrong.