Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using 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( | |
6a488035 TO |
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 | ), | |
50fb255d | 29 | 'api.website.create' => array( |
edb0d67a | 30 | '0' => array( |
50fb255d | 31 | 'url' => 'http://civicrm.org', |
32 | ), | |
edb0d67a | 33 | '1' => array( |
50fb255d | 34 | 'url' => 'http://chained.org', |
35 | 'website_type_id' => 2, | |
36 | ), | |
6a488035 | 37 | ), |
50fb255d | 38 | ); |
6a488035 | 39 | |
50fb255d | 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 | } | |
6a488035 | 54 | |
50fb255d | 55 | return $result; |
6a488035 TO |
56 | } |
57 | ||
fb32de45 | 58 | /** |
50fb255d | 59 | * Function returns array of result expected from previous function. |
60 | * | |
61 | * @return array | |
62 | * API result array | |
6a488035 | 63 | */ |
50fb255d | 64 | function contact_create_expectedresult() { |
6a488035 | 65 | |
edb0d67a | 66 | $expectedResult = array( |
50fb255d | 67 | 'is_error' => 0, |
68 | 'version' => 3, | |
69 | 'count' => 1, | |
70 | 'id' => 1, | |
71 | 'values' => array( | |
edb0d67a | 72 | '1' => array( |
50fb255d | 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', | |
6a488035 | 158 | ), |
50fb255d | 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( | |
edb0d67a | 182 | '0' => array( |
50fb255d | 183 | 'id' => '2', |
184 | 'contact_id' => '1', | |
185 | 'url' => 'http://chained.org', | |
186 | 'website_type_id' => '2', | |
187 | ), | |
6a488035 | 188 | ), |
50fb255d | 189 | ), |
6a488035 | 190 | ), |
50fb255d | 191 | ), |
6a488035 | 192 | ), |
50fb255d | 193 | ); |
6a488035 | 194 | |
fb32de45 | 195 | return $expectedResult; |
6a488035 TO |
196 | } |
197 | ||
50fb255d | 198 | /** |
199 | * This example has been generated from the API test suite. | |
200 | * The test that created it is called | |
201 | * testCreateIndividualWithContributionChainedArrays | |
202 | * and can be found in | |
69d79249 | 203 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
204 | * |
205 | * You can see the outcome of the API tests at | |
69d79249 | 206 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
207 | * |
208 | * To Learn about the API read | |
69d79249 | 209 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 210 | * |
69d79249 | 211 | * Browse the api on your own site with the api explorer |
41d4d31f | 212 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
213 | * |
214 | * Read more about testing here | |
215 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
216 | * | |
217 | * API Standards documentation: | |
218 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 219 | */ |