Merge pull request #766 from eileenmcnaughton/test-fix
[civicrm-core.git] / api / v3 / PaymentProcessorType.php
1 <?php
2 // $Id$
3
4 /*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28 */
29
30 /**
31 * new version of civicrm apis. See blog post at
32 * http://civicrm.org/node/131
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Contact
36 * @copyright CiviCRM LLC (c) 2004-2013
37 * $Id: PaymentProcessorType.php 30415 2010-10-29 12:02:47Z shot $
38 *
39 */
40
41 /**
42 * Include common API util functions
43 */
44
45 /**
46 * Function to create payment_processor type
47 *
48 * @param array $params Associative array of property name/value pairs to insert in new payment_processor type.
49 *
50 * @return Newly created PaymentProcessor_type object
51 * {@getfields PaymentProcessorType_create}
52 * @access public
53 * {@schema Core/PaymentProcessorType.xml}
54 */
55 function civicrm_api3_payment_processor_type_create($params) {
56 $ids = array();
57 if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
58 return civicrm_api3_create_error('Invalid value for payment_processor type ID');
59 }
60
61 $payProcType = new CRM_Financial_BAO_PaymentProcessorType();
62 $payProcType = CRM_Financial_BAO_PaymentProcessorType::create($params);
63
64 $relType = array();
65
66 _civicrm_api3_object_to_array($payProcType, $relType[$payProcType->id]);
67
68 return civicrm_api3_create_success($relType, $params, 'payment_processor_type', 'create', $payProcType);
69 }
70
71 /**
72 * Adjust Metadata for Create action
73 *
74 * The metadata is used for setting defaults, documentation & validation
75 * @param array $params array or parameters determined by getfields
76 */
77 function _civicrm_api3_payment_processor_type_create_spec(&$params) {
78 $params['billing_mode']['api.required'] = 1;
79 $params['class_name']['api.required'] = 1;
80 $params['is_active']['api.default'] = 1;
81 $params['is_recur']['api.default'] = FALSE;
82 // FIXME bool support // $params['is_recur']['api.required'] = 1;
83 $params['name']['api.required'] = 1;
84 $params['title']['api.required'] = 1;
85 }
86
87 /**
88 * Function to get all payment_processor type
89 * retruns An array of PaymentProcessor_type
90 * @access public
91 * {@getfields PaymentProcessorType_get}
92 * @example PaymentProcessorTypeGet.php
93 */
94 function civicrm_api3_payment_processor_type_get($params) {
95 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
96 }
97
98 /**
99 * Delete a payment_processor type delete
100 *
101 * @param id of payment_processor type $id
102 *
103 * @return array API Result Array
104 * {@getfields PaymentProcessorType_delete}
105 * @static void
106 * @access public
107 */
108 function civicrm_api3_payment_processor_type_delete($params) {
109 if ($params['id'] != NULL && !CRM_Utils_Rule::integer($params['id'])) {
110 return civicrm_api3_create_error('Invalid value for payment processor type ID');
111 }
112
113 $payProcTypeBAO = new CRM_Financial_BAO_PaymentProcessorType();
114 $result = $payProcTypeBAO->del($params['id']);
115 if (!$result) {
116 return civicrm_api3_create_error('Could not delete payment processor type');
117 }
118 return civicrm_api3_create_success($result, $params, 'payment_processor_type', 'delete', $payProcTypeBAO);
119 }