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 +--------------------------------------------------------------------+
14 * This api exposes CiviCRM LineItem records.
16 * Line items are sub-components of a complete financial transaction record.
18 * @package CiviCRM_APIv3
22 * Create or update a line_item.
24 * @param array $params
25 * Array of property name/value pairs to insert in new 'line_item'
30 function civicrm_api3_line_item_create($params) {
31 // @todo the following line is not really appropriate for the api. The BAO should
32 // do the work, and it should be in a tighter function. The below function is not really
33 // readable because it is handling contribution and line item together.
34 $params = CRM_Contribute_BAO_Contribution
::checkTaxAmount($params, TRUE);
35 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'LineItem');
39 * Adjust Metadata for Create action.
41 * The metadata is used for setting defaults, documentation & validation.
43 * @param array $params
44 * Array of parameters determined by getfields.
46 function _civicrm_api3_line_item_create_spec(&$params) {
47 $params['entity_id']['api.required'] = 1;
48 $params['qty']['api.required'] = 1;
49 $params['unit_price']['api.required'] = 1;
50 $params['line_total']['api.required'] = 1;
51 $params['label']['api.default'] = 'line item';
55 * Returns array of line_items matching a set of one or more group properties.
57 * @param array $params
58 * Array of one or more valid property_name=>value pairs. If $params is set.
59 * as null, all line_items will be returned (default limit is 25)
62 * Array of matching line_items
64 function civicrm_api3_line_item_get($params) {
65 if (CRM_Financial_BAO_FinancialType
::isACLFinancialTypeStatus() && !empty($params['check_permissions'])) {
66 CRM_Price_BAO_LineItem
::getAPILineItemParams($params);
68 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
72 * Delete an existing LineItem.
74 * This method is used to delete any existing LineItem given its id.
76 * @param array $params
77 * Array containing id of the group to be deleted.
79 * @return array API result array
80 * @throws API_Exception
81 * @throws \CiviCRM_API3_Exception
83 function civicrm_api3_line_item_delete($params) {
84 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);