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