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)