3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
113 * @internal param array $ids the array that holds all the db ids
115 * @return object CRM_Financial_DAO_PaymentProcessorType
119 static function create(&$params) {
120 $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
121 $paymentProcessorType->copyValues($params);
124 // adapted from CRM_Core_Extensions_Payment::install
137 'url_site_test_default',
138 'url_api_test_default',
139 'url_recur_test_default',
140 'url_button_default',
141 'url_button_test_default',
146 if (isset($paymentProcessorType->{$trimmable})) {
147 $paymentProcessorType->{$trimmable} = trim($paymentProcessorType->{$trimmable});
152 if (isset($paymentProcessorType->billing_mode
)) {
153 // ugh unidirectional manipulation
154 if (!is_numeric($paymentProcessorType->billing_mode
)) {
155 $billingModes = array_flip(self
::buildOptions('billing_mode'));
156 if (array_key_exists($paymentProcessorType->billing_mode
, $billingModes)) {
157 $paymentProcessorType->billing_mode
= $billingModes[$paymentProcessorType->billing_mode
];
160 if (!array_key_exists($paymentProcessorType->billing_mode
, self
::buildOptions('billing_mode'))) {
161 throw new Exception("Unrecognized billing_mode");
165 // FIXME handle is_default
166 if (!empty($paymentProcessorType->id
)) {
167 $ppByName = self
::getAllPaymentProcessorTypes('name');
168 if (array_key_exists($paymentProcessorType->name
, $ppByName)) {
169 if ($ppByName[$paymentProcessorType->name
] != $paymentProcessorType->id
) {
170 CRM_Core_Error
::fatal('This payment processor type already exists.');
175 return $paymentProcessorType->save();
179 * Function to delete payment processor
181 * @param int $paymentProcessorTypeId ID of the processor to be deleted.
187 static function del($paymentProcessorTypeId) {
189 SELECT pp.id processor_id
190 FROM civicrm_payment_processor pp, civicrm_payment_processor_type ppt
191 WHERE pp.payment_processor_type_id = ppt.id AND ppt.id = %1";
193 $params = array(1 => array($paymentProcessorTypeId, 'Integer'));
194 $dao = CRM_Core_DAO
::executeQuery($query, $params);
197 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');
201 $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
202 $paymentProcessorType->id
= $paymentProcessorTypeId;
203 if ($paymentProcessorType->delete()) {
204 CRM_Core_Session
::setStatus(ts('Selected Payment Processor type has been deleted.<br>'), '', 'success');
214 static private function getAllPaymentProcessorTypes($attr) {
216 $dao = new CRM_Financial_DAO_PaymentProcessorType();
218 while ($dao->fetch()) {
219 $ppt[$dao->$attr] = $dao->id
;