From c158d6986d05d10f81756976780cecddddc7f167 Mon Sep 17 00:00:00 2001 From: Kevin Verschoor Date: Wed, 27 May 2020 09:03:43 +0200 Subject: [PATCH 1/3] Update GetService to v16 --- src/Api/Transaction/GetService.php | 23 +++++++++++++++++++++-- src/Paymentmethods.php | 25 ++++++++++++++++--------- src/Transaction.php | 26 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 11 deletions(-) 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 0c066551..5e01f5ba 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -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) From a8ea7c3d44b220f2b02ce1edeb8cd3ac8ef8f528 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Wed, 3 Jun 2020 10:00:16 +0200 Subject: [PATCH 2/3] Update Transaction.php --- src/Transaction.php | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/Transaction.php b/src/Transaction.php index 5e01f5ba..1740f2ab 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -331,33 +331,7 @@ public static function details( $result = $api->doRequest(); 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. From 8b5c706c625ff13e398519772ed3e039f52074bd Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Wed, 3 Jun 2020 10:01:32 +0200 Subject: [PATCH 3/3] Update Transaction.php --- src/Transaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Transaction.php b/src/Transaction.php index 1740f2ab..29b53349 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -331,8 +331,8 @@ public static function details( $result = $api->doRequest(); 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)