Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
ce064e4f | 35 | * This class generates form components for Location Type. |
6a488035 TO |
36 | */ |
37 | class CRM_Admin_Form_PaymentProcessorType extends CRM_Admin_Form { | |
38 | protected $_id = NULL; | |
39 | ||
40 | protected $_fields = NULL; | |
41 | ||
00be9182 | 42 | public function preProcess() { |
6a488035 TO |
43 | parent::preProcess(); |
44 | ||
be2fb01f CW |
45 | $this->_fields = [ |
46 | [ | |
6a488035 TO |
47 | 'name' => 'name', |
48 | 'label' => ts('Name'), | |
49 | 'required' => TRUE, | |
be2fb01f CW |
50 | ], |
51 | [ | |
6a488035 TO |
52 | 'name' => 'title', |
53 | 'label' => ts('Title'), | |
54 | 'required' => TRUE, | |
be2fb01f CW |
55 | ], |
56 | [ | |
6a488035 TO |
57 | 'name' => 'billing_mode', |
58 | 'label' => ts('Billing Mode'), | |
59 | 'required' => TRUE, | |
60 | 'rule' => 'positiveInteger', | |
61 | 'msg' => ts('Enter a positive integer'), | |
be2fb01f CW |
62 | ], |
63 | [ | |
6a488035 TO |
64 | 'name' => 'description', |
65 | 'label' => ts('Description'), | |
be2fb01f CW |
66 | ], |
67 | [ | |
6a488035 TO |
68 | 'name' => 'user_name_label', |
69 | 'label' => ts('User Name Label'), | |
be2fb01f CW |
70 | ], |
71 | [ | |
6a488035 TO |
72 | 'name' => 'password_label', |
73 | 'label' => ts('Password Label'), | |
be2fb01f CW |
74 | ], |
75 | [ | |
6a488035 TO |
76 | 'name' => 'signature_label', |
77 | 'label' => ts('Signature Label'), | |
be2fb01f CW |
78 | ], |
79 | [ | |
6a488035 TO |
80 | 'name' => 'subject_label', |
81 | 'label' => ts('Subject Label'), | |
be2fb01f CW |
82 | ], |
83 | [ | |
6a488035 TO |
84 | 'name' => 'class_name', |
85 | 'label' => ts('PHP class name'), | |
86 | 'required' => TRUE, | |
be2fb01f CW |
87 | ], |
88 | [ | |
6a488035 TO |
89 | 'name' => 'url_site_default', |
90 | 'label' => ts('Live Site URL'), | |
91 | 'required' => TRUE, | |
92 | 'rule' => 'url', | |
93 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
94 | ], |
95 | [ | |
6a488035 TO |
96 | 'name' => 'url_api_default', |
97 | 'label' => ts('Live API URL'), | |
98 | 'required' => FALSE, | |
99 | 'rule' => 'url', | |
100 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
101 | ], |
102 | [ | |
6a488035 TO |
103 | 'name' => 'url_recur_default', |
104 | 'label' => ts('Live Recurring Payments URL'), | |
105 | 'required' => TRUE, | |
106 | 'rule' => 'url', | |
107 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
108 | ], |
109 | [ | |
6a488035 TO |
110 | 'name' => 'url_button_default', |
111 | 'label' => ts('Live Button URL'), | |
112 | 'rule' => 'url', | |
113 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
114 | ], |
115 | [ | |
6a488035 TO |
116 | 'name' => 'url_site_test_default', |
117 | 'label' => ts('Test Site URL'), | |
118 | 'required' => TRUE, | |
119 | 'rule' => 'url', | |
120 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
121 | ], |
122 | [ | |
6a488035 TO |
123 | 'name' => 'url_api_test_default', |
124 | 'label' => ts('Test API URL'), | |
125 | 'required' => FALSE, | |
126 | 'rule' => 'url', | |
127 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
128 | ], |
129 | [ | |
6a488035 TO |
130 | 'name' => 'url_recur_test_default', |
131 | 'label' => ts('Test Recurring Payments URL'), | |
132 | 'required' => TRUE, | |
133 | 'rule' => 'url', | |
134 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
135 | ], |
136 | [ | |
6a488035 TO |
137 | 'name' => 'url_button_test_default', |
138 | 'label' => ts('Test Button URL'), | |
139 | 'rule' => 'url', | |
140 | 'msg' => ts('Enter a valid URL'), | |
be2fb01f CW |
141 | ], |
142 | ]; | |
6a488035 TO |
143 | } |
144 | ||
145 | /** | |
eceb18cc | 146 | * Build the form object. |
6a488035 | 147 | * |
dd244018 | 148 | * @param bool $check |
6a488035 TO |
149 | */ |
150 | public function buildQuickForm($check = FALSE) { | |
151 | parent::buildQuickForm(); | |
152 | ||
153 | if ($this->_action & CRM_Core_Action::DELETE) { | |
154 | return; | |
155 | } | |
156 | ||
481a74f4 | 157 | $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessorType'); |
6a488035 TO |
158 | |
159 | foreach ($this->_fields as $field) { | |
160 | $required = CRM_Utils_Array::value('required', $field, FALSE); | |
161 | $this->add('text', $field['name'], | |
162 | $field['label'], $attributes['name'], $required | |
163 | ); | |
a7488080 | 164 | if (!empty($field['rule'])) { |
6a488035 TO |
165 | $this->addRule($field['name'], $field['msg'], $field['rule']); |
166 | } | |
167 | } | |
168 | ||
169 | // is this processor active ? | |
170 | $this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?')); | |
171 | $this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?')); | |
172 | $this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?')); | |
173 | } | |
174 | ||
e0ef6999 EM |
175 | /** |
176 | * @return array | |
177 | */ | |
00be9182 | 178 | public function setDefaultValues() { |
be2fb01f | 179 | $defaults = []; |
6a488035 TO |
180 | |
181 | if (!$this->_id) { | |
182 | $defaults['is_active'] = $defaults['is_default'] = 1; | |
183 | $defaults['user_name_label'] = ts('User Name'); | |
184 | $defaults['password_label'] = ts('Password'); | |
185 | $defaults['signature_label'] = ts('Signature'); | |
186 | $defaults['subject_label'] = ts('Subject'); | |
187 | return $defaults; | |
188 | } | |
189 | ||
481a74f4 | 190 | $dao = new CRM_Financial_DAO_PaymentProcessorType(); |
6a488035 TO |
191 | $dao->id = $this->_id; |
192 | ||
193 | if (!$dao->find(TRUE)) { | |
194 | return $defaults; | |
195 | } | |
196 | ||
197 | CRM_Core_DAO::storeValues($dao, $defaults); | |
198 | ||
199 | return $defaults; | |
200 | } | |
201 | ||
202 | /** | |
eceb18cc | 203 | * Process the form submission. |
6a488035 TO |
204 | */ |
205 | public function postProcess() { | |
d7d6c461 | 206 | CRM_Utils_System::flushCache(); |
6a488035 TO |
207 | |
208 | if ($this->_action & CRM_Core_Action::DELETE) { | |
209 | CRM_Financial_BAO_PaymentProcessorType::del($this->_id); | |
210 | return; | |
211 | } | |
212 | ||
213 | $values = $this->controller->exportValues($this->_name); | |
214 | ||
a7488080 | 215 | if (!empty($values['is_default'])) { |
6a488035 TO |
216 | $query = " |
217 | UPDATE civicrm_payment_processor SET is_default = 0"; | |
33621c4f | 218 | CRM_Core_DAO::executeQuery($query); |
6a488035 TO |
219 | } |
220 | ||
481a74f4 | 221 | $dao = new CRM_Financial_DAO_PaymentProcessorType(); |
6a488035 | 222 | |
353ffa53 | 223 | $dao->id = $this->_id; |
6a488035 | 224 | $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0); |
353ffa53 TO |
225 | $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0); |
226 | $dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0); | |
6a488035 TO |
227 | |
228 | $dao->name = $values['name']; | |
229 | $dao->description = $values['description']; | |
230 | ||
231 | foreach ($this->_fields as $field) { | |
232 | $dao->{$field['name']} = trim($values[$field['name']]); | |
233 | if (empty($dao->{$field['name']})) { | |
234 | $dao->{$field['name']} = 'null'; | |
235 | } | |
236 | } | |
237 | $dao->save(); | |
238 | } | |
96025800 | 239 | |
6a488035 | 240 | } |