Merge pull request #2061 from civicrm/4.3
[civicrm-core.git] / api / v3 / examples / Participant / CreateParticipantPayment.php
1 <?php
2 /**
3 * Test Generated example of using participant create API
4 * single function to create contact w partipation & contribution. Note that in the
5 case of 'contribution' the 'create' is implied (api.contribution.create) *
6 */
7 function participant_create_example(){
8 $params = array(
9 'contact_type' => 'Individual',
10 'display_name' => 'dlobo',
11 'api.participant' => array(
12 'event_id' => 39,
13 'status_id' => 1,
14 'role_id' => 1,
15 'format.only_id' => 1,
16 ),
17 'api.contribution.create' => array(
18 'financial_type_id' => 1,
19 'total_amount' => 100,
20 'format.only_id' => 1,
21 ),
22 'api.participant_payment.create' => array(
23 'contribution_id' => '$value.api.contribution.create',
24 'participant_id' => '$value.api.participant',
25 ),
26 );
27
28 try{
29 $result = civicrm_api3('participant', 'create', $params);
30 }
31 catch (CiviCRM_API3_Exception $e) {
32 // handle error here
33 $errorMessage = $e->getMessage();
34 $errorCode = $e->getErrorCode();
35 $errorData = $e->getExtraParams();
36 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
37 }
38
39 return $result;
40 }
41
42 /**
43 * Function returns array of result expected from previous function
44 */
45 function participant_create_expectedresult(){
46
47 $expectedResult = array(
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
51 'id' => 5,
52 'values' => array(
53 '5' => array(
54 'id' => '5',
55 'contact_type' => 'Individual',
56 'contact_sub_type' => '',
57 'do_not_email' => 0,
58 'do_not_phone' => 0,
59 'do_not_mail' => 0,
60 'do_not_sms' => 0,
61 'do_not_trade' => 0,
62 'is_opt_out' => 0,
63 'legal_identifier' => '',
64 'external_identifier' => '',
65 'sort_name' => '',
66 'display_name' => 'dlobo',
67 'nick_name' => '',
68 'legal_name' => '',
69 'image_URL' => '',
70 'preferred_communication_method' => '',
71 'preferred_language' => 'en_US',
72 'preferred_mail_format' => 'Both',
73 'hash' => '67eac7789eaee00',
74 'api_key' => '',
75 'first_name' => '',
76 'middle_name' => '',
77 'last_name' => '',
78 'prefix_id' => '',
79 'suffix_id' => '',
80 'email_greeting_id' => '1',
81 'email_greeting_custom' => '',
82 'email_greeting_display' => '',
83 'postal_greeting_id' => '1',
84 'postal_greeting_custom' => '',
85 'postal_greeting_display' => '',
86 'addressee_id' => '1',
87 'addressee_custom' => '',
88 'addressee_display' => '',
89 'job_title' => '',
90 'gender_id' => '',
91 'birth_date' => '',
92 'is_deceased' => 0,
93 'deceased_date' => '',
94 'household_name' => '',
95 'primary_contact_id' => '',
96 'organization_name' => '',
97 'sic_code' => '',
98 'user_unique_id' => '',
99 'created_date' => '2013-07-28 08:49:19',
100 'modified_date' => '2012-11-14 16:02:35',
101 'api.participant' => 4,
102 'api.contribution.create' => 1,
103 'api.participant_payment.create' => array(
104 'is_error' => 0,
105 'version' => 3,
106 'count' => 1,
107 'id' => 1,
108 'values' => array(
109 '0' => array(
110 'id' => '1',
111 'participant_id' => '4',
112 'contribution_id' => '1',
113 ),
114 ),
115 ),
116 ),
117 ),
118 );
119
120 return $expectedResult;
121 }
122
123
124 /*
125 * This example has been generated from the API test suite. The test that created it is called
126 *
127 * testCreateParticipantWithPayment and can be found in
128 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ParticipantTest.php
129 *
130 * You can see the outcome of the API tests at
131 * http://tests.dev.civicrm.org/trunk/results-api_v3
132 *
133 * To Learn about the API read
134 * http://book.civicrm.org/developer/current/techniques/api/
135 *
136 * and review the wiki at
137 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
138 *
139 * Read more about testing here
140 * http://wiki.civicrm.org/confluence/display/CRM/Testing
141 *
142 * API Standards documentation:
143 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
144 */