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