Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
731a0992 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
c28e1768 | 29 | * This api exposes CiviCRM Pledge payment. |
6a488035 TO |
30 | * |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Pledge_Payment | |
33 | * | |
6a488035 TO |
34 | */ |
35 | ||
6a488035 | 36 | /** |
9d32e6f7 EM |
37 | * Add or update a pledge payment. |
38 | * | |
c28e1768 CW |
39 | * Pledge Payment API doesn't actually add a pledge. |
40 | * If the request is to 'create' and 'id' is not passed in | |
41 | * the oldest pledge with no associated contribution is updated. | |
6a488035 TO |
42 | * |
43 | * @todo possibly add ability to add payment if there are less payments than pledge installments | |
c206647d | 44 | * @todo possibly add ability to recalculate dates if the schedule is changed |
6a488035 | 45 | * |
cf470720 TO |
46 | * @param array $params |
47 | * Input parameters. | |
6a488035 | 48 | * |
a6c01b45 | 49 | * @return array |
72b3a70c | 50 | * API Result |
6a488035 TO |
51 | */ |
52 | function civicrm_api3_pledge_payment_create($params) { | |
53 | ||
54 | $paymentParams = $params; | |
8cc574cf | 55 | if (empty($params['id']) && empty($params['option.create_new'])) { |
6a488035 TO |
56 | $paymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($params['pledge_id']); |
57 | if (empty($paymentDetails)) { | |
58 | return civicrm_api3_create_error("There are no unmatched payment on this pledge. Pass in the pledge_payment id to specify one or 'option.create_new' to create one"); | |
59 | } | |
60 | elseif (is_array($paymentDetails)) { | |
61 | $paymentParams = array_merge($params, $paymentDetails); | |
62 | } | |
63 | } | |
64 | ||
65 | $dao = CRM_Pledge_BAO_PledgePayment::add($paymentParams); | |
906e6120 | 66 | $result = array(); |
9b873358 | 67 | if (empty($dao->pledge_id)) { |
35671d00 | 68 | $dao->find(TRUE); |
6a488035 TO |
69 | } |
70 | _civicrm_api3_object_to_array($dao, $result[$dao->id]); | |
71 | ||
6a488035 TO |
72 | //update pledge status |
73 | CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($dao->pledge_id); | |
74 | ||
75 | return civicrm_api3_create_success($result, $params, 'pledge_payment', 'create', $dao); | |
76 | } | |
11e09c59 TO |
77 | |
78 | /** | |
0aa0303c EM |
79 | * Adjust Metadata for Create action. |
80 | * | |
81 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 82 | * |
cf470720 TO |
83 | * @param array $params |
84 | * Array or parameters determined by getfields. | |
6a488035 TO |
85 | */ |
86 | function _civicrm_api3_pledge_payment_create_spec(&$params) { | |
87 | $params['pledge_id']['api.required'] = 1; | |
88 | $params['status_id']['api.required'] = 1; | |
89 | } | |
90 | ||
91 | /** | |
9d32e6f7 | 92 | * Delete a pledge Payment - Note this deletes the contribution not just the link. |
6a488035 | 93 | * |
cf470720 TO |
94 | * @param array $params |
95 | * Input parameters. | |
6a488035 | 96 | * |
a6c01b45 | 97 | * @return array |
72b3a70c | 98 | * API result |
6a488035 TO |
99 | */ |
100 | function civicrm_api3_pledge_payment_delete($params) { | |
101 | ||
102 | if (CRM_Pledge_BAO_PledgePayment::del($params['id'])) { | |
35671d00 | 103 | return civicrm_api3_create_success(array('id' => $params['id']), $params, 'pledge_payment', 'delete'); |
6a488035 TO |
104 | } |
105 | else { | |
106 | return civicrm_api3_create_error('Could not delete payment'); | |
107 | } | |
108 | } | |
109 | ||
110 | /** | |
9d32e6f7 | 111 | * Retrieve a set of pledges, given a set of input params. |
6a488035 | 112 | * |
cf470720 TO |
113 | * @param array $params |
114 | * Input parameters. | |
6a488035 | 115 | * |
a6c01b45 | 116 | * @return array |
9d32e6f7 | 117 | * array of pledges, if error an array with an error id and error message |
6a488035 TO |
118 | */ |
119 | function civicrm_api3_pledge_payment_get($params) { | |
120 | ||
6a488035 TO |
121 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
122 | } | |
123 | ||
11e09c59 | 124 | /** |
9d32e6f7 | 125 | * Gets field for civicrm_pledge_payment functions. |
6a488035 | 126 | * |
c490a46a | 127 | * @param array $params |
ae5ffbb7 | 128 | * Modifiable list of fields allowed for the PledgePayment.get action. |
6a488035 TO |
129 | */ |
130 | function civicrm_api3_pledge_payment_get_spec(&$params) { | |
131 | $params['option.create_new'] = array('title' => "Create new field rather than update an unpaid payment"); | |
132 | } |