Merge pull request #15103 from mattwire/relationshipaddbao
[civicrm-core.git] / api / v3 / examples / Contact / ChainTwoWebsitesSyntax2.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contact.create API.
4 *
5 * Demonstrates creating two websites as an array.
6 *
7 * @return array
8 * API result array
9 */
10 function contact_create_example() {
11 $params = [
12 'first_name' => 'abc3',
13 'last_name' => 'xyz3',
14 'contact_type' => 'Individual',
15 'email' => 'man3@yahoo.com',
16 'api.contribution.create' => [
17 'receive_date' => '2010-01-01',
18 'total_amount' => '100',
19 'financial_type_id' => 1,
20 'payment_instrument_id' => 1,
21 'non_deductible_amount' => '10',
22 'fee_amount' => '50',
23 'net_amount' => '90',
24 'trxn_id' => 12345,
25 'invoice_id' => 67890,
26 'source' => 'SSF',
27 'contribution_status_id' => 1,
28 'skipCleanMoney' => 1,
29 ],
30 'api.website.create' => [
31 '0' => [
32 'url' => 'http://civicrm.org',
33 ],
34 '1' => [
35 'url' => 'http://chained.org',
36 'website_type_id' => 2,
37 ],
38 ],
39 ];
40
41 try{
42 $result = civicrm_api3('Contact', 'create', $params);
43 }
44 catch (CiviCRM_API3_Exception $e) {
45 // Handle error here.
46 $errorMessage = $e->getMessage();
47 $errorCode = $e->getErrorCode();
48 $errorData = $e->getExtraParams();
49 return [
50 'is_error' => 1,
51 'error_message' => $errorMessage,
52 'error_code' => $errorCode,
53 'error_data' => $errorData,
54 ];
55 }
56
57 return $result;
58 }
59
60 /**
61 * Function returns array of result expected from previous function.
62 *
63 * @return array
64 * API result array
65 */
66 function contact_create_expectedresult() {
67
68 $expectedResult = [
69 'is_error' => 0,
70 'version' => 3,
71 'count' => 1,
72 'id' => 3,
73 'values' => [
74 '3' => [
75 'id' => '3',
76 'contact_type' => 'Individual',
77 'contact_sub_type' => '',
78 'do_not_email' => 0,
79 'do_not_phone' => 0,
80 'do_not_mail' => 0,
81 'do_not_sms' => 0,
82 'do_not_trade' => 0,
83 'is_opt_out' => 0,
84 'legal_identifier' => '',
85 'external_identifier' => '',
86 'sort_name' => 'xyz3, abc3',
87 'display_name' => 'abc3 xyz3',
88 'nick_name' => '',
89 'legal_name' => '',
90 'image_URL' => '',
91 'preferred_communication_method' => '',
92 'preferred_language' => 'en_US',
93 'preferred_mail_format' => 'Both',
94 'hash' => '67eac7789eaee00',
95 'api_key' => '',
96 'first_name' => 'abc3',
97 'middle_name' => '',
98 'last_name' => 'xyz3',
99 'prefix_id' => '',
100 'suffix_id' => '',
101 'formal_title' => '',
102 'communication_style_id' => '1',
103 'email_greeting_id' => '1',
104 'email_greeting_custom' => '',
105 'email_greeting_display' => '',
106 'postal_greeting_id' => '1',
107 'postal_greeting_custom' => '',
108 'postal_greeting_display' => '',
109 'addressee_id' => '1',
110 'addressee_custom' => '',
111 'addressee_display' => '',
112 'job_title' => '',
113 'gender_id' => '',
114 'birth_date' => '',
115 'is_deceased' => 0,
116 'deceased_date' => '',
117 'household_name' => '',
118 'primary_contact_id' => '',
119 'organization_name' => '',
120 'sic_code' => '',
121 'user_unique_id' => '',
122 'created_date' => '2013-07-28 08:49:19',
123 'modified_date' => '2012-11-14 16:02:35',
124 'api.contribution.create' => [
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 'financial_type_id' => '1',
134 'contribution_page_id' => '',
135 'payment_instrument_id' => '1',
136 'receive_date' => '20100101000000',
137 'non_deductible_amount' => '10',
138 'total_amount' => '100',
139 'fee_amount' => '50',
140 'net_amount' => '90',
141 'trxn_id' => '12345',
142 'invoice_id' => '67890',
143 'invoice_number' => '',
144 'currency' => 'USD',
145 'cancel_date' => '',
146 'cancel_reason' => '',
147 'receipt_date' => '',
148 'thankyou_date' => '',
149 'source' => 'SSF',
150 'amount_level' => '',
151 'contribution_recur_id' => '',
152 'is_test' => '',
153 'is_pay_later' => '',
154 'contribution_status_id' => '1',
155 'address_id' => '',
156 'check_number' => '',
157 'campaign_id' => '',
158 'creditnote_id' => '',
159 'tax_amount' => '',
160 'revenue_recognition_date' => '',
161 'contribution_type_id' => '1',
162 ],
163 ],
164 ],
165 'api.website.create' => [
166 '0' => [
167 'is_error' => 0,
168 'version' => 3,
169 'count' => 1,
170 'id' => 1,
171 'values' => [
172 '0' => [
173 'id' => '1',
174 'contact_id' => '3',
175 'url' => 'http://civicrm.org',
176 'website_type_id' => '',
177 ],
178 ],
179 ],
180 '1' => [
181 'is_error' => 0,
182 'version' => 3,
183 'count' => 1,
184 'id' => 2,
185 'values' => [
186 '0' => [
187 'id' => '2',
188 'contact_id' => '3',
189 'url' => 'http://chained.org',
190 'website_type_id' => '2',
191 ],
192 ],
193 ],
194 ],
195 ],
196 ],
197 ];
198
199 return $expectedResult;
200 }
201
202 /*
203 * This example has been generated from the API test suite.
204 * The test that created it is called "testCreateIndividualWithContributionChainedArrays"
205 * and can be found at:
206 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
207 *
208 * You can see the outcome of the API tests at
209 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
210 *
211 * To Learn about the API read
212 * https://docs.civicrm.org/dev/en/latest/api/
213 *
214 * Browse the API on your own site with the API Explorer. It is in the main
215 * CiviCRM menu, under: Support > Development > API Explorer.
216 *
217 * Read more about testing here
218 * https://docs.civicrm.org/dev/en/latest/testing/
219 *
220 * API Standards documentation:
221 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
222 */