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 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM Pledge payment.
15 * @package CiviCRM_APIv3
19 * Add or update a pledge payment.
21 * Pledge Payment API doesn't actually add a pledge.
22 * If the request is to 'create' and 'id' is not passed in
23 * the oldest pledge with no associated contribution is updated.
25 * @todo possibly add ability to add payment if there are less payments than pledge installments
26 * @todo possibly add ability to recalculate dates if the schedule is changed
28 * @param array $params
34 function civicrm_api3_pledge_payment_create($params) {
36 $paymentParams = $params;
37 if (empty($params['id']) && empty($params['option.create_new'])) {
38 $paymentDetails = CRM_Pledge_BAO_PledgePayment
::getOldestPledgePayment($params['pledge_id']);
39 if (empty($paymentDetails)) {
40 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");
42 elseif (is_array($paymentDetails)) {
43 $paymentParams = array_merge($params, $paymentDetails);
47 $dao = CRM_Pledge_BAO_PledgePayment
::add($paymentParams);
49 if (empty($dao->pledge_id
)) {
52 _civicrm_api3_object_to_array($dao, $result[$dao->id
]);
54 //update pledge status
55 CRM_Pledge_BAO_PledgePayment
::updatePledgePaymentStatus($dao->pledge_id
);
57 return civicrm_api3_create_success($result, $params, 'PledgePayment', 'create', $dao);
61 * Adjust Metadata for Create action.
63 * The metadata is used for setting defaults, documentation & validation.
65 * @param array $params
66 * Array of parameters determined by getfields.
68 function _civicrm_api3_pledge_payment_create_spec(&$params) {
69 $params['pledge_id']['api.required'] = 1;
70 $params['status_id']['api.required'] = 1;
74 * Delete a pledge Payment - Note this deletes the contribution not just the link.
76 * @param array $params
82 function civicrm_api3_pledge_payment_delete($params) {
84 if (CRM_Pledge_BAO_PledgePayment
::del($params['id'])) {
85 return civicrm_api3_create_success(['id' => $params['id']], $params, 'PledgePayment', 'delete');
88 return civicrm_api3_create_error('Could not delete payment');
93 * Retrieve a set of pledges, given a set of input params.
95 * @param array $params
99 * array of pledges, if error an array with an error id and error message
101 function civicrm_api3_pledge_payment_get($params) {
103 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);