. * */ namespace Vvveb\System; use Vvveb\System\Cart\Cart; class Payment { private $driver; private $methods = []; private $instances = []; private $instance; public static function getInstance($options = []) { static $inst = null; if ($inst === null) { $inst = new Payment($options); } return $inst; } public function __construct($options = []) { } public function getMethods(&$checkoutInfo) { $data = []; foreach ($this->methods as $name => $method) { list($class, $options) = $method; $obj = new $class(Cart::getInstance()); $this->instances[$name] = $obj; $paymentData = $obj->getMethod($checkoutInfo, $options); //if payment method returns false or no data then don't add it to the list if ($paymentData) { $data[$name] = $paymentData; } } return $data; } public function registerMethod($method, $class, $options = []) { $this->methods[$method] = [$class, $options]; } public function setMethod($method) { foreach ($this->instances as $instance) { $instance->init(); } if (isset($this->instances[$method])) { $this->instance = $this->instances[$method]; $this->instance->setMethod(); } } public function authorize(&$checkoutInfo = []) { if ($this->instance) { $this->instance->authorize($checkoutInfo); } } }