Merge pull request #13852 from pradpnayak/RecurringMemIssue
[civicrm-core.git] / api / v3 / examples / Contact / APIChainedArray.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contact.get API.
4 *
5 * This demonstrates the usage of chained api functions.
6 * In this case no notes or custom fields have been created.
7 *
8 * @return array
9 * API result array
10 */
11 function contact_get_example() {
12 $params = [
13 'id' => 3,
14 'api.website.get' => [],
15 'api.Contribution.get' => [
16 'total_amount' => '120.00',
17 ],
18 'api.CustomValue.get' => 1,
19 'api.Note.get' => 1,
20 ];
21
22 try{
23 $result = civicrm_api3('Contact', 'get', $params);
24 }
25 catch (CiviCRM_API3_Exception $e) {
26 // Handle error here.
27 $errorMessage = $e->getMessage();
28 $errorCode = $e->getErrorCode();
29 $errorData = $e->getExtraParams();
30 return [
31 'is_error' => 1,
32 'error_message' => $errorMessage,
33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 ];
36 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function contact_get_expectedresult() {
48
49 $expectedResult = [
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 3,
54 'values' => [
55 '3' => [
56 'contact_id' => '3',
57 'contact_type' => 'Individual',
58 'contact_sub_type' => '',
59 'sort_name' => 'xyz3, abc3',
60 'display_name' => 'abc3 xyz3',
61 'do_not_email' => 0,
62 'do_not_phone' => 0,
63 'do_not_mail' => 0,
64 'do_not_sms' => 0,
65 'do_not_trade' => 0,
66 'is_opt_out' => 0,
67 'legal_identifier' => '',
68 'external_identifier' => '',
69 'nick_name' => '',
70 'legal_name' => '',
71 'image_URL' => '',
72 'preferred_communication_method' => '',
73 'preferred_language' => 'en_US',
74 'preferred_mail_format' => 'Both',
75 'first_name' => 'abc3',
76 'middle_name' => '',
77 'last_name' => 'xyz3',
78 'prefix_id' => '',
79 'suffix_id' => '',
80 'formal_title' => '',
81 'communication_style_id' => '',
82 'job_title' => '',
83 'gender_id' => '',
84 'birth_date' => '',
85 'is_deceased' => 0,
86 'deceased_date' => '',
87 'household_name' => '',
88 'organization_name' => '',
89 'sic_code' => '',
90 'contact_is_deleted' => 0,
91 'current_employer' => '',
92 'address_id' => '',
93 'street_address' => '',
94 'supplemental_address_1' => '',
95 'supplemental_address_2' => '',
96 'supplemental_address_3' => '',
97 'city' => '',
98 'postal_code_suffix' => '',
99 'postal_code' => '',
100 'geo_code_1' => '',
101 'geo_code_2' => '',
102 'state_province_id' => '',
103 'country_id' => '',
104 'phone_id' => '',
105 'phone_type_id' => '',
106 'phone' => '',
107 'email_id' => '1',
108 'email' => 'man3@yahoo.com',
109 'on_hold' => 0,
110 'im_id' => '',
111 'provider_id' => '',
112 'im' => '',
113 'worldregion_id' => '',
114 'world_region' => '',
115 'languages' => 'English (United States)',
116 'individual_prefix' => '',
117 'individual_suffix' => '',
118 'communication_style' => '',
119 'gender' => '',
120 'state_province_name' => '',
121 'state_province' => '',
122 'country' => '',
123 'id' => '3',
124 'api.website.get' => [
125 'is_error' => 0,
126 'version' => 3,
127 'count' => 1,
128 'id' => 1,
129 'values' => [
130 '0' => [
131 'id' => '1',
132 'contact_id' => '3',
133 'url' => 'http://civicrm.org',
134 ],
135 ],
136 ],
137 'api.Contribution.get' => [
138 'is_error' => 0,
139 'version' => 3,
140 'count' => 1,
141 'id' => 2,
142 'values' => [
143 '0' => [
144 'contact_id' => '3',
145 'contact_type' => 'Individual',
146 'contact_sub_type' => '',
147 'sort_name' => 'xyz3, abc3',
148 'display_name' => 'abc3 xyz3',
149 'contribution_id' => '2',
150 'currency' => 'USD',
151 'payment_instrument' => 'Credit Card',
152 'payment_instrument_id' => '1',
153 'receive_date' => '2011-01-01 00:00:00',
154 'non_deductible_amount' => '10.00',
155 'total_amount' => '120.00',
156 'fee_amount' => '50.00',
157 'net_amount' => '90.00',
158 'trxn_id' => '12335',
159 'invoice_id' => '67830',
160 'cancel_date' => '',
161 'cancel_reason' => '',
162 'receipt_date' => '',
163 'thankyou_date' => '',
164 'contribution_source' => 'SSF',
165 'amount_level' => '',
166 'contribution_recur_id' => '',
167 'is_test' => 0,
168 'is_pay_later' => 0,
169 'contribution_status' => 'Completed',
170 'contribution_status_id' => '1',
171 'contribution_check_number' => '',
172 'contribution_campaign_id' => '',
173 'financial_type_id' => '1',
174 'financial_type' => 'Donation',
175 'product_id' => '',
176 'product_name' => '',
177 'sku' => '',
178 'contribution_product_id' => '',
179 'product_option' => '',
180 'fulfilled_date' => '',
181 'contribution_start_date' => '',
182 'contribution_end_date' => '',
183 'financial_account_id' => '1',
184 'accounting_code' => '4200',
185 'campaign_id' => '',
186 'contribution_campaign_title' => '',
187 'contribution_note' => '',
188 'contribution_batch' => '',
189 'check_number' => '',
190 'instrument_id' => '1',
191 'id' => '2',
192 'contribution_type_id' => '1',
193 ],
194 ],
195 ],
196 'api.CustomValue.get' => [
197 'is_error' => 0,
198 'version' => 3,
199 'count' => 0,
200 'values' => [],
201 ],
202 'api.Note.get' => [
203 'is_error' => 0,
204 'version' => 3,
205 'count' => 0,
206 'values' => [],
207 ],
208 ],
209 ],
210 ];
211
212 return $expectedResult;
213 }
214
215 /*
216 * This example has been generated from the API test suite.
217 * The test that created it is called "testGetIndividualWithChainedArrays"
218 * and can be found at:
219 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
220 *
221 * You can see the outcome of the API tests at
222 * https://test.civicrm.org/job/CiviCRM-master-git/
223 *
224 * To Learn about the API read
225 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
226 *
227 * Browse the api on your own site with the api explorer
228 * http://MYSITE.ORG/path/to/civicrm/api
229 *
230 * Read more about testing here
231 * http://wiki.civicrm.org/confluence/display/CRM/Testing
232 *
233 * API Standards documentation:
234 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
235 */