From 5f4e400dfa608453058947bdaee722373d608ea8 Mon Sep 17 00:00:00 2001 From: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com> Date: Wed, 11 Jan 2023 11:24:37 +0100 Subject: [PATCH] Move Payment Gateways into folders (#630) * Update ServicePayGateway * Resolve issues with crappy naming * Resolve issues with auto loading --- src/modules/Invoice/ServicePayGateway.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/modules/Invoice/ServicePayGateway.php b/src/modules/Invoice/ServicePayGateway.php index 0cdb3f168..d3b10ed04 100644 --- a/src/modules/Invoice/ServicePayGateway.php +++ b/src/modules/Invoice/ServicePayGateway.php @@ -92,6 +92,16 @@ class ServicePayGateway implements InjectionAwareInterface $adapters[] = $adapter; } } + $pattern = PATH_LIBRARY . '/Payment/Adapter/*/*.php'; + foreach (glob($pattern) as $path) { + $directory = explode('/',pathinfo($path, PATHINFO_DIRNAME)); + $adapter = end($directory); + if (!array_key_exists($adapter, $exists)) { + if($path == PATH_LIBRARY . '/Payment/Adapter/'.$adapter.'/'.$adapter.'.php'){ + $adapters[] = $adapter; + } + } + } return $adapters; } @@ -265,7 +275,9 @@ class ServicePayGateway implements InjectionAwareInterface { $class = $this->getAdapterClassName($pg); if (!file_exists(PATH_LIBRARY . '/Payment/Adapter/' . $pg->gateway . '.php')) { - throw new \Box_Exception('Payment gateway :adapter was not found', [':adapter' => $pg->gateway]); + if(!file_exists(PATH_LIBRARY . '/Payment/Adapter/' . $pg->gateway . '/'.$pg->gateway.'.php')){ + throw new \Box_Exception('Payment gateway :adapter was not found', [':adapter' => $pg->gateway]); + } } if (!class_exists($class)) { @@ -283,7 +295,13 @@ class ServicePayGateway implements InjectionAwareInterface public function getAdapterClassName(\Model_PayGateway $pg) { - return sprintf('Payment_Adapter_%s', $pg->gateway); + $class = sprintf('Payment_Adapter_%s', $pg->gateway); + if(!class_exists($class)){ + include PATH_LIBRARY . '/Payment/Adapter/' . $pg->gateway . '/'.$pg->gateway.'.php'; + return sprintf('Payment_Adapter_%s', $pg->gateway); + }else{ + return $class; + } } public function getAcceptedCurrencies(\Model_PayGateway $model)