3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Location Type.
21 class CRM_Admin_Form_PaymentProcessorType
extends CRM_Admin_Form
{
24 protected $_fields = NULL;
26 public function preProcess() {
32 'label' => ts('Name'),
37 'label' => ts('Title'),
41 'name' => 'billing_mode',
42 'label' => ts('Billing Mode'),
44 'rule' => 'positiveInteger',
45 'msg' => ts('Enter a positive integer'),
48 'name' => 'description',
49 'label' => ts('Description'),
52 'name' => 'user_name_label',
53 'label' => ts('User Name Label'),
56 'name' => 'password_label',
57 'label' => ts('Password Label'),
60 'name' => 'signature_label',
61 'label' => ts('Signature Label'),
64 'name' => 'subject_label',
65 'label' => ts('Subject Label'),
68 'name' => 'class_name',
69 'label' => ts('PHP class name'),
73 'name' => 'url_site_default',
74 'label' => ts('Live Site URL'),
77 'msg' => ts('Enter a valid URL'),
80 'name' => 'url_api_default',
81 'label' => ts('Live API URL'),
84 'msg' => ts('Enter a valid URL'),
87 'name' => 'url_recur_default',
88 'label' => ts('Live Recurring Payments URL'),
91 'msg' => ts('Enter a valid URL'),
94 'name' => 'url_button_default',
95 'label' => ts('Live Button URL'),
97 'msg' => ts('Enter a valid URL'),
100 'name' => 'url_site_test_default',
101 'label' => ts('Test Site URL'),
104 'msg' => ts('Enter a valid URL'),
107 'name' => 'url_api_test_default',
108 'label' => ts('Test API URL'),
111 'msg' => ts('Enter a valid URL'),
114 'name' => 'url_recur_test_default',
115 'label' => ts('Test Recurring Payments URL'),
118 'msg' => ts('Enter a valid URL'),
121 'name' => 'url_button_test_default',
122 'label' => ts('Test Button URL'),
124 'msg' => ts('Enter a valid URL'),
130 * Build the form object.
134 public function buildQuickForm($check = FALSE) {
135 parent
::buildQuickForm();
137 if ($this->_action
& CRM_Core_Action
::DELETE
) {
141 $attributes = CRM_Core_DAO
::getAttribute('CRM_Financial_DAO_PaymentProcessorType');
143 foreach ($this->_fields
as $field) {
144 $required = CRM_Utils_Array
::value('required', $field, FALSE);
145 $this->add('text', $field['name'],
146 $field['label'], $attributes['name'], $required
148 if (!empty($field['rule'])) {
149 $this->addRule($field['name'], $field['msg'], $field['rule']);
153 // is this processor active ?
154 $this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?'));
155 $this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?'));
156 $this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?'));
162 public function setDefaultValues() {
166 $defaults['is_active'] = $defaults['is_default'] = 1;
167 $defaults['user_name_label'] = ts('User Name');
168 $defaults['password_label'] = ts('Password');
169 $defaults['signature_label'] = ts('Signature');
170 $defaults['subject_label'] = ts('Subject');
174 $dao = new CRM_Financial_DAO_PaymentProcessorType();
175 $dao->id
= $this->_id
;
177 if (!$dao->find(TRUE)) {
181 CRM_Core_DAO
::storeValues($dao, $defaults);
187 * Process the form submission.
189 public function postProcess() {
190 CRM_Utils_System
::flushCache();
192 if ($this->_action
& CRM_Core_Action
::DELETE
) {
193 CRM_Financial_BAO_PaymentProcessorType
::del($this->_id
);
197 $values = $this->controller
->exportValues($this->_name
);
199 if (!empty($values['is_default'])) {
201 UPDATE civicrm_payment_processor SET is_default = 0";
202 CRM_Core_DAO
::executeQuery($query);
205 $dao = new CRM_Financial_DAO_PaymentProcessorType();
207 $dao->id
= $this->_id
;
208 $dao->is_default
= CRM_Utils_Array
::value('is_default', $values, 0);
209 $dao->is_active
= CRM_Utils_Array
::value('is_active', $values, 0);
210 $dao->is_recur
= CRM_Utils_Array
::value('is_recur', $values, 0);
212 $dao->name
= $values['name'];
213 $dao->description
= $values['description'];
215 foreach ($this->_fields
as $field) {
216 $dao->{$field['name']} = trim($values[$field['name']]);
217 if (empty($dao->{$field['name']})) {
218 $dao->{$field['name']} = 'null';