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;
29 public $submitOnce = TRUE;
31 public function preProcess() {
37 'label' => ts('Name'),
42 'label' => ts('Title'),
46 'name' => 'billing_mode',
47 'label' => ts('Billing Mode'),
49 'rule' => 'positiveInteger',
50 'msg' => ts('Enter a positive integer'),
53 'name' => 'description',
54 'label' => ts('Description'),
57 'name' => 'user_name_label',
58 'label' => ts('User Name Label'),
61 'name' => 'password_label',
62 'label' => ts('Password Label'),
65 'name' => 'signature_label',
66 'label' => ts('Signature Label'),
69 'name' => 'subject_label',
70 'label' => ts('Subject Label'),
73 'name' => 'class_name',
74 'label' => ts('PHP class name'),
78 'name' => 'url_site_default',
79 'label' => ts('Live Site URL'),
82 'msg' => ts('Enter a valid URL'),
85 'name' => 'url_api_default',
86 'label' => ts('Live API URL'),
89 'msg' => ts('Enter a valid URL'),
92 'name' => 'url_recur_default',
93 'label' => ts('Live Recurring Payments URL'),
96 'msg' => ts('Enter a valid URL'),
99 'name' => 'url_button_default',
100 'label' => ts('Live Button URL'),
102 'msg' => ts('Enter a valid URL'),
105 'name' => 'url_site_test_default',
106 'label' => ts('Test Site URL'),
109 'msg' => ts('Enter a valid URL'),
112 'name' => 'url_api_test_default',
113 'label' => ts('Test API URL'),
116 'msg' => ts('Enter a valid URL'),
119 'name' => 'url_recur_test_default',
120 'label' => ts('Test Recurring Payments URL'),
123 'msg' => ts('Enter a valid URL'),
126 'name' => 'url_button_test_default',
127 'label' => ts('Test Button URL'),
129 'msg' => ts('Enter a valid URL'),
135 * Build the form object.
139 public function buildQuickForm($check = FALSE) {
140 parent
::buildQuickForm();
142 if ($this->_action
& CRM_Core_Action
::DELETE
) {
146 $attributes = CRM_Core_DAO
::getAttribute('CRM_Financial_DAO_PaymentProcessorType');
148 foreach ($this->_fields
as $field) {
149 $required = CRM_Utils_Array
::value('required', $field, FALSE);
150 $this->add('text', $field['name'],
151 $field['label'], $attributes['name'], $required
153 if (!empty($field['rule'])) {
154 $this->addRule($field['name'], $field['msg'], $field['rule']);
158 // is this processor active ?
159 $this->add('checkbox', 'is_active', ts('Is this Payment Processor Type active?'));
160 $this->add('checkbox', 'is_default', ts('Is this Payment Processor Type the default?'));
161 $this->add('checkbox', 'is_recur', ts('Does this Payment Processor Type support recurring donations?'));
167 public function setDefaultValues() {
171 $defaults['is_active'] = $defaults['is_default'] = 1;
172 $defaults['user_name_label'] = ts('User Name');
173 $defaults['password_label'] = ts('Password');
174 $defaults['signature_label'] = ts('Signature');
175 $defaults['subject_label'] = ts('Subject');
179 $dao = new CRM_Financial_DAO_PaymentProcessorType();
180 $dao->id
= $this->_id
;
182 if (!$dao->find(TRUE)) {
186 CRM_Core_DAO
::storeValues($dao, $defaults);
192 * Process the form submission.
194 public function postProcess() {
195 CRM_Utils_System
::flushCache();
197 if ($this->_action
& CRM_Core_Action
::DELETE
) {
198 CRM_Financial_BAO_PaymentProcessorType
::del($this->_id
);
202 $values = $this->controller
->exportValues($this->_name
);
204 if (!empty($values['is_default'])) {
206 UPDATE civicrm_payment_processor SET is_default = 0";
207 CRM_Core_DAO
::executeQuery($query);
210 $dao = new CRM_Financial_DAO_PaymentProcessorType();
212 $dao->id
= $this->_id
;
213 $dao->is_default
= CRM_Utils_Array
::value('is_default', $values, 0);
214 $dao->is_active
= CRM_Utils_Array
::value('is_active', $values, 0);
215 $dao->is_recur
= CRM_Utils_Array
::value('is_recur', $values, 0);
217 $dao->name
= $values['name'];
218 $dao->description
= $values['description'];
220 foreach ($this->_fields
as $field) {
221 $dao->{$field['name']} = trim($values[$field['name']]);
222 if (empty($dao->{$field['name']})) {
223 $dao->{$field['name']} = 'null';