Merge pull request #4892 from colemanw/INFRA-132
[civicrm-core.git] / api / v3 / ParticipantPayment.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
39de6fd5 5 | CiviCRM version 4.6 |
6a488035 6 +--------------------------------------------------------------------+
731a0992 7 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29/**
30 * File for the CiviCRM APIv3 participant functions
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Participant
34 *
731a0992 35 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
36 * @version $Id: Participant.php 30486 2010-11-02 16:12:09Z shot $
37 *
38 */
39
40/**
41 * Files required for this package
42 */
6a488035
TO
43
44/**
45 * Create a Event Participant Payment
46 *
47 * This API is used for creating a Participant Payment of Event.
48 * Required parameters : participant_id, contribution_id.
49 *
cf470720
TO
50 * @param array $params
51 * An associative array of name/value property values of civicrm_participant_payment.
6a488035
TO
52 * @example ParticipantPaymentCreate.php
53 * {@example ParticipantPaymentCreate.php 0}
54 *
55 * @return array of newly created payment property values.
56 * {@getfields ParticipantPayment_create}
57 * @access public
58 */
59function civicrm_api3_participant_payment_create($params) {
60
61 $ids = array();
a7488080 62 if (!empty($params['id'])) {
6a488035
TO
63 $ids['id'] = $params['id'];
64 }
65 $participantPayment = CRM_Event_BAO_ParticipantPayment::create($params, $ids);
66
67 $payment = array();
68 _civicrm_api3_object_to_array($participantPayment, $payment[$participantPayment->id]);
69
70 return civicrm_api3_create_success($payment, $params);
71}
11e09c59
TO
72
73/**
6a488035 74 * Adjust Metadata for Create action
1c88e578 75 *
6a488035 76 * The metadata is used for setting defaults, documentation & validation
cf470720
TO
77 * @param array $params
78 * Array or parameters determined by getfields.
6a488035
TO
79 */
80function _civicrm_api3_participant_payment_create_spec(&$params) {
81 $params['participant_id']['api.required'] = 1;
82 $params['contribution_id']['api.required'] = 1;
83}
84
85/**
86 * Deletes an existing Participant Payment
87 *
88 * This API is used for deleting a Participant Payment
89 *
c490a46a 90 * @param array $params
6a488035
TO
91 *
92 * @return array API result
93 * @example ParticipantPaymentDelete.php
94 * {@getfields ParticipantPayment_delete}
95 * @access public
96 */
97function civicrm_api3_participant_payment_delete($params) {
98 $participant = new CRM_Event_BAO_ParticipantPayment();
99 return $participant->deleteParticipantPayment($params) ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting participantPayment');
100}
101
102/**
103 * Retrieve one / all contribution(s) / participant(s) linked to a
7c285037 104 * contribution.
6a488035 105 *
cf470720
TO
106 * @param array $params
107 * Input parameters.
6a488035
TO
108 *
109 * @return array array of properties, if error an array with an error id and error message
35671d00 110 * @example ParticipantPaymentGet
6a488035
TO
111 * {@getfields ParticipantPayment_get}
112 * @access public
113 */
114function civicrm_api3_participant_payment_get($params) {
115 return _civicrm_api3_basic_get('CRM_Event_DAO_ParticipantPayment', $params);
116}