diff --git a/src/Api/Transaction/GetService.php b/src/Api/Transaction/GetService.php index 7427c559..0967e40d 100644 --- a/src/Api/Transaction/GetService.php +++ b/src/Api/Transaction/GetService.php @@ -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(); } @@ -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) { @@ -55,6 +73,7 @@ public function doRequest($endpoint = null, $version = null) self::$cache[$cacheKey] = $e; throw $e; } + return $result; } } diff --git a/src/Paymentmethods.php b/src/Paymentmethods.php index 51d0154b..207f75d1 100644 --- a/src/Paymentmethods.php +++ b/src/Paymentmethods.php @@ -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']; @@ -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'], + ); } } @@ -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']); diff --git a/src/Transaction.php b/src/Transaction.php index 5ced4ced..7bbde549 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -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)