Merge pull request #17473 from eileenmcnaughton/anet
[civicrm-core.git] / CRM / Admin / Page / PaymentProcessor.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of payment processors.
20 */
21 class CRM_Admin_Page_PaymentProcessor extends CRM_Core_Page_Basic {
22
23 /**
24 * The action links that we need to display for the browse screen.
25 *
26 * @var array
27 */
28 public static $_links = NULL;
29
30 /**
31 * Get BAO Name.
32 *
33 * @return string
34 * Classname of BAO.
35 */
36 public function getBAOName() {
37 return 'CRM_Financial_BAO_PaymentProcessor';
38 }
39
40 /**
41 * Get action Links.
42 *
43 * @return array
44 * (reference) of action links
45 */
46 public function &links() {
47 if (!(self::$_links)) {
48 self::$_links = array(
49 CRM_Core_Action::UPDATE => array(
50 'name' => ts('Edit'),
51 'url' => 'civicrm/admin/paymentProcessor',
52 'qs' => 'action=update&id=%%id%%&reset=1',
53 'title' => ts('Edit Payment Processor'),
54 ),
55 CRM_Core_Action::DISABLE => array(
56 'name' => ts('Disable'),
57 'ref' => 'crm-enable-disable',
58 'title' => ts('Disable Payment Processor'),
59 ),
60 CRM_Core_Action::ENABLE => array(
61 'name' => ts('Enable'),
62 'ref' => 'crm-enable-disable',
63 'title' => ts('Enable Payment Processor'),
64 ),
65 CRM_Core_Action::DELETE => array(
66 'name' => ts('Delete'),
67 'url' => 'civicrm/admin/paymentProcessor',
68 'qs' => 'action=delete&id=%%id%%',
69 'title' => ts('Delete Payment Processor'),
70 ),
71 );
72 }
73 return self::$_links;
74 }
75
76 /**
77 * Run the page.
78 *
79 * This method is called after the page is created. It checks for the
80 * type of action and executes that action.
81 * Finally it calls the parent's run method.
82 */
83 public function run() {
84 // set title and breadcrumb
85 CRM_Utils_System::setTitle(ts('Settings - Payment Processor'));
86 //CRM-15546
87 $paymentProcessorTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_PaymentProcessor', 'payment_processor_type_id', array(
88 'labelColumn' => 'name',
89 'flip' => 1,
90 ));
91 $this->assign('defaultPaymentProcessorType', $paymentProcessorTypes['PayPal']);
92 $breadCrumb = array(
93 array(
94 'title' => ts('Administration'),
95 'url' => CRM_Utils_System::url('civicrm/admin',
96 'reset=1'
97 ),
98 ),
99 );
100 CRM_Utils_System::appendBreadCrumb($breadCrumb);
101 return parent::run();
102 }
103
104 /**
105 * Browse all payment processors.
106 *
107 * @param null $action
108 */
109 public function browse($action = NULL) {
110 // get all custom groups sorted by weight
111 $paymentProcessor = [];
112 $dao = new CRM_Financial_DAO_PaymentProcessor();
113 $dao->is_test = 0;
114 $dao->domain_id = CRM_Core_Config::domainID();
115 $dao->orderBy('name');
116 $dao->find();
117
118 while ($dao->fetch()) {
119 $paymentProcessor[$dao->id] = [];
120 CRM_Core_DAO::storeValues($dao, $paymentProcessor[$dao->id]);
121 $paymentProcessor[$dao->id]['payment_processor_type'] = CRM_Core_PseudoConstant::getLabel(
122 'CRM_Financial_DAO_PaymentProcessor', 'payment_processor_type_id', $dao->payment_processor_type_id
123 );
124
125 // form all action links
126 $action = array_sum(array_keys($this->links()));
127
128 // update enable/disable links.
129 if ($dao->is_active) {
130 $action -= CRM_Core_Action::ENABLE;
131 }
132 else {
133 $action -= CRM_Core_Action::DISABLE;
134 }
135
136 $paymentProcessor[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
137 array('id' => $dao->id),
138 ts('more'),
139 FALSE,
140 'paymentProcessor.manage.action',
141 'PaymentProcessor',
142 $dao->id
143 );
144 $paymentProcessor[$dao->id]['financialAccount'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($dao->id, NULL, 'civicrm_payment_processor', 'financial_account_id.name');
145
146 try {
147 $paymentProcessor[$dao->id]['test_id'] = CRM_Financial_BAO_PaymentProcessor::getTestProcessorId($dao->id);
148 }
149 catch (CiviCRM_API3_Exception $e) {
150 CRM_Core_Session::setStatus(ts('No test processor entry exists for %1. Not having a test entry for each processor could cause problems', [$dao->name]));
151 }
152 }
153
154 $this->assign('rows', $paymentProcessor);
155 }
156
157 /**
158 * Get name of edit form.
159 *
160 * @return string
161 * Classname of edit form.
162 */
163 public function editForm() {
164 return 'CRM_Admin_Form_PaymentProcessor';
165 }
166
167 /**
168 * Get edit form name.
169 *
170 * @return string
171 * name of this page.
172 */
173 public function editName() {
174 return 'Payment Processors';
175 }
176
177 /**
178 * Get user context.
179 *
180 * @param null $mode
181 *
182 * @return string
183 * user context.
184 */
185 public function userContext($mode = NULL) {
186 return 'civicrm/admin/paymentProcessor';
187 }
188
189 }