3 namespace Civi\Payment
;
7 * @package Civi\Payment
14 private static $singleton;
19 private $cache = array();
22 * @return \Civi\Payment\System
24 public static function singleton() {
25 if (!self
::$singleton) {
26 self
::$singleton = new self();
28 return self
::$singleton;
32 * @param array $processor
33 * @throws \CRM_Core_Exception
35 public function getByProcessor($processor) {
36 $id = $processor['id'];
38 if (!isset($this->cache
[$id])) {
39 if (!isset($this->cache
[$id])) {
40 //does this config need to be called?
41 $config = \CRM_Core_Config
::singleton();
42 $ext = \CRM_Extension_System
::singleton()->getMapper();
43 if ($ext->isExtensionKey($processor['class_name'])) {
44 $paymentClass = $ext->keyToClass($processor['class_name'], 'payment');
45 require_once $ext->classToPath($paymentClass);
48 $paymentClass = 'CRM_Core_' . $processor['class_name'];
49 if (empty($paymentClass)) {
50 throw new \
CRM_Core_Exception('no class provided');
52 require_once str_replace('_', DIRECTORY_SEPARATOR
, $paymentClass) . '.php';
55 $this->cache
[$id] = new $paymentClass($processor['is_test'] ?
'test' : 'live', $processor);
58 return $this->cache
[$id];
63 * @throws \CiviCRM_API3_Exception
65 public function getById($id) {
66 $processor = civicrm_api3('payment_processor', 'get_single', array('id' => $id));
67 return self
::getByProcessor($processor);
72 * @param bool $is_test
73 * @throws \CiviCRM_API3_Exception
75 public function getByName($name, $is_test) {
76 $processor = civicrm_api3('payment_processor', 'get_single', array('name' => $name, 'is_test' => $is_test));
77 return self
::getByProcessor($processor);
81 * Flush processors from static cache.
83 * This is particularly used for tests.
86 public function flushProcessors() {
87 $this->cache
= array();