/** * Returns payment class, identified by $engine variable * * @param string $engine * @param Wpjb_Model_Payment $payment * @return Wpjb_Payment_Interface */ public static function factory(Wpjb_Model_Payment $payment) { $factory = new self(); $engine = $payment->engine; if (!$factory->hasEngine($engine)) { throw new Exception("Payment engine [{$engine}] not registered!"); } $class = $factory->getEngine($engine); $object = new $class($payment); return $object; }