Skip to content

Commit

Permalink
Merge pull request #106 from paynl/feature/PLUG-127
Browse files Browse the repository at this point in the history
Update GetService to v16
  • Loading branch information
woutse authored Jun 18, 2020
2 parents 5a74613 + 8b5c706 commit c801462
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 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
2 changes: 1 addition & 1 deletion src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static function details(

return new Result\Details($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 c801462

Please sign in to comment.