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