Merge pull request #17473 from eileenmcnaughton/anet
[civicrm-core.git] / CRM / Admin / Page / PaymentProcessor.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
ce064e4f 19 * Page for displaying list of payment processors.
6a488035
TO
20 */
21class CRM_Admin_Page_PaymentProcessor extends CRM_Core_Page_Basic {
22
23 /**
eceb18cc 24 * The action links that we need to display for the browse screen.
6a488035
TO
25 *
26 * @var array
6a488035 27 */
62d3ee27 28 public static $_links = NULL;
6a488035
TO
29
30 /**
eceb18cc 31 * Get BAO Name.
6a488035 32 *
a6c01b45
CW
33 * @return string
34 * Classname of BAO.
6a488035 35 */
00be9182 36 public function getBAOName() {
6a488035
TO
37 return 'CRM_Financial_BAO_PaymentProcessor';
38 }
39
40 /**
eceb18cc 41 * Get action Links.
6a488035 42 *
a6c01b45
CW
43 * @return array
44 * (reference) of action links
6a488035 45 */
00be9182 46 public function &links() {
6a488035
TO
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'),
4d17a233 57 'ref' => 'crm-enable-disable',
6a488035
TO
58 'title' => ts('Disable Payment Processor'),
59 ),
60 CRM_Core_Action::ENABLE => array(
61 'name' => ts('Enable'),
4d17a233 62 'ref' => 'crm-enable-disable',
6a488035
TO
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.
6a488035 82 */
00be9182 83 public function run() {
6a488035
TO
84 // set title and breadcrumb
85 CRM_Utils_System::setTitle(ts('Settings - Payment Processor'));
71d085fe 86 //CRM-15546
353ffa53 87 $paymentProcessorTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_PaymentProcessor', 'payment_processor_type_id', array(
5d4fcf54
TO
88 'labelColumn' => 'name',
89 'flip' => 1,
90 ));
71d085fe 91 $this->assign('defaultPaymentProcessorType', $paymentProcessorTypes['PayPal']);
353ffa53
TO
92 $breadCrumb = array(
93 array(
94 'title' => ts('Administration'),
6a488035 95 'url' => CRM_Utils_System::url('civicrm/admin',
353ffa53 96 'reset=1'
6a488035 97 ),
389bcebf 98 ),
353ffa53 99 );
6a488035
TO
100 CRM_Utils_System::appendBreadCrumb($breadCrumb);
101 return parent::run();
102 }
103
104 /**
105 * Browse all payment processors.
106 *
77b97be7 107 * @param null $action
6a488035 108 */
00be9182 109 public function browse($action = NULL) {
6a488035 110 // get all custom groups sorted by weight
affcc9d2 111 $paymentProcessor = [];
6a488035 112 $dao = new CRM_Financial_DAO_PaymentProcessor();
353ffa53
TO
113 $dao->is_test = 0;
114 $dao->domain_id = CRM_Core_Config::domainID();
6a488035
TO
115 $dao->orderBy('name');
116 $dao->find();
117
118 while ($dao->fetch()) {
affcc9d2 119 $paymentProcessor[$dao->id] = [];
6a488035 120 CRM_Core_DAO::storeValues($dao, $paymentProcessor[$dao->id]);
56085cc7 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 );
6a488035
TO
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,
87dab4a4
AH
137 array('id' => $dao->id),
138 ts('more'),
139 FALSE,
140 'paymentProcessor.manage.action',
141 'PaymentProcessor',
142 $dao->id
6a488035 143 );
74afdc40 144 $paymentProcessor[$dao->id]['financialAccount'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($dao->id, NULL, 'civicrm_payment_processor', 'financial_account_id.name');
59972452 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 }
6a488035
TO
152 }
153
154 $this->assign('rows', $paymentProcessor);
155 }
156
157 /**
eceb18cc 158 * Get name of edit form.
6a488035 159 *
a6c01b45
CW
160 * @return string
161 * Classname of edit form.
6a488035 162 */
00be9182 163 public function editForm() {
6a488035
TO
164 return 'CRM_Admin_Form_PaymentProcessor';
165 }
166
167 /**
eceb18cc 168 * Get edit form name.
6a488035 169 *
a6c01b45
CW
170 * @return string
171 * name of this page.
6a488035 172 */
00be9182 173 public function editName() {
6a488035
TO
174 return 'Payment Processors';
175 }
176
177 /**
178 * Get user context.
179 *
da6b46f4
EM
180 * @param null $mode
181 *
a6c01b45
CW
182 * @return string
183 * user context.
6a488035 184 */
00be9182 185 public function userContext($mode = NULL) {
6a488035
TO
186 return 'civicrm/admin/paymentProcessor';
187 }
96025800 188
6a488035 189}