| 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 | require_once 'CRM/Financial/BAO/PaymentProcessorType.php'; |
| 45 | |
| 46 | /** |
| 47 | * Function to create payment_processor type |
| 48 | * |
| 49 | * @param array $params Associative array of property name/value pairs to insert in new payment_processor type. |
| 50 | * |
| 51 | * @return Newly created PaymentProcessor_type object |
| 52 | * {@getfields PaymentProcessorType_create} |
| 53 | * @access public |
| 54 | * {@schema Core/PaymentProcessorType.xml} |
| 55 | */ |
| 56 | function civicrm_api3_payment_processor_type_create($params) { |
| 57 | require_once 'CRM/Utils/Rule.php'; |
| 58 | |
| 59 | $ids = array(); |
| 60 | if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { |
| 61 | return civicrm_api3_create_error('Invalid value for payment_processor type ID'); |
| 62 | } |
| 63 | |
| 64 | $payProcType = new CRM_Financial_BAO_PaymentProcessorType(); |
| 65 | $payProcType = CRM_Financial_BAO_PaymentProcessorType::create($params); |
| 66 | |
| 67 | $relType = array(); |
| 68 | |
| 69 | _civicrm_api3_object_to_array($payProcType, $relType[$payProcType->id]); |
| 70 | |
| 71 | return civicrm_api3_create_success($relType, $params, 'payment_processor_type', 'create', $payProcType); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Adjust Metadata for Create action |
| 76 | * |
| 77 | * The metadata is used for setting defaults, documentation & validation |
| 78 | * @param array $params array or parameters determined by getfields |
| 79 | */ |
| 80 | function _civicrm_api3_payment_processor_type_create_spec(&$params) { |
| 81 | $params['billing_mode']['api.required'] = 1; |
| 82 | $params['class_name']['api.required'] = 1; |
| 83 | $params['is_active']['api.default'] = 1; |
| 84 | $params['is_recur']['api.default'] = FALSE; |
| 85 | // FIXME bool support // $params['is_recur']['api.required'] = 1; |
| 86 | $params['name']['api.required'] = 1; |
| 87 | $params['title']['api.required'] = 1; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Function to get all payment_processor type |
| 92 | * retruns An array of PaymentProcessor_type |
| 93 | * @access public |
| 94 | * {@getfields PaymentProcessorType_get} |
| 95 | * @example PaymentProcessorTypeGet.php |
| 96 | */ |
| 97 | function civicrm_api3_payment_processor_type_get($params) { |
| 98 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Delete a payment_processor type delete |
| 103 | * |
| 104 | * @param id of payment_processor type $id |
| 105 | * |
| 106 | * @return array API Result Array |
| 107 | * {@getfields PaymentProcessorType_delete} |
| 108 | * @static void |
| 109 | * @access public |
| 110 | */ |
| 111 | function civicrm_api3_payment_processor_type_delete($params) { |
| 112 | |
| 113 | require_once 'CRM/Utils/Rule.php'; |
| 114 | if ($params['id'] != NULL && !CRM_Utils_Rule::integer($params['id'])) { |
| 115 | return civicrm_api3_create_error('Invalid value for payment processor type ID'); |
| 116 | } |
| 117 | |
| 118 | $payProcTypeBAO = new CRM_Financial_BAO_PaymentProcessorType(); |
| 119 | $result = $payProcTypeBAO->del($params['id']); |
| 120 | if (!$result) { |
| 121 | return civicrm_api3_create_error('Could not delete payment processor type'); |
| 122 | } |
| 123 | return civicrm_api3_create_success($result, $params, 'payment_processor_type', 'delete', $payProcTypeBAO); |
| 124 | } |