From 6bc1838e3bab2d486354474136934ce878f1a760 Mon Sep 17 00:00:00 2001 From: Jaime Hing III Date: Wed, 24 Jul 2024 21:12:08 +0800 Subject: [PATCH] Adjust building of parameter query due to changes in checkout session endpoints. --- CHANGELOG.md | 4 ++++ VERSION | 2 +- initialize.php | 1 - src/Helpers/Parameter.php | 31 ------------------------------- src/HttpClient.php | 4 ++-- 5 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 src/Helpers/Parameter.php diff --git a/CHANGELOG.md b/CHANGELOG.md index facd658..fb1bd01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.1.3] - 2024-07-24 + +- Adjust building of parameter query due to changes in checkout session endpoints. + ## [0.1.2] - 2024-07-24 - Add checkout session endpoints. diff --git a/VERSION b/VERSION index d917d3e..b1e80bb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.2 +0.1.3 diff --git a/initialize.php b/initialize.php index 13fd2be..b63db21 100644 --- a/initialize.php +++ b/initialize.php @@ -3,7 +3,6 @@ $srcDir = dirname(__FILE__) . '/src'; require $srcDir . '/Payrex.php'; -require $srcDir . '/Helpers/Parameter.php'; require $srcDir . '/PayrexClient.php'; require $srcDir . '/ApiResource.php'; require $srcDir . '/Error.php'; diff --git a/src/Helpers/Parameter.php b/src/Helpers/Parameter.php deleted file mode 100644 index dad9600..0000000 --- a/src/Helpers/Parameter.php +++ /dev/null @@ -1,31 +0,0 @@ - $value) { - $newKey = $prefix === '' ? $key : $prefix . '[' . $key . ']'; - - if($prefix === '') { - $newKey = $key; - } else { - if(is_numeric($key) && !is_array($value)) { - $newKey = $prefix . '[]'; - } else { - $newKey = $prefix . '[' . $key . ']'; - } - } - - if (is_array($value)) { - $final_query[] = self::encode($value, $newKey); - } else { - $final_query[] = urlencode($newKey) . '=' . urlencode($value); - } - } - - return implode('&', $final_query); - } -} \ No newline at end of file diff --git a/src/HttpClient.php b/src/HttpClient.php index 80390ca..60d317f 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -17,7 +17,7 @@ public function request($opts) $url = $opts['url']; if (isset($opts['params']) && $opts['method'] === 'GET') { - $url .= '?' . http_build_query($opts['params']); + $url .= '?' . preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', http_build_query($opts['params'])); } $ch = curl_init($url); @@ -43,7 +43,7 @@ public function request($opts) if (in_array($opts['method'], ['DELETE', 'POST', 'PUT'])) { if (isset($opts['params'])) { - curl_setopt($ch, CURLOPT_POSTFIELDS, \Payrex\Helpers\Parameter::encode($opts['params'])); + curl_setopt($ch, CURLOPT_POSTFIELDS, preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', http_build_query($opts['params']))); } curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $opts['method']); curl_setopt($ch, CURLOPT_POST, 1);