Skip to content

Commit

Permalink
Update GetService to v16
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinverschoor committed May 27, 2020
1 parent ae6ccc2 commit c158d69
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
23 changes: 21 additions & 2 deletions src/Api/Transaction/GetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,40 @@ class GetService extends Transaction
{
protected $apiTokenRequired = true;
protected $serviceIdRequired = true;
protected $version = 16;

/**
* @var int The ID of the payment method. Only the payment options linked to the provided payment method ID will be returned if an ID is provided. If omitted, all available payment options are returned. Use the following IDs to filter the options:.
*/
private $paymentMethodId;

/**
* @var array cached result
*/
private static $cache = array();

/**
* @param int $paymentMethodId
*/
public function setPaymentMethodId($paymentMethodId)
{
$this->paymentMethodId = $paymentMethodId;
}

/**
* @inheritdoc
* @throws \Paynl\Error\Required\ServiceId serviceId is required
*/
protected function getData()
{
Helper::requireServiceId();
Helper::requireServiceId();

$this->data['serviceId'] = Config::getServiceId();

if (!empty($this->paymentMethodId)) {
$this->data['paymentMethodId'] = $this->paymentMethodId;
}

return parent::getData();
}

Expand All @@ -40,7 +58,7 @@ public function doRequest($endpoint = null, $version = null)
{
Helper::requireApiToken();
Helper::requireServiceId();

$cacheKey = Config::getTokenCode().'|'.Config::getApiToken() . '|' . Config::getServiceId();
if (isset(self::$cache[$cacheKey])) {
if (self::$cache[$cacheKey] instanceof \Exception) {
Expand All @@ -55,6 +73,7 @@ public function doRequest($endpoint = null, $version = null)
self::$cache[$cacheKey] = $e;
throw $e;
}

return $result;
}
}
25 changes: 16 additions & 9 deletions src/Paymentmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class Paymentmethods
*/
private static function reorderOutput($input)
{
$paymentMethods = array();
$paymentMethods = array();

$basePath = $input['service']['basePath'];

foreach ((array)$input['countryOptionList'] as $country) {
foreach ((array)$input['countryOptionList'] as $country) {

foreach ((array)$country['paymentOptionList'] as $paymentOption) {
if (isset($paymentMethods[$paymentOption['id']])) {
$paymentMethods[$paymentOption['id']]['countries'][] = $country['id'];
Expand All @@ -34,24 +33,30 @@ private static function reorderOutput($input)
$banks = array();
if (!empty($paymentOption['paymentOptionSubList'])) {
foreach ((array)$paymentOption['paymentOptionSubList'] as $optionSub) {

$image = '';
if ($paymentOption['id'] == 10) {// only add images for ideal, because the rest will not have images
$image = $basePath.$optionSub['path'].$optionSub['img'];
if (isset($optionSub['image'])) {
$image = $optionSub['image'];
}
$banks[] = array(
'id' => $optionSub['id'],
'name' => $optionSub['name'],
'visibleName' => $optionSub['visibleName'],
'image' => $image,
'image' => $optionSub['image'],
);
}
}
}

$paymentMethods[$paymentOption['id']] = array(
'id' => $paymentOption['id'],
'name' => $paymentOption['name'],
'visibleName' => $paymentOption['visibleName'],
'min_amount' => $paymentOption['min_amount'],
'max_amount' => $paymentOption['max_amount'],
'countries' => array($country['id']),
'banks' => $banks,
'brand' => $paymentOption['brand'],

);
}
}
Expand Down Expand Up @@ -88,8 +93,10 @@ private static function filterCountry($paymentMethods, $country)
public static function getList(array $options = array())
{
$api = new Api\GetService();
$result = $api->doRequest();
$result = $api->doRequest();

$paymentMethods = self::reorderOutput($result);


if (isset($options['country'])) {
$paymentMethods = self::filterCountry($paymentMethods, $options['country']);
Expand Down
26 changes: 26 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,32 @@ public static function details(
return new Result\Details($result);
}


/**
* Gets the services
*
* @param string|null $paymentMethodId
*
* @return Result\GetService
* @throws Error\Api
* @throws Error\Error
* @throws Error\Required\ApiToken
*/
public static function getService(
$paymentMethodId = null
)
{

$api = new Api\GetService();

if ($paymentMethodId !== null) {
$api->setPaymentMethodId($paymentMethodId);
}
$result = $api->doRequest();

return new Result\GetService($result);
}

/**
* Get the transaction in an exchange script.
* This will work for all kinds of exchange calls (GET, POST AND POST_XML)
Expand Down

0 comments on commit c158d69

Please sign in to comment.