From a0a5d2f4e3ab9063938122bbf18d1384758c6975 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:04:25 +0100 Subject: [PATCH 01/21] PLUG-3986 - CRLF Fix --- PHP.gitattributes | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 PHP.gitattributes diff --git a/PHP.gitattributes b/PHP.gitattributes new file mode 100644 index 0000000..647242d --- /dev/null +++ b/PHP.gitattributes @@ -0,0 +1,15 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# PHP files +*.php text eol=lf diff=php +*.phpt text eol=lf diff=php +*.phtml text eol=lf diff=html +*.twig text eol=lf +*.phar binary + +# Configuration +phpcs.xml text eol=lf +phpunit.xml text eol=lf +phpstan.neon text eol=lf +psalm.xml text eol=lf From b3061f7daa5845273431d65f55928f0357d7a3d2 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:05:42 +0100 Subject: [PATCH 02/21] commit --- PHP.gitattributes => .gitattributes | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PHP.gitattributes => .gitattributes (100%) diff --git a/PHP.gitattributes b/.gitattributes similarity index 100% rename from PHP.gitattributes rename to .gitattributes From 30a22c996b0c4abe0dd93f7c826a5bede11150df Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:07:23 +0100 Subject: [PATCH 03/21] commit --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index 647242d..e3aed5c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,6 +7,8 @@ *.phtml text eol=lf diff=html *.twig text eol=lf *.phar binary +*.json text eol=lf diff=json +*.md text eol=lf diff=md # Configuration phpcs.xml text eol=lf From 0baf849bc4515741067f217fb204fa79d416fddb Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:08:47 +0100 Subject: [PATCH 04/21] Update .gitattributes --- .gitattributes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index e3aed5c..bac79e7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ # Auto detect text files and perform LF normalization * text=auto -# PHP files +# Files *.php text eol=lf diff=php *.phpt text eol=lf diff=php *.phtml text eol=lf diff=html @@ -15,3 +15,4 @@ phpcs.xml text eol=lf phpunit.xml text eol=lf phpstan.neon text eol=lf psalm.xml text eol=lf +phplint.yml text eol=lf From e004bdf768b9d63e959334ed330ceb453260add1 Mon Sep 17 00:00:00 2001 From: woutse Date: Fri, 22 Nov 2024 13:50:33 +0100 Subject: [PATCH 05/21] Code polish --- samples/OrderCreate.php | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/OrderCreate.php b/samples/OrderCreate.php index a616041..1caa973 100644 --- a/samples/OrderCreate.php +++ b/samples/OrderCreate.php @@ -107,7 +107,6 @@ try { $request->setReference('SDK0123456789'); $payOrder = $request->start(); - echo get_class($payOrder); } catch (PayException $e) { echo '
';
     echo 'Technical message: ' . $e->getMessage() . PHP_EOL;

From c31fc301232b8b5f0d308f2cf20ebda627588c8a Mon Sep 17 00:00:00 2001
From: woutse 
Date: Fri, 22 Nov 2024 13:56:30 +0100
Subject: [PATCH 06/21] Code polish

---
 src/Util/Text.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/Util/Text.php b/src/Util/Text.php
index ec8f836..a14520f 100644
--- a/src/Util/Text.php
+++ b/src/Util/Text.php
@@ -53,6 +53,7 @@ public function splitAddress(string $address): array
     public static function getFriendlyMessage($errorMessage)
     {
         $friendlyMessages = [
+          'requested payment method is not enabled' => 'This payment method is not available',
           'INVALID_TRANSACTION_STAT' => 'Transaction not ready for refund.',
           'username can not be empty' => 'Connection error. Please check your connection credentials.',
           'bestelling kon niet worden gevonden' => 'Your order could not be found',

From 61657e590f9e1863e31561c2f6717fbee316158a Mon Sep 17 00:00:00 2001
From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com>
Date: Fri, 22 Nov 2024 14:22:12 +0100
Subject: [PATCH 07/21] Update .gitattributes

---
 .gitattributes | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index bac79e7..566b1b8 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,17 +2,4 @@
 * text=auto
 
 # Files
-*.php     text eol=lf diff=php
-*.phpt    text eol=lf diff=php
-*.phtml   text eol=lf diff=html
-*.twig    text eol=lf
-*.phar    binary
-*.json    text eol=lf diff=json
-*.md      text eol=lf diff=md
-
-# Configuration
-phpcs.xml    text eol=lf
-phpunit.xml  text eol=lf
-phpstan.neon text eol=lf
-psalm.xml    text eol=lf
-phplint.yml  text eol=lf
+* text eol=lf diff=php

From 23f5e5a6d1be7e6b16dea395e0af1c5fe62c5e5c Mon Sep 17 00:00:00 2001
From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com>
Date: Fri, 22 Nov 2024 14:24:02 +0100
Subject: [PATCH 08/21] Update .gitattributes

---
 .gitattributes | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/.gitattributes b/.gitattributes
index 566b1b8..130805e 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,5 +1,3 @@
 # Auto detect text files and perform LF normalization
 * text=auto
-
-# Files
-* text eol=lf diff=php
+* text eol=lf

From 2e43b44e7bf5920cf876889d0bce98815d169f9f Mon Sep 17 00:00:00 2001
From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com>
Date: Fri, 22 Nov 2024 14:44:20 +0100
Subject: [PATCH 09/21] Update .gitattributes

---
 .gitattributes | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/.gitattributes b/.gitattributes
index 130805e..36ea091 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,3 +1,11 @@
 # Auto detect text files and perform LF normalization
 * text=auto
 * text eol=lf
+
+# Convert images to binary
+*.png binary
+*.jpg binary
+*.jpeg binary
+*.gif binary
+*.tiff binary
+*.ico binary
\ No newline at end of file

From 5a5dbe5233fc60b5a65cb1aa5b20d020a45ad5fe Mon Sep 17 00:00:00 2001
From: woutse 
Date: Thu, 23 Jan 2025 15:19:09 +0100
Subject: [PATCH 10/21] Code polish

---
 src/Util/Exchange.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Util/Exchange.php b/src/Util/Exchange.php
index cae6240..69e9c68 100644
--- a/src/Util/Exchange.php
+++ b/src/Util/Exchange.php
@@ -47,7 +47,7 @@ public function eventStateChangeToPaid()
      *
      * @param bool $result
      * @param string $message
-     * @param bool $returnOutput If true, then this method returs the output string
+     * @param $returnOutput If If true, then this method returs the output string
      * @return false|string|void
      */
     public function setResponse(bool $result, string $message, $returnOutput = false)

From 7a1c3f3ed8a6a469278cd256efc5466f719b9f0b Mon Sep 17 00:00:00 2001
From: woutse 
Date: Fri, 21 Mar 2025 16:34:22 +0100
Subject: [PATCH 11/21] Added caching

---
 config/config.global.php                      |   3 +-
 samples/ServiceGetConfig.php                  |  14 +-
 src/Config/Config.php                         |   8 +
 src/Model/Request/ServiceGetConfigRequest.php |  14 +-
 src/Util/PayCache.php                         | 144 ++++++++++++++++++
 5 files changed, 172 insertions(+), 11 deletions(-)
 create mode 100644 src/Util/PayCache.php

diff --git a/config/config.global.php b/config/config.global.php
index cd9a18c..2730bbd 100644
--- a/config/config.global.php
+++ b/config/config.global.php
@@ -7,5 +7,6 @@
         'username' => '', # Use AT-Code or SL-Code. Use AT-code together with API-Token.
         'password' => '', # Use API token or secret. Use Secret in combination with SL-Code.
     ],
-    'debug' => false
+    'debug' => false,
+    'useFileCaching' => true
 ];
\ No newline at end of file
diff --git a/samples/ServiceGetConfig.php b/samples/ServiceGetConfig.php
index b24da48..6032637 100644
--- a/samples/ServiceGetConfig.php
+++ b/samples/ServiceGetConfig.php
@@ -16,7 +16,7 @@
 
 try {
     $slCode = $_REQUEST['slcode'] ?? '';
-    $config = (new ServiceGetConfigRequest($slCode))->setConfig($config)->start();
+    $serviceConfig = (new ServiceGetConfigRequest($slCode))->setConfig($config)->start();
 } catch (PayException $e) {
     echo '
';
     echo 'Technical message: ' . $e->getMessage() . PHP_EOL;
@@ -28,18 +28,18 @@
 
 echo '
';
 
-echo $config->getCode() . ' - ' . $config->getName() . PHP_EOL;
+echo $serviceConfig->getCode() . ' - ' . $serviceConfig->getName() . PHP_EOL;
 
-$banks = $config->getBanks();
+$banks = $serviceConfig->getBanks();
 print_r($banks);
 
-$terminals = $config->getTerminals();
+$terminals = $serviceConfig->getTerminals();
 print_r($terminals);
 
-$tguList = $config->getCores();
+$tguList = $serviceConfig->getCores();
 print_r($tguList);
 
-$paymentMethods = $config->getPaymentMethods();
+$paymentMethods = $serviceConfig->getPaymentMethods();
 foreach ($paymentMethods as $method) {
     echo $method->getId() . ' - ';
     echo $method->getName() . ' - ';
@@ -51,6 +51,6 @@
     echo PHP_EOL;
 }
 
-foreach ($config->getCheckoutOptions() as $checkoutOption) {
+foreach ($serviceConfig->getCheckoutOptions() as $checkoutOption) {
     echo '=> TAG: ' . $checkoutOption->getTag() . PHP_EOL;
 }
diff --git a/src/Config/Config.php b/src/Config/Config.php
index d9573e0..5627c0a 100644
--- a/src/Config/Config.php
+++ b/src/Config/Config.php
@@ -371,6 +371,14 @@ public function isEmpty()
         return false;
     }
 
+    /**
+     * @return bool
+     */
+    public function isCacheEnabled()
+    {
+        return ($this->data['useFileCaching'] ?? 0) == 1;
+    }
+
     /**
      * @return string
      */
diff --git a/src/Model/Request/ServiceGetConfigRequest.php b/src/Model/Request/ServiceGetConfigRequest.php
index 767368e..0907a58 100644
--- a/src/Model/Request/ServiceGetConfigRequest.php
+++ b/src/Model/Request/ServiceGetConfigRequest.php
@@ -8,6 +8,7 @@
 use PayNL\Sdk\Request\RequestData;
 use PayNL\Sdk\Model\Response\ServiceGetConfigResponse;
 use PayNL\Sdk\Request\RequestInterface;
+use PayNL\Sdk\Util\PayCache;
 
 /**
  * Class ServiceGetConfigRequest
@@ -54,8 +55,15 @@ public function getBodyParameters(): array
      */
     public function start(): ServiceGetConfigResponse
     {
-        $this->config->setCore('https://rest.pay.nl');
-        $this->config->setVersion(2);
-        return parent::start();
+        $cache = new PayCache();
+        $cacheKey = 'service_config_' . md5(json_encode([$this->config->getUsername(), $this->serviceId]));
+
+        return $cache->get($cacheKey, function () {
+            # Not in cache, doing request
+            echo "Niet in cache, voer API-verzoek uit";
+            $this->config->setCore('https://rest.pay.nl');
+            $this->config->setVersion(2);
+            return parent::start();
+        }, 5); // 5 seconds caching
     }
 }
\ No newline at end of file
diff --git a/src/Util/PayCache.php b/src/Util/PayCache.php
new file mode 100644
index 0000000..dc5215a
--- /dev/null
+++ b/src/Util/PayCache.php
@@ -0,0 +1,144 @@
+cacheDir = $cacheDir ?? sys_get_temp_dir() . '/cache_pay_phpsdk';
+        $this->defaultTtl = $defaultTtl;
+
+        if (!is_dir($this->cacheDir)) {
+            if (!@mkdir($this->cacheDir, 0777, true) && !is_dir($this->cacheDir)) {
+                $this->enabled = false;
+                return;
+            }
+        }
+
+        if (!is_writable($this->cacheDir)) {
+            $this->enabled = false;
+        }
+    }
+
+    /**
+     * @param string $key
+     * @param callable|null $callback
+     * @param int|null $ttl
+     * @return mixed|null
+     */
+    public function get(string $key, callable $callback = null, int $ttl = null): mixed
+    {
+        if (!(Config::getConfig())->isCacheEnabled()) {
+            $this->enabled = false;
+        }
+
+        if (!$this->enabled) {
+            return $callback ? $callback() : null;
+        }
+
+        $file = $this->getCacheFile($key);
+
+        if (file_exists($file)) {
+            $data = @unserialize(file_get_contents($file));
+
+            if ($data !== false && isset($data['expires'], $data['value'])) {
+                if ($data['expires'] >= time()) {
+                    return $data['value'];
+                }
+            }
+
+            // Cache is verlopen of ongeldig
+            @unlink($file);
+        }
+
+        if ($callback !== null) {
+            $value = $callback();
+            $this->set($key, $value, $ttl);
+            return $value;
+        }
+
+        return null;
+    }
+
+    /**
+     * @param string $key
+     * @param mixed $value
+     * @param int|null $ttl
+     * @return void
+     */
+    public function set(string $key, mixed $value, int $ttl = null): void
+    {
+        if (!$this->enabled) {
+            return;
+        }
+
+        $ttl = $ttl ?? $this->defaultTtl;
+        $file = $this->getCacheFile($key);
+
+        $data = [
+            'expires' => time() + $ttl,
+            'value' => $value
+        ];
+
+        @file_put_contents($file, serialize($data), LOCK_EX);
+    }
+
+    /**
+     * @param string $key
+     * @return void
+     */
+    public function delete(string $key): void
+    {
+        if (!$this->enabled) {
+            return;
+        }
+
+        $file = $this->getCacheFile($key);
+        if (file_exists($file)) {
+            @unlink($file);
+        }
+    }
+
+    /**
+     * @return void\
+     */
+    public function clear(): void
+    {
+        if (!$this->enabled) {
+            return;
+        }
+
+        foreach (glob($this->cacheDir . '/*') ?: [] as $file) {
+            @unlink($file);
+        }
+    }
+
+    /**
+     * @param string $key
+     * @return string
+     */
+    private function getCacheFile(string $key): string
+    {
+        echo  $this->cacheDir . '/' . md5($key) . '.cache';
+        return $this->cacheDir . '/' . md5($key) . '.cache';
+    }
+
+    /**
+     * @return bool
+     */
+    public function isEnabled(): bool
+    {
+        return $this->enabled;
+    }
+}

From d4ffbf6b20926c291575a31c8a15fd4e662e5d25 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Fri, 21 Mar 2025 16:54:00 +0100
Subject: [PATCH 12/21] Added caching

---
 src/Model/Request/ServiceGetConfigRequest.php | 3 +--
 src/Util/PayCache.php                         | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/Model/Request/ServiceGetConfigRequest.php b/src/Model/Request/ServiceGetConfigRequest.php
index 0907a58..f74f6e3 100644
--- a/src/Model/Request/ServiceGetConfigRequest.php
+++ b/src/Model/Request/ServiceGetConfigRequest.php
@@ -56,11 +56,10 @@ public function getBodyParameters(): array
     public function start(): ServiceGetConfigResponse
     {
         $cache = new PayCache();
-        $cacheKey = 'service_config_' . md5(json_encode([$this->config->getUsername(), $this->serviceId]));
+        $cacheKey = 'service_getconfig_' . md5(json_encode([$this->config->getUsername(), $this->config->getPassword(), $this->serviceId]));
 
         return $cache->get($cacheKey, function () {
             # Not in cache, doing request
-            echo "Niet in cache, voer API-verzoek uit";
             $this->config->setCore('https://rest.pay.nl');
             $this->config->setVersion(2);
             return parent::start();
diff --git a/src/Util/PayCache.php b/src/Util/PayCache.php
index dc5215a..c42de87 100644
--- a/src/Util/PayCache.php
+++ b/src/Util/PayCache.php
@@ -130,7 +130,6 @@ public function clear(): void
      */
     private function getCacheFile(string $key): string
     {
-        echo  $this->cacheDir . '/' . md5($key) . '.cache';
         return $this->cacheDir . '/' . md5($key) . '.cache';
     }
 

From af8adaac27d88a5be840f53cff3767edf3823b48 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Fri, 21 Mar 2025 19:45:59 +0100
Subject: [PATCH 13/21] Added caching

---
 samples/ServiceGetConfig.php                  |  2 +-
 src/Config/Config.php                         | 18 +++++++++++++
 src/Model/Request/ServiceGetConfigRequest.php | 26 ++++++++++++++-----
 src/Request/RequestData.php                   |  3 ++-
 src/Util/PayCache.php                         |  6 -----
 5 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/samples/ServiceGetConfig.php b/samples/ServiceGetConfig.php
index 6032637..739f9db 100644
--- a/samples/ServiceGetConfig.php
+++ b/samples/ServiceGetConfig.php
@@ -12,7 +12,7 @@
 $config = new Config();
 $config->setUsername($_REQUEST['username'] ?? '');
 $config->setPassword($_REQUEST['password'] ?? '');
-
+$config->enableCaching();
 
 try {
     $slCode = $_REQUEST['slcode'] ?? '';
diff --git a/src/Config/Config.php b/src/Config/Config.php
index 5627c0a..705ea2f 100644
--- a/src/Config/Config.php
+++ b/src/Config/Config.php
@@ -397,6 +397,24 @@ public function setPassword(string $password): self
         return $this;
     }
 
+    /**
+     * @return $this
+     */
+    public function enableCaching()
+    {
+        $this->data['useFileCaching'] = true;
+        return $this;
+    }
+
+    /**
+     * @return $this
+     */
+    public function disableCaching()
+    {
+        $this->data['useFileCaching'] = false;
+        return $this;
+    }
+
     /**
      * @return string
      */
diff --git a/src/Model/Request/ServiceGetConfigRequest.php b/src/Model/Request/ServiceGetConfigRequest.php
index f74f6e3..67da489 100644
--- a/src/Model/Request/ServiceGetConfigRequest.php
+++ b/src/Model/Request/ServiceGetConfigRequest.php
@@ -56,13 +56,25 @@ public function getBodyParameters(): array
     public function start(): ServiceGetConfigResponse
     {
         $cache = new PayCache();
-        $cacheKey = 'service_getconfig_' . md5(json_encode([$this->config->getUsername(), $this->config->getPassword(), $this->serviceId]));
 
-        return $cache->get($cacheKey, function () {
-            # Not in cache, doing request
-            $this->config->setCore('https://rest.pay.nl');
-            $this->config->setVersion(2);
-            return parent::start();
-        }, 5); // 5 seconds caching
+        if ($this->config->isCacheEnabled()) {
+            $cacheKey = 'service_getconfig_' . md5(json_encode([$this->config->getUsername(), $this->config->getPassword(), $this->serviceId]));
+            return $cache->get($cacheKey, function () {
+                return $this->startAPI();
+            }, 5); // 5 seconds caching
+        }
+
+        return $this->startAPI();
+    }
+
+    /**
+     * @return mixed
+     * @throws PayException
+     */
+    private function startAPI(): mixed
+    {
+        $this->config->setCore('https://rest.pay.nl');
+        $this->config->setVersion(2);
+        return parent::start();
     }
 }
\ No newline at end of file
diff --git a/src/Request/RequestData.php b/src/Request/RequestData.php
index f357fad..1636089 100644
--- a/src/Request/RequestData.php
+++ b/src/Request/RequestData.php
@@ -43,7 +43,8 @@ public function __construct(string $mapperName, string $uri, string $requestMeth
      */
     public function setConfig(Config $config): self
     {
-        $this->config = $config;
+        $this->config = (new Config(require __DIR__ . '/../../config/config.global.php'));
+        $this->config->merge($config);
         return $this;
     }
 
diff --git a/src/Util/PayCache.php b/src/Util/PayCache.php
index c42de87..2b0bbe8 100644
--- a/src/Util/PayCache.php
+++ b/src/Util/PayCache.php
@@ -2,8 +2,6 @@
 
 namespace PayNL\Sdk\Util;
 
-use PayNL\Sdk\Config\Config;
-
 class PayCache
 {
     private string $cacheDir;
@@ -39,10 +37,6 @@ public function __construct(string $cacheDir = null, int $defaultTtl = 600)
      */
     public function get(string $key, callable $callback = null, int $ttl = null): mixed
     {
-        if (!(Config::getConfig())->isCacheEnabled()) {
-            $this->enabled = false;
-        }
-
         if (!$this->enabled) {
             return $callback ? $callback() : null;
         }

From 53058b26ac89eece3343baca529c4405ff2425f6 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Sat, 22 Mar 2025 11:29:40 +0100
Subject: [PATCH 14/21] Added caching

---
 samples/ServiceGetConfig.php |  1 -
 src/Config/Config.php        | 16 ++++------------
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/samples/ServiceGetConfig.php b/samples/ServiceGetConfig.php
index 739f9db..cc17263 100644
--- a/samples/ServiceGetConfig.php
+++ b/samples/ServiceGetConfig.php
@@ -12,7 +12,6 @@
 $config = new Config();
 $config->setUsername($_REQUEST['username'] ?? '');
 $config->setPassword($_REQUEST['password'] ?? '');
-$config->enableCaching();
 
 try {
     $slCode = $_REQUEST['slcode'] ?? '';
diff --git a/src/Config/Config.php b/src/Config/Config.php
index 705ea2f..b240364 100644
--- a/src/Config/Config.php
+++ b/src/Config/Config.php
@@ -398,20 +398,12 @@ public function setPassword(string $password): self
     }
 
     /**
-     * @return $this
-     */
-    public function enableCaching()
-    {
-        $this->data['useFileCaching'] = true;
-        return $this;
-    }
-
-    /**
-     * @return $this
+     * @param bool $caching
+     * @return self
      */
-    public function disableCaching()
+    public function setCaching(bool $caching): self
     {
-        $this->data['useFileCaching'] = false;
+        $this->data['useFileCaching'] = $caching;
         return $this;
     }
 

From b44f3c52889b50fec95dc2785c2bb2beee67243f Mon Sep 17 00:00:00 2001
From: woutse 
Date: Sat, 22 Mar 2025 12:40:49 +0100
Subject: [PATCH 15/21] Added caching

---
 src/Model/Request/ServiceGetConfigRequest.php | 45 +++++++++++++++----
 src/Request/RequestData.php                   | 24 +++++++---
 src/Util/PayCache.php                         |  4 +-
 3 files changed, 57 insertions(+), 16 deletions(-)

diff --git a/src/Model/Request/ServiceGetConfigRequest.php b/src/Model/Request/ServiceGetConfigRequest.php
index 67da489..c814a42 100644
--- a/src/Model/Request/ServiceGetConfigRequest.php
+++ b/src/Model/Request/ServiceGetConfigRequest.php
@@ -49,29 +49,58 @@ public function getBodyParameters(): array
         return [];
     }
 
+    /**
+     * @var array cached result
+     */
+    private static $cache = array();
+
     /**
      * @return ServiceGetConfigResponse
      * @throws PayException
      */
     public function start(): ServiceGetConfigResponse
     {
-        $cache = new PayCache();
+        $cacheKey = 'service_getconfig_' . md5(json_encode([$this->config->getUsername(), $this->config->getPassword(), $this->serviceId]));
+
+        # First check static cache
+        if (isset(self::$cache[$cacheKey])) {
+            if (self::$cache[$cacheKey] instanceof \Exception) {
+                throw self::$cache[$cacheKey];
+            }
+            return self::$cache[$cacheKey];
+        }
 
+        # Then check file-based cache
         if ($this->config->isCacheEnabled()) {
-            $cacheKey = 'service_getconfig_' . md5(json_encode([$this->config->getUsername(), $this->config->getPassword(), $this->serviceId]));
-            return $cache->get($cacheKey, function () {
-                return $this->startAPI();
-            }, 5); // 5 seconds caching
+            $cache = new PayCache();
+
+            return $cache->get($cacheKey, function () use ($cacheKey) {
+                try {
+                    $result = $this->startAPI();
+                    self::$cache[$cacheKey] = $result;
+                    return $result;
+                } catch (\Exception $e) {
+                    self::$cache[$cacheKey] = $e;
+                    throw $e;
+                }
+            }, 5); // 5 seconden caching
         }
 
-        return $this->startAPI();
+        try {
+            $result = $this->startAPI();
+            self::$cache[$cacheKey] = $result;
+            return $result;
+        } catch (\Exception $e) {
+            self::$cache[$cacheKey] = $e;
+            throw $e;
+        }
     }
 
     /**
-     * @return mixed
+     * @return ServiceGetConfigResponse
      * @throws PayException
      */
-    private function startAPI(): mixed
+    private function startAPI(): ServiceGetConfigResponse
     {
         $this->config->setCore('https://rest.pay.nl');
         $this->config->setVersion(2);
diff --git a/src/Request/RequestData.php b/src/Request/RequestData.php
index 1636089..fa702d1 100644
--- a/src/Request/RequestData.php
+++ b/src/Request/RequestData.php
@@ -57,16 +57,17 @@ public function setApplication(Application $application): void
         $this->application = $application;
     }
 
+
     /**
-     * @return mixed
+     * @return Config|null
      * @throws PayException
-     * @throws Exception
      */
-    public function start()
+    private function getConfig(): Config
     {
-        $config = (new Config(require __DIR__ . '/../../config/config.global.php'));
-        if (!empty($this->config)) {
-            $config->merge($this->config);
+        if (empty($this->config)) {
+            $config = (new Config(require __DIR__ . '/../../config/config.global.php'));
+        } else {
+            $config = $this->config;
         }
 
         if (!empty($config->getFailoverUrl())) {
@@ -77,6 +78,17 @@ public function start()
             throw new PayException('Please check your config', 0, 0);
         }
 
+        return $config;
+    }
+
+    /**
+     * @return mixed
+     * @throws PayException
+     */
+    public function start()
+    {
+        $config = $this->getConfig();
+
         try {
             if (empty($this->application)) {
                 $this->application = Application::init($config);
diff --git a/src/Util/PayCache.php b/src/Util/PayCache.php
index 2b0bbe8..54d82f8 100644
--- a/src/Util/PayCache.php
+++ b/src/Util/PayCache.php
@@ -52,7 +52,7 @@ public function get(string $key, callable $callback = null, int $ttl = null): mi
                 }
             }
 
-            // Cache is verlopen of ongeldig
+            # Cache expired or invalid
             @unlink($file);
         }
 
@@ -105,7 +105,7 @@ public function delete(string $key): void
     }
 
     /**
-     * @return void\
+     * @return void
      */
     public function clear(): void
     {

From d6174d7405dc18941dc390a9ce008e2b0619cb5a Mon Sep 17 00:00:00 2001
From: woutse 
Date: Sat, 22 Mar 2025 15:17:57 +0100
Subject: [PATCH 16/21] Added caching

---
 src/Helpers/StaticCacheTrait.php              | 65 +++++++++++++++++++
 src/Model/Request/OrderStatusRequest.php      | 13 ++--
 src/Model/Request/ServiceGetConfigRequest.php | 41 ++++--------
 .../Request/TransactionStatusRequest.php      | 21 +++++-
 4 files changed, 105 insertions(+), 35 deletions(-)
 create mode 100644 src/Helpers/StaticCacheTrait.php

diff --git a/src/Helpers/StaticCacheTrait.php b/src/Helpers/StaticCacheTrait.php
new file mode 100644
index 0000000..f997246
--- /dev/null
+++ b/src/Helpers/StaticCacheTrait.php
@@ -0,0 +1,65 @@
+config->setCore(Config::TGU1);
-        
-        return parent::start();
+        $cacheKey = 'order_status_' . md5(json_encode([$this->config->getUsername(), $this->orderId]));
+
+        return $this->staticCache($cacheKey, function () {
+            $this->config->setCore(Config::TGU1);
+            return parent::start();
+        });
     }
 }
\ No newline at end of file
diff --git a/src/Model/Request/ServiceGetConfigRequest.php b/src/Model/Request/ServiceGetConfigRequest.php
index c814a42..c07a497 100644
--- a/src/Model/Request/ServiceGetConfigRequest.php
+++ b/src/Model/Request/ServiceGetConfigRequest.php
@@ -9,6 +9,7 @@
 use PayNL\Sdk\Model\Response\ServiceGetConfigResponse;
 use PayNL\Sdk\Request\RequestInterface;
 use PayNL\Sdk\Util\PayCache;
+use PayNL\Sdk\Helpers\StaticCacheTrait;
 
 /**
  * Class ServiceGetConfigRequest
@@ -19,6 +20,7 @@
  */
 class ServiceGetConfigRequest extends RequestData
 {
+    use StaticCacheTrait;
     private string $serviceId;
 
     /**
@@ -49,11 +51,6 @@ public function getBodyParameters(): array
         return [];
     }
 
-    /**
-     * @var array cached result
-     */
-    private static $cache = array();
-
     /**
      * @return ServiceGetConfigResponse
      * @throws PayException
@@ -62,38 +59,22 @@ public function start(): ServiceGetConfigResponse
     {
         $cacheKey = 'service_getconfig_' . md5(json_encode([$this->config->getUsername(), $this->config->getPassword(), $this->serviceId]));
 
-        # First check static cache
-        if (isset(self::$cache[$cacheKey])) {
-            if (self::$cache[$cacheKey] instanceof \Exception) {
-                throw self::$cache[$cacheKey];
-            }
-            return self::$cache[$cacheKey];
+        if ($this->hasStaticCache($cacheKey)) {
+            return $this->getStaticCacheValue($cacheKey);
         }
 
-        # Then check file-based cache
         if ($this->config->isCacheEnabled()) {
             $cache = new PayCache();
-
             return $cache->get($cacheKey, function () use ($cacheKey) {
-                try {
-                    $result = $this->startAPI();
-                    self::$cache[$cacheKey] = $result;
-                    return $result;
-                } catch (\Exception $e) {
-                    self::$cache[$cacheKey] = $e;
-                    throw $e;
-                }
-            }, 5); // 5 seconden caching
+                return $this->staticCache($cacheKey, function () {
+                    return $this->startAPI();
+                });
+            }, 5);
         }
 
-        try {
-            $result = $this->startAPI();
-            self::$cache[$cacheKey] = $result;
-            return $result;
-        } catch (\Exception $e) {
-            self::$cache[$cacheKey] = $e;
-            throw $e;
-        }
+        return $this->staticCache($cacheKey, function () {
+            return $this->startAPI();
+        });
     }
 
     /**
diff --git a/src/Model/Request/TransactionStatusRequest.php b/src/Model/Request/TransactionStatusRequest.php
index b328084..8564b2f 100644
--- a/src/Model/Request/TransactionStatusRequest.php
+++ b/src/Model/Request/TransactionStatusRequest.php
@@ -4,10 +4,12 @@
 
 namespace PayNL\Sdk\Model\Request;
 
+use PayNL\Sdk\Config\Config;
 use PayNL\Sdk\Exception\PayException;
 use PayNL\Sdk\Request\RequestData;
 use PayNL\Sdk\Model\Pay\PayOrder;
 use PayNL\Sdk\Request\RequestInterface;
+use PayNL\Sdk\Helpers\StaticCacheTrait;
 
 /**
  * Class TransactionStatusRequest
@@ -17,6 +19,8 @@
  */
 class TransactionStatusRequest extends RequestData
 {
+    use StaticCacheTrait;
+
     private string $orderId;
 
     /**
@@ -50,10 +54,25 @@ public function getBodyParameters(): array
      * @return PayOrder
      * @throws PayException
      */
-    public function start(): PayOrder
+    public function stgtart(): PayOrder
     {
         # Always use rest.pay.nl for this status request
         $this->config->setCore('https://rest.pay.nl');
         return parent::start();
     }
+
+
+    /**
+     * @return PayOrder
+     * @throws \Exception
+     */
+    public function start(): PayOrder
+    {
+        $cacheKey = 'transaction_status_' . md5(json_encode([$this->config->getUsername(), $this->orderId]));
+
+        return $this->staticCache($cacheKey, function () {
+            $this->config->setCore('https://rest.pay.nl');
+            return parent::start();
+        });
+    }
 }
\ No newline at end of file

From c4388a954cedb7e0bf0e55fc0aaa89995984f062 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Sat, 22 Mar 2025 15:18:31 +0100
Subject: [PATCH 17/21] Added caching

---
 src/Model/Request/TransactionStatusRequest.php | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/src/Model/Request/TransactionStatusRequest.php b/src/Model/Request/TransactionStatusRequest.php
index 8564b2f..7b8a917 100644
--- a/src/Model/Request/TransactionStatusRequest.php
+++ b/src/Model/Request/TransactionStatusRequest.php
@@ -50,18 +50,6 @@ public function getBodyParameters(): array
         return [];
     }
 
-    /**
-     * @return PayOrder
-     * @throws PayException
-     */
-    public function stgtart(): PayOrder
-    {
-        # Always use rest.pay.nl for this status request
-        $this->config->setCore('https://rest.pay.nl');
-        return parent::start();
-    }
-
-
     /**
      * @return PayOrder
      * @throws \Exception

From a870b4120c582fe18a3c569219aa172fe5ade037 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Sat, 22 Mar 2025 16:44:53 +0100
Subject: [PATCH 18/21] Updates

---
 .../Response/ServiceGetConfigResponse.php     | 21 ++++++++++++++++++-
 src/Util/Exchange.php                         |  5 ++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/Model/Response/ServiceGetConfigResponse.php b/src/Model/Response/ServiceGetConfigResponse.php
index 4d8d2c4..be9712a 100644
--- a/src/Model/Response/ServiceGetConfigResponse.php
+++ b/src/Model/Response/ServiceGetConfigResponse.php
@@ -335,11 +335,30 @@ public function setTguList(array $tguList): void
     }
 
     /**
+     * Provides a core-list prepared with web protocol.
      * @return array
      */
     public function getCores(): array
     {
-        return $this->getTguList();
+        $cores = $this->getTguList();
+
+        $payDomain = false;
+        foreach ($cores as &$core) {
+            $domain = $core['domain'];
+
+            if (in_array($domain, ['pay.nl', 'connect.pay.nl'])) {
+                $payDomain = true;
+            }
+
+            $core['domain'] = 'https://' . $domain;
+            $core['label'] = $domain;
+        }
+
+        if ($payDomain !== true) {
+            array_unshift($cores, ['domain' => 'https://connect.pay.nl', 'label' => 'connect.pay.nl']);
+        }
+
+        return $cores;
     }
 
     /**
diff --git a/src/Util/Exchange.php b/src/Util/Exchange.php
index 1e72e9d..7bba74d 100644
--- a/src/Util/Exchange.php
+++ b/src/Util/Exchange.php
@@ -74,10 +74,9 @@ public function eventCapture()
     /**
      * Set your exchange response in the end of your exchange processing
      *
-     * @param boolean $result
+     * @param bool $result
      * @param string $message
-     * @param boolean $returnOutput If true, then this method returs the output string
-     * @param $returnOutput If If true, then this method returs the output string
+     * @param bool $returnOutput
      * @return false|string|void
      */
     public function setResponse(bool $result, string $message, bool $returnOutput = false)

From ad7f574d69ceeb674d8b0ff3173c39673675edee Mon Sep 17 00:00:00 2001
From: woutse 
Date: Mon, 24 Mar 2025 11:00:09 +0100
Subject: [PATCH 19/21] Updates

---
 src/Model/Request/OrderStatusRequest.php       | 18 +++++++++++++++++-
 src/Model/Request/TransactionStatusRequest.php | 16 ++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/Model/Request/OrderStatusRequest.php b/src/Model/Request/OrderStatusRequest.php
index ff6803a..d18c934 100644
--- a/src/Model/Request/OrderStatusRequest.php
+++ b/src/Model/Request/OrderStatusRequest.php
@@ -10,6 +10,7 @@
 use PayNL\Sdk\Request\RequestInterface;
 use PayNL\Sdk\Config\Config;
 use PayNL\Sdk\Helpers\StaticCacheTrait;
+use PayNL\Sdk\Util\PayCache;
 
 /**
  * Class OrderStatusRequest
@@ -38,7 +39,7 @@ public function __construct(string $orderId)
     public function getPathParameters(): array
     {
         return [
-          'transactionId' => $this->orderId
+            'transactionId' => $this->orderId
         ];
     }
 
@@ -58,9 +59,24 @@ public function start(): PayOrder
     {
         $cacheKey = 'order_status_' . md5(json_encode([$this->config->getUsername(), $this->orderId]));
 
+        if ($this->hasStaticCache($cacheKey)) {
+            return $this->getStaticCacheValue($cacheKey);
+        }
+
+        if ($this->config->isCacheEnabled()) {
+            $cache = new PayCache();
+            return $cache->get($cacheKey, function () use ($cacheKey) {
+                return $this->staticCache($cacheKey, function () {
+                    $this->config->setCore(Config::TGU1);
+                    return parent::start();
+                });
+            }, 3); # 3 seconds file caching
+        }
+
         return $this->staticCache($cacheKey, function () {
             $this->config->setCore(Config::TGU1);
             return parent::start();
         });
     }
+
 }
\ No newline at end of file
diff --git a/src/Model/Request/TransactionStatusRequest.php b/src/Model/Request/TransactionStatusRequest.php
index 7b8a917..cefabcb 100644
--- a/src/Model/Request/TransactionStatusRequest.php
+++ b/src/Model/Request/TransactionStatusRequest.php
@@ -10,6 +10,7 @@
 use PayNL\Sdk\Model\Pay\PayOrder;
 use PayNL\Sdk\Request\RequestInterface;
 use PayNL\Sdk\Helpers\StaticCacheTrait;
+use PayNL\Sdk\Util\PayCache;
 
 /**
  * Class TransactionStatusRequest
@@ -58,9 +59,24 @@ public function start(): PayOrder
     {
         $cacheKey = 'transaction_status_' . md5(json_encode([$this->config->getUsername(), $this->orderId]));
 
+        if ($this->hasStaticCache($cacheKey)) {
+            return $this->getStaticCacheValue($cacheKey);
+        }
+
+        if ($this->config->isCacheEnabled()) {
+            $cache = new PayCache();
+            return $cache->get($cacheKey, function () use ($cacheKey) {
+                return $this->staticCache($cacheKey, function () {
+                    $this->config->setCore('https://rest.pay.nl');
+                    return parent::start();
+                });
+            }, 3); # 3 seconds file caching
+        }
+
         return $this->staticCache($cacheKey, function () {
             $this->config->setCore('https://rest.pay.nl');
             return parent::start();
         });
     }
+
 }
\ No newline at end of file

From b7e5d36b73f48e254d54b945f1475c52ac260678 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Tue, 25 Mar 2025 16:12:08 +0100
Subject: [PATCH 20/21] Bumped version

---
 composer.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/composer.json b/composer.json
index 9e91e0b..fece440 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
 {
     "name": "paynl/php-sdk",
     "description": "Software Development Kit for implementing Pay.'s API version 3",
-    "version": "0.2.0",
+    "version": "0.2.1",
     "type": "library",
     "require": {
         "php": "^8.1",

From d1de6b233c24a4d0a9b51824ba238d9cb5a721a2 Mon Sep 17 00:00:00 2001
From: woutse 
Date: Tue, 25 Mar 2025 16:27:26 +0100
Subject: [PATCH 21/21] Code polish

---
 config/config.global.php                       |  2 +-
 src/Config/Config.php                          |  4 ++--
 src/Helpers/StaticCacheTrait.php               |  4 +---
 src/Model/Request/OrderStatusRequest.php       |  3 +--
 src/Model/Request/ServiceGetConfigRequest.php  | 10 +++++++---
 src/Model/Request/TransactionStatusRequest.php |  7 +++----
 src/Util/Exchange.php                          |  4 ++--
 src/Util/PayCache.php                          |  8 ++++----
 8 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/config/config.global.php b/config/config.global.php
index 2730bbd..e6ff123 100644
--- a/config/config.global.php
+++ b/config/config.global.php
@@ -9,4 +9,4 @@
     ],
     'debug' => false,
     'useFileCaching' => true
-];
\ No newline at end of file
+];
diff --git a/src/Config/Config.php b/src/Config/Config.php
index b240364..a987305 100644
--- a/src/Config/Config.php
+++ b/src/Config/Config.php
@@ -372,7 +372,7 @@ public function isEmpty()
     }
 
     /**
-     * @return bool
+     * @return boolean
      */
     public function isCacheEnabled()
     {
@@ -398,7 +398,7 @@ public function setPassword(string $password): self
     }
 
     /**
-     * @param bool $caching
+     * @param boolean $caching
      * @return self
      */
     public function setCaching(bool $caching): self
diff --git a/src/Helpers/StaticCacheTrait.php b/src/Helpers/StaticCacheTrait.php
index f997246..19113f0 100644
--- a/src/Helpers/StaticCacheTrait.php
+++ b/src/Helpers/StaticCacheTrait.php
@@ -36,7 +36,7 @@ protected function staticCache(string $key, callable $callback): mixed
 
     /**
      * @param string $key
-     * @return bool
+     * @return boolean
      */
     protected function hasStaticCache(string $key): bool
     {
@@ -60,6 +60,4 @@ protected function getStaticCacheValue(string $key): mixed
 
         return self::$cache[$key];
     }
-
-
 }
diff --git a/src/Model/Request/OrderStatusRequest.php b/src/Model/Request/OrderStatusRequest.php
index d18c934..2844f4f 100644
--- a/src/Model/Request/OrderStatusRequest.php
+++ b/src/Model/Request/OrderStatusRequest.php
@@ -78,5 +78,4 @@ public function start(): PayOrder
             return parent::start();
         });
     }
-
-}
\ No newline at end of file
+}
diff --git a/src/Model/Request/ServiceGetConfigRequest.php b/src/Model/Request/ServiceGetConfigRequest.php
index c07a497..cee0222 100644
--- a/src/Model/Request/ServiceGetConfigRequest.php
+++ b/src/Model/Request/ServiceGetConfigRequest.php
@@ -21,12 +21,16 @@
 class ServiceGetConfigRequest extends RequestData
 {
     use StaticCacheTrait;
+
+    /**
+     * @var string|mixed
+     */
     private string $serviceId;
 
     /**
-     * @param $serviceId
+     * @param string $serviceId
      */
-    public function __construct($serviceId = '')
+    public function __construct(string $serviceId = '')
     {
         $this->serviceId = $serviceId;
         parent::__construct('GetConfig', '/services/config', RequestInterface::METHOD_GET);
@@ -87,4 +91,4 @@ private function startAPI(): ServiceGetConfigResponse
         $this->config->setVersion(2);
         return parent::start();
     }
-}
\ No newline at end of file
+}
diff --git a/src/Model/Request/TransactionStatusRequest.php b/src/Model/Request/TransactionStatusRequest.php
index cefabcb..bf6629f 100644
--- a/src/Model/Request/TransactionStatusRequest.php
+++ b/src/Model/Request/TransactionStatusRequest.php
@@ -25,9 +25,9 @@ class TransactionStatusRequest extends RequestData
     private string $orderId;
 
     /**
-     * @param $orderid
+     * @param string $orderId
      */
-    public function __construct($orderId)
+    public function __construct(string $orderId)
     {
         $this->orderId = $orderId;
         parent::__construct('TransactionStatus', '/transactions/%transactionId%/status', RequestInterface::METHOD_GET);
@@ -78,5 +78,4 @@ public function start(): PayOrder
             return parent::start();
         });
     }
-
-}
\ No newline at end of file
+}
diff --git a/src/Util/Exchange.php b/src/Util/Exchange.php
index 7bba74d..7924edb 100644
--- a/src/Util/Exchange.php
+++ b/src/Util/Exchange.php
@@ -74,9 +74,9 @@ public function eventCapture()
     /**
      * Set your exchange response in the end of your exchange processing
      *
-     * @param bool $result
+     * @param boolean $result
      * @param string $message
-     * @param bool $returnOutput
+     * @param boolean $returnOutput
      * @return false|string|void
      */
     public function setResponse(bool $result, string $message, bool $returnOutput = false)
diff --git a/src/Util/PayCache.php b/src/Util/PayCache.php
index 54d82f8..d557db8 100644
--- a/src/Util/PayCache.php
+++ b/src/Util/PayCache.php
@@ -10,7 +10,7 @@ class PayCache
 
     /**
      * @param string|null $cacheDir
-     * @param int $defaultTtl
+     * @param integer $defaultTtl
      */
     public function __construct(string $cacheDir = null, int $defaultTtl = 600)
     {
@@ -32,7 +32,7 @@ public function __construct(string $cacheDir = null, int $defaultTtl = 600)
     /**
      * @param string $key
      * @param callable|null $callback
-     * @param int|null $ttl
+     * @param integer|null $ttl
      * @return mixed|null
      */
     public function get(string $key, callable $callback = null, int $ttl = null): mixed
@@ -68,7 +68,7 @@ public function get(string $key, callable $callback = null, int $ttl = null): mi
     /**
      * @param string $key
      * @param mixed $value
-     * @param int|null $ttl
+     * @param integer|null $ttl
      * @return void
      */
     public function set(string $key, mixed $value, int $ttl = null): void
@@ -128,7 +128,7 @@ private function getCacheFile(string $key): string
     }
 
     /**
-     * @return bool
+     * @return boolean
      */
     public function isEnabled(): bool
     {