3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Financial_BAO_PaymentProcessorType
extends CRM_Financial_DAO_PaymentProcessorType
{
38 * static holder for the default payment processor
40 static $_defaultPaymentProcessorType = NULL;
45 function __construct() {
46 parent
::__construct();
50 * Takes a bunch of params that are needed to match certain criteria and
51 * retrieves the relevant objects. Typically the valid params are only
52 * contact_id. We'll tweak this function to be more full featured over a period
53 * of time. This is the inverse function of create. It also stores all the retrieved
54 * values in the default array
56 * @param array $params (reference ) an assoc array of name/value pairs
57 * @param array $defaults (reference ) an assoc array to hold the flattened values
59 * @return object CRM_Core_BAO_LocaationType object on success, null otherwise
63 static function retrieve(&$params, &$defaults) {
64 $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
65 $paymentProcessorType->copyValues($params);
66 if ($paymentProcessorType->find(TRUE)) {
67 CRM_Core_DAO
::storeValues($paymentProcessorType, $defaults);
68 return $paymentProcessorType;
74 * update the is_active flag in the db
76 * @param int $id id of the database record
77 * @param boolean $is_active value we want to set the is_active field
79 * @return Object DAO object on sucess, null otherwise
84 static function setIsActive($id, $is_active) {
85 return CRM_Core_DAO
::setFieldValue('CRM_Financial_DAO_PaymentProcessorType', $id, 'is_active', $is_active);
89 * retrieve the default payment processor
93 * @return object The default payment processor object on success,
98 static function &getDefault() {
99 if (self
::$_defaultPaymentProcessorType == NULL) {
100 $params = array('is_default' => 1);
102 self
::$_defaultPaymentProcessorType = self
::retrieve($params, $defaults);
104 return self
::$_defaultPaymentProcessorType;
108 * Function to add the payment-processor type in the db
110 * @param array $params (reference ) an assoc array of name/value pairs
111 * @param array $ids the array that holds all the db ids
113 * @return object CRM_Financial_DAO_PaymentProcessorType
118 static function create(&$params) {
119 $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
120 $paymentProcessorType->copyValues($params);
123 // adapted from CRM_Core_Extensions_Payment::install
136 'url_site_test_default',
137 'url_api_test_default',
138 'url_recur_test_default',
139 'url_button_default',
140 'url_button_test_default',
145 if (isset($paymentProcessorType->{$trimmable})) {
146 $paymentProcessorType->{$trimmable} = trim($paymentProcessorType->{$trimmable});
151 if (isset($paymentProcessorType->billing_mode
)) {
152 // ugh unidirectional manipulation
153 if (!is_numeric($paymentProcessorType->billing_mode
)) {
154 $billingModes = array_flip(self
::buildOptions('billing_mode'));
155 if (array_key_exists($paymentProcessorType->billing_mode
, $billingModes)) {
156 $paymentProcessorType->billing_mode
= $billingModes[$paymentProcessorType->billing_mode
];
159 if (!array_key_exists($paymentProcessorType->billing_mode
, self
::buildOptions('billing_mode'))) {
160 throw new Exception("Unrecognized billing_mode");
164 // FIXME handle is_default
165 if (!empty($paymentProcessorType->id
)) {
166 $ppByName = self
::getAllPaymentProcessorTypes('name');
167 if (array_key_exists($paymentProcessorType->name
, $ppByName)) {
168 if ($ppByName[$paymentProcessorType->name
] != $paymentProcessorType->id
) {
169 CRM_Core_Error
::fatal('This payment processor type already exists.');
174 return $paymentProcessorType->save();
178 * Function to delete payment processor
180 * @param int $paymentProcessorTypeId ID of the processor to be deleted.
185 static function del($paymentProcessorTypeId) {
187 SELECT pp.id processor_id
188 FROM civicrm_payment_processor pp, civicrm_payment_processor_type ppt
189 WHERE pp.payment_processor_type_id = ppt.id AND ppt.id = %1";
191 $params = array(1 => array($paymentProcessorTypeId, 'Integer'));
192 $dao = CRM_Core_DAO
::executeQuery($query, $params);
195 CRM_Core_Session
::setStatus(ts('There is a Payment Processor associated with selected Payment Processor type, hence it can not be deleted.'), ts('Deletion Error'), 'error');
199 $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
200 $paymentProcessorType->id
= $paymentProcessorTypeId;
201 if ($paymentProcessorType->delete()) {
202 CRM_Core_Session
::setStatus(ts('Selected Payment Processor type has been deleted.<br>'), '', 'success');
207 static private function getAllPaymentProcessorTypes($attr) {
209 $dao = new CRM_Financial_DAO_PaymentProcessorType();
211 while ($dao->fetch()) {
212 $ppt[$dao->$attr] = $dao->id
;
218 * Get options for a given field.
219 * @see CRM_Core_DAO::buildOptions
221 * @param String $fieldName
222 * @param String $context: @see CRM_Core_DAO::buildOptionsContext
223 * @param Array $props: whatever is known about this dao object
225 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
227 // Special logic for fields whose options depend on context or properties
228 switch ($fieldName) {
229 // These options are not in the db
232 CRM_Core_Payment
::BILLING_MODE_FORM
=> 'form',
233 CRM_Core_Payment
::BILLING_MODE_BUTTON
=> 'button',
234 CRM_Core_Payment
::BILLING_MODE_NOTIFY
=> 'notify',
237 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);